source: extensions/ASearchEngine/templates/ase_dialog_tag_choose.tpl @ 15360

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

feature:2635 - Compatibility with Piwigo 2.4

  • Property svn:executable set to *
File size: 7.2 KB
Line 
1{combine_script id="gpc.tagSelector" path="plugins/GrumPluginClasses/js/ui.tagSelector.js" require='jquery,jquery.ui'}
2
3{literal}
4
5<script type="text/javascript">
6/**
7 * include this template in a page and use dialogChooseASETagBox.show({options}) to display
8 * the dialog box
9 *
10 */
11dialogChooseASETagBox = function()
12{
13  var dialogOptions = {
14      id:'',
15      eventOk:null,
16      cBuilder:null,
17
18      values: {
19        tags:[],
20        method:'AND'
21      },
22    };
23
24  /**
25   * initialize the dialog box
26   */
27  var initDialogBox = function()
28  {
29    $("#iDialogASETagChoose")
30    .dialog(
31      {
32        autoOpen: false,
33        resizable: false,
34        width:550,
35        height:200,
36        modal: true,
37        draggable:true,
38        dialogClass: 'gcBgTabSheet gcBorder',
39        title: '{/literal}{"ase_search_tags"|@translate}{literal}',
40        open: function(event, ui)
41        {
42        },
43        buttons:
44        {
45          '{/literal}{"ase_ok"|@translate}{literal}':
46            function()
47            {
48              if(checkValidity())
49              {
50                dialogOptions.values.tags=$("#iBDTagTags").tagSelector('value');
51                dialogOptions.values.method=$('[name=fBDTagMethod]:checked').val();
52
53                if(dialogOptions.cBuilder!=null)
54                {
55                  setCBuilderItem(dialogOptions.id, dialogOptions.values);
56                }
57
58                if(dialogOptions.eventOk!=null)
59                {
60                  dialogOptions.eventOk(dialogOptions.id, dialogOptions.values);
61                }
62                $(this).dialog('close');
63              }
64            },
65          '{/literal}{"ase_cancel"|@translate}{literal}':
66            function()
67            {
68              $(this).dialog('close');
69            }
70        }
71      }
72    );
73
74    $("#iBDTagTags").tagSelector(
75      {
76        listMaxWidth:400,
77        listMaxHeight:350,
78        maximumTagLoaded:150,
79        filter:'affected',
80        {/literal}
81        textStart:"{'ase_tag_start_to_type_text'|@translate}",
82        textDisplay:"{'ase_tag_x_tags_display'|@translate}",
83        textFound:"{'ase_tag_x_tags_found'|@translate}",
84          {if is_admin()}
85        mode:'admin',
86          {else}
87        mode:'public',
88          {/if}
89        {literal}
90      }
91    );
92
93  }
94
95  /**
96   * check the validity of the condition
97   * return Boolean : true if OK, otherwise false
98   */
99  var checkValidity = function ()
100  {
101    $(".error").removeClass('error');
102    returned=true;
103
104    if($('#iBDTagTags').tagSelector('numberOfTags')==0)
105    {
106      $('#iBDTagTags').addClass('error');
107      returned=false;
108      alert("{/literal}{'ase_error_no_tag_selected'|@translate}{literal}");
109    }
110    return(returned);
111  }
112
113
114  /**
115   * the show() function display and manage a dialog box to choose categories
116   * and the kind of test to apply
117   *
118   * @param options : properties to manage the dialog box
119   *                  - id : a string to identify a DOM object ; this parameter
120   *                         is given to the callback when the OK button is pushed
121   *                  - values : an object with 3 properties
122   *                               - withHD : with our without HD picture
123   *                  - eventOK : a callback function, with 2 parameters : id of
124   *                              the given DOM object and values parameted
125   *                  - cBuilder : a criteriaBuilder object
126   *                               if set, the dialog box manage automaticaly
127   *                               the criteria builder interface
128   */
129  this.show = function (options)
130  {
131    showDialog(options);
132  }
133
134  /**
135   * private function used to show the dialog box
136   */
137  var showDialog = function(options)
138  {
139    if(options.id!=null)
140    {
141      dialogOptions.id=options.id;
142    }
143    else
144    {
145      dialogOptions.id='';
146    }
147
148    if(options.eventOk!=null)
149    {
150      dialogOptions.eventOk=options.eventOk;
151    }
152
153    if(options.cBuilder!=null)
154    {
155      dialogOptions.cBuilder=options.cBuilder;
156      dialogOptions.cBuilder.doAction('setOptions',
157        {
158          onEdit:function (e) { editCB(e.data); },
159          onDelete:function (e) { deleteCB(e.data); },
160        }
161      );
162    }
163
164    if(options.values!=null)
165    {
166      dialogOptions.values=jQuery.extend(dialogOptions.values, options.values);
167    }
168    else
169    {
170      dialogOptions.values.tags=[];
171      dialogOptions.values.method='AND';
172    }
173
174    $("#iBDTagTags").tagSelector('value', 'clear').tagSelector('value', dialogOptions.values.tags);
175    $('#iBDTagMethodAND').attr('checked', dialogOptions.values.method=='AND');
176    $('#iBDTagMethodOR').attr('checked', dialogOptions.values.method=='OR');
177
178    $("#iDialogASETagChoose").dialog('open');
179  }
180
181
182
183  /**
184   * manage the 'edit' button from criteria builder interface
185   * @param String itemId : the itemId
186   */
187  var editCB = function (itemId)
188  {
189    extraData=dialogOptions.cBuilder.doAction('getExtraData', itemId);
190    showDialog(
191      {
192        id:itemId,
193        values:
194          {
195            tags:extraData.param.tags,
196            method:extraData.param.method,
197          },
198      }
199    );
200  }
201
202  /**
203   * manage the 'delete' button from criteria builder interface
204   * @param String itemId : the itemId
205   */
206  var deleteCB = function (itemId)
207  {
208    dialogOptions.cBuilder.doAction('delete', itemId);
209  }
210
211  /**
212   * set the content for the cBuilder item
213   */
214  var setCBuilderItem = function(id)
215  {
216    var content="";
217
218    for(var i=0;i<dialogOptions.values.tags.length;i++)
219    {
220      if(content!='') content+=', ';
221      content+=dialogOptions.values.tags[i].name;
222    }
223
224
225    if(dialogOptions.values.method=='AND')
226    {
227      content="<div>{/literal}{'ase_tag_method_and_text'|@translate}{literal}&nbsp;<span style='font-style:italic;'>"+content+"</span>";
228    }
229    else
230    {
231      content="<div>{/literal}{'ase_tag_method_or_text'|@translate}{literal}&nbsp;<span style='font-style:italic;'>"+content+"</span>";
232    }
233
234    content+="</div>";
235
236    if(id=='')
237    {
238      //no id:add a new item in the list
239      dialogOptions.cBuilder.doAction(
240        'add',
241        content,
242        criteriaBuilder.makeExtendedData(
243          'ASETag',
244          {
245            tags:dialogOptions.values.tags,
246            method:dialogOptions.values.method,
247          }
248        )
249      );
250    }
251    else
252    {
253      // update item
254      dialogOptions.cBuilder.doAction(
255        'edit',
256        id,
257        content,
258        criteriaBuilder.makeExtendedData(
259          'ASETag',
260          {
261            tags:dialogOptions.values.tags,
262            method:dialogOptions.values.method,
263          }
264        )
265      );
266    }
267  }
268
269  initDialogBox();
270}
271
272
273</script>
274{/literal}
275
276<div id="iDialogASETagChoose" style='display:none;'>
277
278  <table class="formtable">
279    <tr>
280      <td>{'ase_tags'|@translate}</td>
281      <td>
282        <div id="iBDTagTags" style="width:400px;"></div>
283      </td>
284    </tr>
285
286    <tr>
287      <td></td>
288      <td>
289        <label><input type='radio' id='iBDTagMethodAND' name='fBDTagMethod' value="AND">&nbsp;{'ase_tag_method_and'|@translate}</label><br>
290        <label><input type='radio' id='iBDTagMethodOR' name='fBDTagMethod' value="OR">&nbsp;{'ase_tag_method_or'|@translate}</label><br>
291      </td>
292    </tr>
293
294  </table>
295
296</div>
297
298
Note: See TracBrowser for help on using the repository browser.