source: extensions/ColorStat/templates/cstat_dialog_colors_choose.tpl @ 6176

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

Improve algorythm for colors analysis + use GPCRequestBuilder interface instead of a local interface

File size: 8.5 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{known_script id="jquery.tipTip" src=$ROOT_URL|@cat:"themes/default/js/plugins/jquery.tipTip.minified.js"}
4
5
6{literal}
7<script type="text/javascript">
8
9/**
10 * include this template in a page and use colorBox.show({options}) to display
11 * the dialog box
12 *
13 */
14dialogChooseColorBox = function()
15{
16  var selectedColors = new Array();
17  var dialogColorOptions = {
18      colorList:'',
19      mode:'and',
20      id:'',
21      eventOk:null,
22      cBuilder:null,
23    };
24
25  /**
26   * initialize the dialog box
27   */
28  var initDialogBox = function()
29  {
30    $('.tiptip').tipTip(
31      {
32        'delay' : 0,
33        'fadeIn' : 0,
34        'fadeOut' : 0,
35        'edgeOffset' : 5,
36      }
37    );
38
39    $("#iDialogColorChoose")
40    .dialog(
41      {
42        autoOpen: false,
43        resizable: false,
44        width:720,
45        height:400,
46        modal: true,
47        draggable:true,
48        dialogClass: 'gcBgTabSheet gcBorder',
49        title: '{/literal}{"cstat_choose_colors"|@translate}{literal}',
50        open: function(event, ui)
51        {
52
53        },
54        buttons:
55        {
56          '{/literal}{"cstat_ok"|@translate}{literal}':
57            function()
58            {
59              list='';
60              nbColor=$('#iDCCchoosenColors div').length;
61              for(i=0;i<nbColor;i++)
62              {
63                if(list!='') { list+=','; }
64                list+=$('#iDCCchoosenColors div').get(i).id.substr(13);
65              }
66
67              if($('#iDCCOperatorAnd').get(0).checked)
68              {
69                mode='and';
70              }
71              else if($('#iDCCOperatorOr').get(0).checked)
72              {
73                mode='or';
74              }
75              else if($('#iDCCOperatorNot').get(0).checked)
76              {
77                mode='not';
78              }
79
80              if(dialogColorOptions.cBuilder!=null)
81              {
82                setCBuilderItem(dialogColorOptions.id, list, mode);
83              }
84
85              if(dialogColorOptions.eventOk!=null)
86              {
87                dialogColorOptions.eventOk(dialogColorOptions.id, list, mode);
88              }
89
90              $(this).dialog('close');
91            },
92          '{/literal}{"cstat_cancel"|@translate}{literal}':
93            function()
94            {
95              $(this).dialog('close');
96            }
97        }
98      }
99    );
100
101    $('#iDCCtableColor td.csSelectable').bind('click', function() { addColorList(this.id.substr(10)); });
102  }
103
104  /**
105   * remove a color from the choosen colors list
106   * event.data : the color top remove
107   */
108  var removeColorList = function(event)
109  {
110    $('#iDCCselected_'+event.data).remove();
111  }
112
113  /**
114   * add a color from the choosen colors list
115   */
116  var addColorList = function(color)
117  {
118    if($('#iDCCselected_'+color).get(0)==null)
119    {
120      $('#iDCCchoosenColors').append("<div id='iDCCselected_"+color+"' class='cellColorChoose' style='background-color:#"+color+";'></div>");
121      $('#iDCCselected_'+color).bind('click', color, removeColorList);
122    }
123    else
124    {
125      alert("{/literal}{'cstat_color_already_choosen'|@translate}{literal}")
126    }
127  }
128
129
130  /**
131   * the show() function display and manage a dialog box to choose
132   * a set of colors from a color table
133   *
134   * @param options : properties to manage the dialog box
135   *                  - colorList : a string of hex color, separated with a comma
136   *                                example: 'ff0000,00ff00,0000ff'
137   *                                if set, theses colors are selected when the
138   *                                dialog box is open
139   *                  - id : a string to identify a DOM object ; this parameter
140   *                         is given to the callback when the OK button is pushed
141   *                  - mode : a string to identify the default mode selected
142   *                           values : 'and', 'or', 'not'
143   *                  - eventOK : a callback function, with 2 parameters : id of
144   *                              the given DOM object and the color list
145   *                  - cBuilder : a criteriaBuilder object
146   *                               if set, the dialog box manage automaticaly
147   *                               the criteria builder interface
148   */
149  this.show = function (options)
150  {
151    showDialog(options);
152  }
153
154  /**
155   * private function used to show the dialog box
156   */
157  var showDialog = function(options)
158  {
159    if(options.colorList!=null)
160    {
161      dialogColorOptions.colorList=options.colorList;
162    }
163    else
164    {
165      dialogColorOptions.colorList='';
166    }
167
168    if(options.mode!=null)
169    {
170      dialogColorOptions.mode=options.mode;
171    }
172    else
173    {
174      dialogColorOptions.mode='and';
175    }
176
177    if(options.id!=null)
178    {
179      dialogColorOptions.id=options.id;
180    }
181    else
182    {
183      dialogColorOptions.id='';
184    }
185
186    if(options.eventOk!=null)
187    {
188      dialogColorOptions.eventOk=options.eventOk;
189    }
190
191    if(options.cBuilder!=null)
192    {
193      dialogColorOptions.cBuilder=options.cBuilder;
194      dialogColorOptions.cBuilder.doAction('setOptions',
195        {
196          onEdit:function (e) { editCB(e.data); },
197          onDelete:function (e) { deleteCB(e.data); },
198        }
199      );
200    }
201
202
203    $('#iDCCchoosenColors').html('');
204
205    if(dialogColorOptions.colorList!='')
206    {
207      selectedColors=dialogColorOptions.colorList.split(',');
208      for(i=0;i<selectedColors.length;i++)
209      {
210        addColorList(selectedColors[i]);
211      }
212    }
213    switch(dialogColorOptions.mode)
214    {
215      case 'and':
216        $('#iDCCOperatorAnd').attr('checked', true);
217        break;
218      case 'or':
219        $('#iDCCOperatorOr').attr('checked', true);
220        break;
221      case 'not':
222        $('#iDCCOperatorNot').attr('checked', true);
223        break;
224    }
225    $("#iDialogColorChoose").dialog('open');
226  }
227
228
229
230  /**
231   * manage the 'edit' button from criteria builder interface
232   * @param String itemId : the itemId
233   */
234  var editCB = function (itemId)
235  {
236    extraData=dialogColorOptions.cBuilder.doAction('getExtraData', itemId);
237    showDialog(
238      {
239        id:itemId,
240        colorList:extraData.param.colors,
241        mode:extraData.param.mode,
242      }
243    );
244  }
245
246  /**
247   * manage the 'delete' button from criteria builder interface
248   * @param String itemId : the itemId
249   */
250  var deleteCB = function (itemId)
251  {
252    dialogColorOptions.cBuilder.doAction('delete', itemId);
253  }
254
255  /**
256   * set the content for the cBuilder item
257   */
258  var setCBuilderItem = function(id, colorList, mode)
259  {
260    content="<div>";
261    switch(mode)
262    {
263      case 'and':
264        content+="{/literal}{'cstat_operator_and'|@translate}{literal}";
265        break;
266      case 'or':
267        content+="{/literal}{'cstat_operator_or'|@translate}{literal}";
268        break;
269      case 'not':
270        content+="{/literal}{'cstat_operator_not'|@translate}{literal}";
271        break;
272    }
273    content+="</div>";
274
275    content+="<div style='float:left;'>";
276    selectedColors=colorList.split(',');
277    for(i=0;i<selectedColors.length;i++)
278    {
279      content+="<div class='cellColorChoose' style='background-color:#"+selectedColors[i]+";'></div>";
280    }
281    content+="</div>";
282
283    if(id=='')
284    {
285      //no id:add a new item in the list
286      dialogColorOptions.cBuilder.doAction('add', content, criteriaBuilder.makeExtendedData('ColorStat', {mode:mode, colors:colorList} ) );
287    }
288    else
289    {
290      // update item
291      dialogColorOptions.cBuilder.doAction('edit', id,  content, criteriaBuilder.makeExtendedData('ColorStat', {mode:mode, colors:colorList} ) );
292    }
293  }
294
295  initDialogBox();
296}
297
298
299</script>
300{/literal}
301
302<div id="iDialogColorChoose" style='display:none;'>
303  <table style="padding-top:8px;">
304    <tr>
305      <td style='width:350px;' id='iDCCtableColor'>{$datas.colorTable}</td>
306      <td style='padding:12px;'>
307        <span>{'cstat_choosen_colors'|@translate}</span>
308
309        <div id='iDCCchoosenColors' style='height:56px;border:1px solid;margin:2px;padding:4px;'>
310        </div>
311
312        <div style='text-align:justify;padding:8px;'>
313          <label><input type="radio" name="f_operator" id="iDCCOperatorAnd" checked>&nbsp;{'cstat_operator_and'|@translate}</label><br>
314          <label><input type="radio" name="f_operator" id="iDCCOperatorOr">&nbsp;{'cstat_operator_or'|@translate}</label><br>
315          <label><input type="radio" name="f_operator" id="iDCCOperatorNot">&nbsp;{'cstat_operator_not'|@translate}</label>
316        </div>
317      </td>
318    </tr>
319  </table>
320</div>
321
322
Note: See TracBrowser for help on using the repository browser.