source: extensions/ASearchEngine/templates/ase_dialog_rate_choose.tpl @ 7318

Last change on this file since 7318 was 7196, checked in by grum, 14 years ago

Commit first files

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