source: extensions/SmiliesSupport/template/smiliessupport_admin.tpl @ 23234

Last change on this file since 23234 was 23234, checked in by mistic100, 11 years ago

rewrite admin page
new set from Pidgin

File size: 5.4 KB
Line 
1{combine_script id='jquery.tokeninput' load='footer' path='themes/default/js/plugins/jquery.tokeninput.js'}
2{combine_css path=$SMILIES_PATH|cat:'template/style.css'}
3
4
5{footer_script}{literal}
6var data = {};
7var edit = false;
8var edited = false;
9
10// set changed
11jQuery("select[name='folder']").change(function() {
12    if (edited) {
13        var ok = confirm("{/literal}{'If you change current set you will lost every shortcuts changes.'|@translate}{literal}");
14        if (!ok) {
15            jQuery(this).val(jQuery(this).data("selected"));
16            return false;
17        }
18    }
19   
20    var image = jQuery(this).find(":selected").css("background-image");
21    jQuery(this).css("background-image", image);
22    jQuery(this).data("selected", jQuery(this).val());
23   
24    fetch();
25});
26
27// size changed
28jQuery("input[name='cols']").change(function() {
29    update();
30});
31
32// switch preview/edit
33jQuery(".edit").click(function() {
34    if (edit) {
35        $(this).html("{/literal}{'Edit shorcuts'|@translate}{literal}");
36    }
37    else {
38        $(this).html("{/literal}{'Preview'|@translate}{literal}");
39    }
40   
41    edit = !edit;
42    update();
43    return false;
44});
45
46// display edit form before submit
47jQuery("#smiliesupport").submit(function() {
48    if (!edit) jQuery(".edit").click();
49    return true;
50});
51
52/* get smilies list */
53function fetch() {
54    jQuery.ajax({
55        url: 'admin.php',
56        type: 'GET',
57        dataType: 'json',
58        data: {
59            action: 'ss_preview',
60            folder: jQuery("select[name='folder']").val(),
61        },
62        success: function(result) {
63            data = result;
64            edited = false;
65            update();
66        }
67    });
68}
69
70/* update preview/edit table */
71function update() {
72    var html = '';
73   
74    if (!edit) {
75        html+= '<tr>';
76        var cols = parseInt(jQuery("input[name='cols']").val());
77        var i=0;
78       
79        for (var file in data.smilies) {
80            var smiley = data.smilies[file];
81            html+= '<td><a href="#" title="'+ smiley.title +'"><img src="'+ data.path + smiley.file +'"/></a></td>';
82            if ((parseInt(i)+1)%cols == 0) html+= '</tr><tr>';
83            i++;
84        }
85       
86        html+= '</tr>';
87    }
88    else {
89    {/literal}
90        html+= '<tr>'
91            +'<th>{'Smiley'|@translate}</th>'
92            +'<th>{'Name'|@translate}</th>'
93            +'<th>{'Shortcuts'|@translate}</th>'
94          +'</tr>';
95     {literal}
96     
97        for (var file in data.smilies) {
98            var smiley = data.smilies[file];
99            html+= '<tr data-file="'+ smiley.file +'">'
100                +'<td><img src="'+ data.path + smiley.file +'"/></td>'
101                +'<td>'+ smiley.title +'</td>'
102                +'<td>'
103                  +'<select name="shortcuts['+ smiley.file +']" class="shortcuts">';
104               
105                for (var j in smiley.short) {
106                    html+= '<option value="'+ smiley.short[j] +'" selected>'+ smiley.short[j] +'</option>';
107                }
108                 
109                html+= '</select>'
110                +'</td>'
111              +'</tr>';
112        }
113    }
114   
115    jQuery("#preview").html(html);
116   
117    // init tokeninput
118    jQuery(".shortcuts").tokenInput([], {
119        hintText: '{/literal}{'Type in a new shortcut'|@translate}{literal}',
120        newText: '',
121        animateDropdown: false,
122        preventDuplicates: true,
123        caseSensitive: true,
124        allowCreation: true,
125        minChars: 2,
126        searchDelay: 10,
127       
128        onAdd: function(item) {
129            edited = true;
130            var file = $(this).parents("tr").data("file");
131           
132            if (data.smilies[file].short == null) {
133                data.smilies[file].short = [item.name];
134            }
135            else {
136                data.smilies[file].short.push(item.name);
137            }
138        },
139        onDelete: function(item) {
140          edited = true;
141          var file = $(this).parents("tr").data("file");
142         
143          for (var i in data.smilies[file].short) {
144              if (data.smilies[file].short[i] == item.name) {
145                  data.smilies[file].short.splice(i, 1);
146              }
147          }
148        },
149    });
150   
151    // prevent spaces
152    jQuery(".token-input-input-token input").keydown(function(e) {
153        if (e.keyCode == 32) {
154            return false;
155        }
156    });
157}
158
159// init
160fetch();
161{/literal}{/footer_script}
162
163
164<div class="titrePage">
165  <h2>Smilies Support</h2>
166</div>
167
168<form method="post" action="" class="properties" id="smiliesupport">
169
170<fieldset>
171  <legend>{'Configuration'|@translate}</legend> 
172 
173  <ul>     
174    <li>
175      <b>{'Smilies set'|@translate}</b>
176      <select name="folder" style="background-image:url('{$SMILIES_PATH}smilies/{$FOLDER}/{$SETS[$FOLDER]}');" data-selected="{$FOLDER}">
177      {foreach from=$SETS item=rep key=set}
178        <option value="{$set}" style="background-image:url('{$SMILIES_PATH}smilies/{$set}/{$rep}');" {if $set==$FOLDER}selected{/if}>{$set}</option>
179      {/foreach}
180      </select>
181    </li>
182    <li>
183      <b>{'Columns'|@translate}</b>
184      <input type="text" size="2" name="cols" value="{$COLS}">
185    </li>
186  </ul>
187</fieldset>
188
189<fieldset>
190  <legend>{'Preview'|@translate}</legend> 
191  <a href="#" class="edit buttonLike">{'Edit shorcuts'|@translate}</a>
192  <table id="preview"></table>
193</fieldset>
194 
195<p class="formButtons"><input class="submit" type="submit" value="{'Submit'|@translate}" name="submit" /></p>
196
197</form>
Note: See TracBrowser for help on using the repository browser.