source: extensions/lmt/templates/lmt_dialog_licence_choose.tpl @ 15348

Last change on this file since 15348 was 15348, checked in by grum, 12 years ago

feature:2641 - Compatibility with Piwigo 2.4
Small improvments for inerface display

  • Property svn:executable set to *
File size: 8.3 KB
Line 
1{combine_script id="jquery" path="themes/default/js/jquery.js"}
2{combine_script id="jquery.ui" path="themes/default/js/ui/jquery.ui.core.js"}
3{combine_script id="jquery.ui.dialog" path="themes/default/js/ui/jquery.ui.dialog.js"}
4
5{literal}
6<style type='text/css'>
7  #lmtRulesArea { border-top:1px solid; overflow:auto; margin-top:5px; }
8  img.pointer, span.pointer, div.pointer { cursor:pointer; }
9  li.valueItems {
10    -moz-border-radius:4px 4px 4px 4px;
11    border:1px solid #666666;
12    margin-bottom:5px;
13    padding:4px;
14  }
15  #iBDLMTLicenceList {
16    list-style:none;
17    margin:8px;
18    padding:0;
19  }
20  img.imgLicence { position:relative; top:3px; }
21</style>
22
23<script type="text/javascript">
24
25/**
26 * include this template in a page and use dialogChooseLMTBox.show({options}) to display
27 * the dialog box
28 *
29 */
30dialogChooseLMTBox = function()
31{
32  var licencesNfo=[
33  {/literal}
34  {foreach from=$datas.licencesList item=licence}
35    {ldelim} value:'{$licence.value}', name:'{$licence.name}' {rdelim},
36  {/foreach}
37  {literal}
38  ];
39
40  var dialogLMTOptions = {
41        id:'',
42        eventOk:null,
43        cBuilder:null,
44        licences:[],
45      };
46
47
48  /**
49   * initialize the dialog box
50   */
51  var initDialogBox = function()
52  {
53
54    $("#iDialogLMTChoose")
55    .dialog(
56      {
57        autoOpen: false,
58        resizable: false,
59        width:640,
60        height:250,
61        modal: true,
62        draggable:true,
63        dialogClass: 'gcBgTabSheet gcBorder',
64        title: '{/literal}{"lmt_choose_licence_type"|@translate}{literal}',
65        open: function(event, ui)
66        {
67        },
68        buttons:
69        {
70          '{/literal}{"lmt_ok"|@translate}{literal}':
71            function()
72            {
73              if(checkValidity())
74              {
75                if(dialogLMTOptions.cBuilder!=null)
76                {
77                  setCBuilderItem(dialogLMTOptions.id, dialogLMTOptions.licences);
78                }
79
80                if(dialogLMTOptions.eventOk!=null)
81                {
82                  dialogLMTOptions.eventOk(dialogLMTOptions.id, dialogLMTOptions.licences);
83                }
84
85                $(this).dialog('close');
86              }
87            },
88          '{/literal}{"lmt_cancel"|@translate}{literal}':
89            function()
90            {
91              $(this).dialog('close');
92            }
93        }
94      }
95    );
96
97    $('#iBDLMTAddLicence').bind('click', function () { addLicence(); } );
98
99  };
100
101
102  /**
103   * add the selected licence in list
104   */
105  var addLicence = function ()
106  {
107    value=$('#iBDLMTLicenceType').val();
108
109    if(!$('#iBDLMTLicenceType option[value='+value+']').attr('disabled'))
110    {
111      dialogLMTOptions.licences.push(value);
112      addLicenceItem(value);
113    }
114  };
115
116  /**
117   *
118   */
119  var addLicenceItem = function (value)
120  {
121    li=$("<li/>",
122          {
123            'class':'valueItems gcBgPage',
124            licence:value
125          }
126        ).append("<span><img class='imgLicence' src='./plugins/lmt/img/"+value.toLowerCase()+"_80x15.png'>&nbsp;"+getLicenceName(value)+"</span>")
127         .append($("<div/>",
128                    {
129                      'class':'button pointer iconDelete',
130                      css:{'float':'right'}
131                    }
132                  ).bind('click', function () { removeLicence(this); })
133                );
134
135    $('#iBDLMTLicenceList').append(li);
136    $('#iBDLMTLicenceType option[value='+value+']').attr('disabled', true);
137  }
138
139  /**
140   * remove the selected licence in list
141   */
142  var removeLicence = function (item)
143  {
144    value=$(item).parent().attr('licence');
145    index=dialogLMTOptions.licences.indexOf(value);
146
147    if(index>-1)
148    {
149      dialogLMTOptions.licences.splice(index,1);
150      $('#iBDLMTLicenceType option[value='+value+']').attr('disabled', false);
151      $(item).unbind().parent().remove();
152    }
153  };
154
155  /**
156   * returns the licence name
157   * @param String value : the licence value
158   * @return String : the licence name
159   */
160  var getLicenceName = function (value)
161  {
162    for(var i=0;i<licencesNfo.length;i++)
163    {
164      if(licencesNfo[i].value==value) return(licencesNfo[i].name);
165    }
166    return('');
167  }
168
169
170  /**
171   * check the validity of the condition
172   * return Boolean : true if OK, otherwise false
173   */
174  var checkValidity = function ()
175  {
176    $(".error").removeClass('error');
177    returned=true;
178
179    if(dialogLMTOptions.licences.length==0)
180    {
181      alert("{/literal}{'lmt_error_num_items'|@translate}{literal}");
182      returned=false;
183    }
184
185    return(returned);
186  }
187
188
189
190  /**
191   * the show() function display and manage a dialog box to choose
192   * a geographic area
193   *
194   * @param options : properties to manage the dialog box
195   *                  - licences : an array of string (licences)
196   *                  - id : a string to identify a DOM object ; this parameter
197   *                         is given to the callback when the OK button is pushed
198   *                  - eventOK : a callback function, with 2 parameters : id of
199   *                              the given DOM object and the bounds object
200   *                  - cBuilder : a criteriaBuilder object
201   *                               if set, the dialog box manage automaticaly
202   *                               the criteria builder interface
203   */
204  this.show = function (options)
205  {
206    showDialog(options);
207  }
208
209  /**
210   * private function used to show the dialog box
211   */
212  var showDialog = function(options)
213  {
214    if(options.licences!=null)
215    {
216      dialogLMTOptions.licences=options.licences;
217    }
218    else
219    {
220      dialogLMTOptions.licences=[];
221    }
222
223    if(options.id!=null)
224    {
225      dialogLMTOptions.id=options.id;
226    }
227    else
228    {
229      dialogLMTOptions.id='';
230    }
231
232    if(options.eventOk!=null)
233    {
234      dialogLMTOptions.eventOk=options.eventOk;
235    }
236
237    if(options.cBuilder!=null)
238    {
239      dialogLMTOptions.cBuilder=options.cBuilder;
240      dialogLMTOptions.cBuilder.doAction('setOptions',
241        {
242          onEdit:function (e) { editGA(e.data); },
243          onDelete:function (e) { deleteGA(e.data); },
244        }
245      );
246    }
247
248    $('#iBDLMTLicenceType option').attr('disabled', false);
249    $('#iBDLMTLicenceList img').unbind();
250    $('#iBDLMTLicenceList').html('');
251    for(var i=0;i<dialogLMTOptions.licences.length;i++)
252    {
253      addLicenceItem(dialogLMTOptions.licences[i]);
254    }
255
256    $("#iDialogLMTChoose").dialog('open');
257  };
258
259
260
261  /**
262   * manage the 'edit' button from criteria builder interface
263   * @param String itemId : the itemId
264   */
265  var editGA = function (itemId)
266  {
267    extraData=dialogLMTOptions.cBuilder.doAction('getExtraData', itemId);
268    showDialog(
269      {
270        id:itemId,
271        licences:extraData.param.licences
272      }
273    );
274  };
275
276  /**
277   * manage the 'delete' button from criteria builder interface
278   * @param String itemId : the itemId
279   */
280  var deleteGA = function (itemId)
281  {
282    dialogLMTOptions.cBuilder.doAction('delete', itemId);
283  };
284
285  /**
286   * set the content for the cBuilder item
287   */
288  var setCBuilderItem = function(id, licences)
289  {
290    var content="";
291
292    if(licences.length>1)
293    {
294      content="{/literal}{'lmt_search_pictures_with_licence_n'|@translate}{literal}";
295    }
296    else
297    {
298      content="{/literal}{'lmt_search_pictures_with_licence_1'|@translate}{literal}";
299    }
300
301    content+='<br><div style="font-style:italic;padding-left:15px;">';
302    for(var i=0;i<licences.length;i++)
303    {
304      content+="<img class='imgLicence' src='./plugins/lmt/img/"+licences[i].toLowerCase()+"_80x15.png'>&nbsp;"+getLicenceName(licences[i])+'<br>';
305    }
306    content+='</div>';
307
308    if(id=='')
309    {
310      //no id:add a new item in the list
311      dialogLMTOptions.cBuilder.doAction('add', content, criteriaBuilder.makeExtendedData('LMT', {licences:licences } ) );
312    }
313    else
314    {
315      // update item
316      dialogLMTOptions.cBuilder.doAction('edit', id,  content, criteriaBuilder.makeExtendedData('LMT', {licences:licences } ) );
317    }
318  };
319
320  initDialogBox();
321}
322
323
324</script>
325{/literal}
326
327<div id="iDialogLMTChoose" style='display:none;margin-top:5px;'>
328  {'lmt_licence_type'|@translate}&nbsp;
329  <select id='iBDLMTLicenceType'>
330    {foreach from=$datas.licencesList item=licence}
331      <option value='{$licence.value}'>{$licence.name}</option>
332    {/foreach}
333  </select>&nbsp;
334  <input type='button' value='{"lmt_add"|@translate}' id='iBDLMTAddLicence'>
335
336  <div id='lmtRulesArea'>
337    <ul id='iBDLMTLicenceList'>
338    </ul>
339  </div>
340</div>
341
342
Note: See TracBrowser for help on using the repository browser.