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

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

two columns display for shortcuts form, keep save of original smilies.txt file

File size: 6.3 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// reset defaults
47jQuery(".reset").click(function() {
48    var ok = confirm("{/literal}{'Are you sure?'|@translate}{literal}");
49    if (!ok) return false;
50   
51    jQuery.ajax({
52        url: 'admin.php',
53        type: 'GET',
54        dataType: 'json',
55        data: {
56            action: 'ss_reset',
57            folder: jQuery("select[name='folder']").val(),
58        },
59        success: function(result) {
60            data = result;
61            edited = false;
62            update();
63        }
64    });
65   
66    return false;
67});
68
69// display edit form before submit
70jQuery("#smiliesupport").submit(function() {
71    if (!edit) jQuery(".edit").click();
72    return true;
73});
74
75/* get smilies list */
76function fetch() {
77    jQuery.ajax({
78        url: 'admin.php',
79        type: 'GET',
80        dataType: 'json',
81        data: {
82            action: 'ss_list',
83            folder: jQuery("select[name='folder']").val(),
84        },
85        success: function(result) {
86            data = result;
87            edited = false;
88            update();
89        }
90    });
91}
92
93/* update preview/edit table */
94function update() {
95    var html = '';
96   
97    if (!edit) {
98        html+= '<tr>';
99       
100        var cols = parseInt(jQuery("input[name='cols']").val());
101        var i=0;
102       
103        for (var file in data.smilies) {
104            var smiley = data.smilies[file];
105            html+= '<td><a href="#" title="'+ smiley.title +'"><img src="'+ data.path + smiley.file +'"/></a></td>';
106            html+= (i+1)%cols==0 ? '</tr><tr>' : '';
107            i++;
108        }
109       
110        html+= '</tr>';
111       
112        jQuery(".reset").hide();
113    }
114    else {
115    {/literal}
116        html+= '<tr>'
117            +'<th></th>'
118            +'<th>{'Name'|@translate}</th>'
119            +'<th>{'Shortcuts'|@translate}</th>'
120            +'<th class="spacer"></th>'
121            +'<th></th>'
122            +'<th>{'Name'|@translate}</th>'
123            +'<th>{'Shortcuts'|@translate}</th>'
124          +'</tr>'
125         
126          +'<tr>';
127     {literal}
128     
129        var i=0;
130     
131        for (var file in data.smilies) {
132            var smiley = data.smilies[file];
133           
134            html+=
135              '<td><img src="'+ data.path + smiley.file +'"/></td>'
136              +'<td>'+ smiley.title +'</td>'
137              +'<td data-file="'+ smiley.file +'">'
138                +'<select name="shortcuts['+ smiley.file +']" class="shortcuts">';
139             
140              for (var j in smiley.short) {
141                  html+= '<option value="'+ smiley.short[j] +'" selected>'+ smiley.short[j] +'</option>';
142              }
143               
144            html+=
145                '</select>'
146              +'</td>';
147           
148            html+= (i+1)%2==0 ? '</tr><tr>' : '<td></td>';
149            i++;
150        }
151       
152        html+= '</tr>';
153       
154        jQuery(".reset").show();
155    }
156   
157    jQuery("#preview").html(html);
158   
159    // init tokeninput
160    jQuery(".shortcuts").tokenInput([], {
161        hintText: '{/literal}{'Type in a new shortcut'|@translate}{literal}',
162        newText: '',
163        animateDropdown: false,
164        preventDuplicates: true,
165        caseSensitive: true,
166        allowCreation: true,
167        minChars: 2,
168        searchDelay: 10,
169       
170        onAdd: function(item) {
171            edited = true;
172            var file = $(this).parent("td").data("file");
173           
174            if (data.smilies[file].short == null) {
175                data.smilies[file].short = [item.name];
176            }
177            else {
178                data.smilies[file].short.push(item.name);
179            }
180        },
181        onDelete: function(item) {
182          edited = true;
183          var file = $(this).parent("td").data("file");
184         
185          for (var i in data.smilies[file].short) {
186              if (data.smilies[file].short[i] == item.name) {
187                  data.smilies[file].short.splice(i, 1);
188              }
189          }
190        },
191    });
192   
193    // prevent spaces
194    jQuery(".token-input-input-token input").keydown(function(e) {
195        if (e.keyCode == 32) {
196            return false;
197        }
198    });
199}
200
201// init
202fetch();
203{/literal}{/footer_script}
204
205
206<div class="titrePage">
207  <h2>Smilies Support</h2>
208</div>
209
210<form method="post" action="" class="properties" id="smiliesupport">
211
212<fieldset>
213  <legend>{'Configuration'|@translate}</legend> 
214 
215  <ul>     
216    <li>
217      <b>{'Smilies set'|@translate}</b>
218      <select name="folder" style="background-image:url('{$SMILIES_PATH}smilies/{$FOLDER}/{$SETS[$FOLDER]}');" data-selected="{$FOLDER}">
219      {foreach from=$SETS item=rep key=set}
220        <option value="{$set}" style="background-image:url('{$SMILIES_PATH}smilies/{$set}/{$rep}');" {if $set==$FOLDER}selected{/if}>{$set}</option>
221      {/foreach}
222      </select>
223    </li>
224    <li>
225      <b>{'Columns'|@translate}</b>
226      <input type="text" size="2" name="cols" value="{$COLS}">
227    </li>
228  </ul>
229</fieldset>
230
231<fieldset>
232  <legend>{'Preview'|@translate}</legend> 
233  <a href="#" class="edit buttonLike">{'Edit shorcuts'|@translate}</a>
234  <table id="preview"></table>
235  <a href="#" class="reset buttonLike" style="display:none;">{'Reset defaults'|@translate}</a>
236</fieldset>
237 
238<p class="formButtons"><input class="submit" type="submit" value="{'Submit'|@translate}" name="submit" /></p>
239
240</form>
Note: See TracBrowser for help on using the repository browser.