source: extensions/ASearchEngine/templates/ase_dialog_date_choose.tpl @ 12864

Last change on this file since 12864 was 10886, checked in by grum, 13 years ago

feature:2145 - compatibility with piwigo 2.2

  • Property svn:executable set to *
File size: 11.6 KB
Line 
1{combine_script id="jquery.ui" path="themes/default/js/ui/minified/jquery.ui.core.min.js" require='jquery'}
2{combine_script id="jquery.ui.dialog" path="themes/default/js/ui/minified/jquery.ui.dialog.min.js" require='jquery'}
3{combine_script id="jquery.ui.datepicker" path="themes/default/js/ui/minified/jquery.ui.datepicker.min.js" require='jquery'}
4
5{assign var="datepicker_language" value="themes/default/js/ui/minified/i18n/jquery.ui.datepicker-"|@cat:$lang_info.code|@cat:".js"}
6{if "PHPWG_ROOT_PATH"|@constant|@cat:$datepicker_language|@file_exists}
7{combine_script id="jquery.ui.datepicker-$lang_info.code" path=$datepicker_language}
8{/if}
9
10{html_head}
11<link rel="stylesheet" type="text/css" href="themes/default/js/ui/theme/jquery.ui.datepicker.css">
12{/html_head}
13
14
15{literal}
16<style type='text/css'>
17  #ui-datepicker-div {
18    z-index:1500;
19    display:none;
20  }
21</style>
22
23<script type="text/javascript">
24/**
25 * include this template in a page and use dialogChooseASEDateBox.show({options}) to display
26 * the dialog box
27 *
28 */
29dialogChooseASEDateBox = function()
30{
31  var dialogOptions = {
32      id:'',
33      eventOk:null,
34      cBuilder:null,
35
36      values: {
37        dateType:'c', //c:creation, a:available
38        from:'',
39        to:'',
40        searchType:'bt'
41      },
42    };
43
44  /**
45   * initialize the dialog box
46   */
47  var initDialogBox = function()
48  {
49    $("#iDialogASEDateChoose")
50    .dialog(
51      {
52        autoOpen: false,
53        resizable: false,
54        width:550,
55        height:200,
56        modal: true,
57        draggable:true,
58        dialogClass: 'gcBgTabSheet gcBorder',
59        title: '{/literal}{"ase_choose_date"|@translate}{literal}',
60        open: function(event, ui)
61        {
62        },
63        buttons:
64        {
65          '{/literal}{"ase_ok"|@translate}{literal}':
66            function()
67            {
68              if(checkValidity())
69              {
70                dialogOptions.values.dateType=$('[name=fASEDateDateType]:checked').val();
71                dialogOptions.values.from=$('#iASEDateFrom').val();
72                dialogOptions.values.to=$('#iASEDateTo').val();
73                dialogOptions.values.searchType=$('#iASEDateSearchType').val();
74
75                switch(dialogOptions.values.searchType)
76                {
77                  case 'gt':
78                  case 'eq':
79                    dialogOptions.values.to='';
80                    break;
81                  case 'lt':
82                    dialogOptions.values.from='';
83                    break;
84                }
85
86                if(dialogOptions.cBuilder!=null)
87                {
88                  setCBuilderItem(dialogOptions.id, dialogOptions.values);
89                }
90
91                if(dialogOptions.eventOk!=null)
92                {
93                  dialogOptions.eventOk(dialogOptions.id, dialogOptions.values);
94                }
95                $(this).dialog('close');
96              }
97            },
98          '{/literal}{"ase_cancel"|@translate}{literal}':
99            function()
100            {
101              $(this).dialog('close');
102            }
103        }
104      }
105    );
106
107    $("#iASEDateFrom").datepicker({dateFormat:'yy-mm-dd'});
108    $('#iASEDateTo').datepicker({dateFormat:'yy-mm-dd'});
109    $('#iASEDateSearchType').bind('change', changeSearchType);
110  }
111
112
113  /**
114   * called when the search type is changed
115   */
116  var changeSearchType = function ()
117  {
118    switch($('#iASEDateSearchType').val())
119    {
120      case 'bt':
121        $("#iASEDateFromRow").show();
122        $("#iASEDateToRow").show();
123        break;
124      case 'gt':
125      case 'eq':
126        $("#iASEDateFromRow").show();
127        $("#iASEDateToRow").hide();
128        break;
129      case 'lt':
130        $("#iASEDateFromRow").hide();
131        $("#iASEDateToRow").show();
132        break;
133    }
134  };
135
136
137  var isDate = function (s)
138  {
139    re=/\d{2,4}-\d\d-\d\d/i;
140    return((re.exec(s)!=null));
141  }
142
143  /**
144   * check the validity of the condition
145   * return Boolean : true if OK, otherwise false
146   */
147  var checkValidity = function ()
148  {
149    $(".error").removeClass('error');
150    returned=true;
151
152    switch($('#iASEDateSearchType').val())
153    {
154      case 'bt':
155        if(!isDate($("#iASEDateFrom").val() ))
156        {
157          $("#iASEDateFrom").addClass('error');
158          returned=false;
159          alert("{/literal}{'ase_error_date_from'|@translate}{literal}");
160        }
161        if(!isDate($("#iASEDateTo").val() ))
162        {
163          $("#iASEDateTo").addClass('error');
164          returned=false;
165          alert("{/literal}{'ase_error_date_to'|@translate}{literal}");
166        }
167        if(returned && $("#iASEDateFrom").val() > $("#iASEDateTo").val())
168        {
169          $("#iASEDateTo, #iASEDateFrom").addClass('error');
170          returned=false;
171          alert("{/literal}{'ase_error_period'|@translate}{literal}");
172        }
173        break;
174      case 'gt':
175        if(!isDate($("#iASEDateFrom").val() ))
176        {
177          $("#iASEDateFrom").addClass('error');
178          alert("{/literal}{'ase_error_date'|@translate}{literal}");
179          returned=false;
180        }
181        break;
182      case 'lt':
183        if(!isDate($("#iASEDateTo").val() ))
184        {
185          $("#iASEDateTo").addClass('error');
186          alert("{/literal}{'ase_error_date'|@translate}{literal}");
187          returned=false;
188        }
189        break;
190    }
191
192    return(returned);
193  }
194
195
196  /**
197   * the show() function display and manage a dialog box to choose categories
198   * and the kind of test to apply
199   *
200   * @param options : properties to manage the dialog box
201   *                  - id : a string to identify a DOM object ; this parameter
202   *                         is given to the callback when the OK button is pushed
203   *                  - values : an object with 3 properties
204   *                               - dateType : 'c' for creation or 'a' for available
205   *                               - from :
206   *                               - to :
207   *                  - eventOK : a callback function, with 2 parameters : id of
208   *                              the given DOM object and values parameted
209   *                  - cBuilder : a criteriaBuilder object
210   *                               if set, the dialog box manage automaticaly
211   *                               the criteria builder interface
212   */
213  this.show = function (options)
214  {
215    showDialog(options);
216  }
217
218  /**
219   * private function used to show the dialog box
220   */
221  var showDialog = function(options)
222  {
223    if(options.id!=null)
224    {
225      dialogOptions.id=options.id;
226    }
227    else
228    {
229      dialogOptions.id='';
230    }
231
232    if(options.eventOk!=null)
233    {
234      dialogOptions.eventOk=options.eventOk;
235    }
236
237    if(options.cBuilder!=null)
238    {
239      dialogOptions.cBuilder=options.cBuilder;
240      dialogOptions.cBuilder.doAction('setOptions',
241        {
242          onEdit:function (e) { editCB(e.data); },
243          onDelete:function (e) { deleteCB(e.data); },
244        }
245      );
246    }
247
248    if(options.values!=null)
249    {
250      dialogOptions.values=jQuery.extend(dialogOptions.values, options.values);
251    }
252    else
253    {
254      dialogOptions.values.dateType='c';
255      dialogOptions.values.from='';
256      dialogOptions.values.to='';
257      dialogOptions.values.searchType='bt';
258    }
259
260    if(dialogOptions.values.dateType=='c')
261    {
262      $('#iASEDateDateTypeC').get(0).checked=true;
263    }
264    else
265    {
266      $('#iASEDateDateTypeA').get(0).checked=true;
267    }
268    $('#iASEDateFrom').val(dialogOptions.values.from);
269    $('#iASEDateTo').val(dialogOptions.values.to);
270    $('#iASEDateSearchType').val(dialogOptions.values.searchType);
271
272    changeSearchType();
273
274    $("#iDialogASEDateChoose").dialog('open');
275  }
276
277
278
279  /**
280   * manage the 'edit' button from criteria builder interface
281   * @param String itemId : the itemId
282   */
283  var editCB = function (itemId)
284  {
285    extraData=dialogOptions.cBuilder.doAction('getExtraData', itemId);
286    showDialog(
287      {
288        id:itemId,
289        values:
290          {
291            dateType:extraData.param.dateType,
292            from:extraData.param.from,
293            to:extraData.param.from,
294            searchType:extraData.param.searchType
295          },
296      }
297    );
298  }
299
300  /**
301   * manage the 'delete' button from criteria builder interface
302   * @param String itemId : the itemId
303   */
304  var deleteCB = function (itemId)
305  {
306    dialogOptions.cBuilder.doAction('delete', itemId);
307  }
308
309  /**
310   * set the content for the cBuilder item
311   */
312  var setCBuilderItem = function(id)
313  {
314    var content="<div>{/literal}{'ase_the_date'|@translate}{literal} ";
315
316    if(dialogOptions.values.dateType=='c')
317    {
318      content+="{/literal}{'ase_image_shot'|@translate}{literal}&nbsp;";
319    }
320    else
321    {
322      content+="{/literal}{'ase_image_availability'|@translate}{literal}&nbsp;";
323    }
324
325    switch(dialogOptions.values.searchType)
326    {
327      case 'eq':
328        content+="{/literal}{'ase_is_equal_to'|@translate}{literal} <span style='font-style:italic;'>"+dialogOptions.values.from+'</span>';
329        break;
330      case 'bt':
331        content+="{/literal}{'ase_is_between'|@translate}{literal} <span style='font-style:italic;'>"+dialogOptions.values.from+"</span> {/literal}{'ase_is_between_and'|@translate}{literal} <span style='font-style:italic;'>"+dialogOptions.values.to+"</span>";
332        break;
333      case 'gt':
334        content+="{/literal}{'ase_is_greater_or_equal'|@translate}{literal} <span style='font-style:italic;'>"+dialogOptions.values.from+"</span>";
335        break;
336      case 'lt':
337        content+="{/literal}{'ase_is_less_or_equal'|@translate}{literal} <span style='font-style:italic;'>"+dialogOptions.values.to+"</span>";
338        break;
339    }
340    content+="</div>";
341
342
343    if(id=='')
344    {
345      //no id:add a new item in the list
346      dialogOptions.cBuilder.doAction(
347        'add',
348        content,
349        criteriaBuilder.makeExtendedData(
350          'ASEDate',
351          {
352            dateType:dialogOptions.values.dateType,
353            searchType:dialogOptions.values.searchType,
354            from:dialogOptions.values.from,
355            to:dialogOptions.values.to
356          }
357        )
358      );
359    }
360    else
361    {
362      // update item
363      dialogOptions.cBuilder.doAction(
364        'edit',
365        id,
366        content,
367        criteriaBuilder.makeExtendedData(
368          'ASEDate',
369          {
370            dateType:dialogOptions.values.dateType,
371            searchType:dialogOptions.values.searchType,
372            from:dialogOptions.values.from,
373            to:dialogOptions.values.to
374          }
375        )
376      );
377    }
378  }
379
380  initDialogBox();
381}
382
383
384</script>
385{/literal}
386
387<div id="iDialogASEDateChoose" style='display:none;'>
388
389  <table class="formtable">
390    <tr>
391      <td>{'ase_search_on_date'|@translate}</td>
392      <td>
393         <label><input type="radio" id="iASEDateDateTypeC" name='fASEDateDateType' value='c' >&nbsp;{'ase_image_shot'|@translate}</label><br>
394         <label><input type="radio" id="iASEDateDateTypeA" name='fASEDateDateType' value='a' >&nbsp;{'ase_image_availability'|@translate}</label>
395      </td>
396    </tr>
397
398
399    <tr>
400      <td>{'ase_the_date'|@translate}</td>
401      <td>
402        <select id="iASEDateSearchType">
403          <option value="eq">{'ase_is_equal_to'|@translate} ...</option>
404          <option value="bt">{'ase_is_between'|@translate} ... {'ase_is_between_and'|@translate} ...</option>
405          <option value="gt">{'ase_is_greater_or_equal'|@translate} ... </option>
406          <option value="lt">{'ase_is_less_or_equal'|@translate} ... </option>
407        </select>
408      </td>
409    </tr>
410
411
412    <tr id="iASEDateFromRow">
413      <td>&nbsp;</td>
414      <td>
415         <input type="text" id="iASEDateFrom">
416      </td>
417    </tr>
418
419    <tr id="iASEDateToRow">
420      <td>&nbsp;</td>
421      <td>
422         <input type="text" id="iASEDateTo">
423      </td>
424    </tr>
425
426
427  </table>
428
429</div>
430
431
Note: See TracBrowser for help on using the repository browser.