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

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

feature:2639 - Compatibility with Piwigo 2.4

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