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

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

feature:2635- compatibility with Piwigo 2.4

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