source: extensions/ASearchEngine/templates/ase_dialog_category_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.6 KB
Line 
1{combine_script id="gpc.categorySelector" path="plugins/GrumPluginClasses/js/ui.categorySelector.js" require='jquery,jquery.ui'}
2{combine_css path="plugins/GrumPluginClasses/css/categorySelector.css"}
3
4{literal}
5<style type='text/css'>
6#iASECategoryCategory {
7  width:500px;
8}
9</style>
10
11<script type="text/javascript">
12/**
13 * include this template in a page and use dialogChooseASECategoryBox.show({options}) to display
14 * the dialog box
15 *
16 */
17dialogChooseASECategoryBox = function()
18{
19  var dialogOptions = {
20      id:'',
21      eventOk:null,
22      cBuilder:null,
23
24      values: {
25        subCat:'=',
26        catIdList:new Array()
27      },
28    };
29
30  /**
31   * initialize the dialog box
32   */
33  var initDialogBox = function()
34  {
35    $("#iDialogASECategoryChoose")
36    .dialog(
37      {
38        autoOpen: false,
39        resizable: false,
40        width:765,
41        height:200,
42        modal: true,
43        draggable:true,
44        dialogClass: 'gcBgTabSheet gcBorder',
45        title: '{/literal}{"ase_choose_categories"|@translate}{literal}',
46        open: function(event, ui)
47        {
48        },
49        buttons:
50        {
51          '{/literal}{"ase_ok"|@translate}{literal}':
52            function()
53            {
54              if(checkValidity())
55              {
56                dialogOptions.values.catIdList=$('#iASECategoryCategory').categorySelector('value');
57                dialogOptions.values.subCat=$('#iASECategorySubCat').val();
58
59
60                if(dialogOptions.cBuilder!=null)
61                {
62                  setCBuilderItem(dialogOptions.id, dialogOptions.values);
63                }
64
65                if(dialogOptions.eventOk!=null)
66                {
67                  dialogOptions.eventOk(dialogOptions.id, dialogOptions.values);
68                }
69                $(this).dialog('close');
70              }
71            },
72          '{/literal}{"ase_cancel"|@translate}{literal}':
73            function()
74            {
75              $(this).dialog('close');
76            }
77        }
78      }
79    )
80    .parent().css('overflow', 'visible');
81
82
83
84
85    $('#iASECategoryCategory').categorySelector(
86      {
87        multiple:true,
88        listMaxWidth:1,
89        listMaxHeight:350,
90        displayStatus:{/literal}{if is_admin()}true{else}false{/if}{literal},
91        levelIndent:20,
92        userMode:{/literal}{if is_admin()}'admin'{else}'public'{/if}{literal},
93        galleryRoot:false,
94        load: function (event) { $(this).categorySelector('collapse', ':all'); }
95      }
96    );
97
98  }
99
100
101  /**
102   * check the validity of the condition
103   * return Boolean : true if OK, otherwise false
104   */
105  var checkValidity = function ()
106  {
107
108    if($('#iASECategoryCategory').categorySelector('value') .length==0)
109    {
110      alert('ase_one_category_must_be_selected');
111      return(false);
112    }
113    return(true);
114  }
115
116
117  /**
118   * the show() function display and manage a dialog box to choose categories
119   * and the kind of test to apply
120   *
121   * @param options : properties to manage the dialog box
122   *                  - id : a string to identify a DOM object ; this parameter
123   *                         is given to the callback when the OK button is pushed
124   *                  - values : an object with 2 properties
125   *                               - subCat : true or false, search in subcategories
126   *                               - catIdList : an array of categories Id
127   *                  - eventOK : a callback function, with 2 parameters : id of
128   *                              the given DOM object and values parameted
129   *                  - cBuilder : a criteriaBuilder object
130   *                               if set, the dialog box manage automaticaly
131   *                               the criteria builder interface
132   */
133  this.show = function (options)
134  {
135    showDialog(options);
136  }
137
138  /**
139   * private function used to show the dialog box
140   */
141  var showDialog = function(options)
142  {
143    if(options.id!=null)
144    {
145      dialogOptions.id=options.id;
146    }
147    else
148    {
149      dialogOptions.id='';
150    }
151
152    if(options.eventOk!=null)
153    {
154      dialogOptions.eventOk=options.eventOk;
155    }
156
157    if(options.cBuilder!=null)
158    {
159      dialogOptions.cBuilder=options.cBuilder;
160      dialogOptions.cBuilder.doAction('setOptions',
161        {
162          onEdit:function (e) { editCB(e.data); },
163          onDelete:function (e) { deleteCB(e.data); },
164        }
165      );
166    }
167
168    if(options.values!=null)
169    {
170      dialogOptions.values=jQuery.extend(dialogOptions.values, options.values);
171    }
172    else
173    {
174      dialogOptions.values.subCat='y';
175      dialogOptions.values.catIdList=0;
176    }
177    $('#iASECategorySubCat').val(dialogOptions.values.subCat);
178    $('#iASECategoryCategory').categorySelector('value', ':none');
179    $('#iASECategoryCategory').categorySelector('value', dialogOptions.values.catIdList);
180    $('#iASECategoryCategory').categorySelector('collapse', ':all');
181    for(var i=0;i<dialogOptions.values.catIdList.length;i++)
182    {
183      $('#iASECategoryCategory').categorySelector('expand', dialogOptions.values.catIdList[i]+'<');
184    }
185
186
187    $("#iDialogASECategoryChoose").dialog('open');
188  }
189
190
191
192  /**
193   * manage the 'edit' button from criteria builder interface
194   * @param String itemId : the itemId
195   */
196  var editCB = function (itemId)
197  {
198    extraData=dialogOptions.cBuilder.doAction('getExtraData', itemId);
199    showDialog(
200      {
201        id:itemId,
202        values:
203          {
204            subCat:extraData.param.subCat,
205            catIdList:extraData.param.catIdList,
206          },
207      }
208    );
209  }
210
211  /**
212   * manage the 'delete' button from criteria builder interface
213   * @param String itemId : the itemId
214   */
215  var deleteCB = function (itemId)
216  {
217    dialogOptions.cBuilder.doAction('delete', itemId);
218  }
219
220  /**
221   * set the content for the cBuilder item
222   */
223  var setCBuilderItem = function(id)
224  {
225    var content="<div>",
226        list=$('#iASECategoryCategory').categorySelector('name');
227
228    if(dialogOptions.values.catIdList.length==1)
229    {
230      content+="{/literal}{'ase_category'|@translate}{literal}";
231    }
232    else
233    {
234      content+="{/literal}{'ase_categories'|@translate}{literal}";
235    }
236
237    if(dialogOptions.values.subCat=='y')
238    {
239      content+="&nbsp;({/literal}{'ase_with_search_in_subcat'|@translate}{literal})";
240    }
241    content+="&nbsp:";
242
243
244    content+="<div style='font-style:italic;padding-left:15px;'>"
245    for(i=0;i<list.length;i++)
246    {
247      content+=list[i]+"<br>";
248    }
249
250    content+="</div></div>";
251
252
253    if(id=='')
254    {
255      //no id:add a new item in the list
256      dialogOptions.cBuilder.doAction(
257        'add',
258        content,
259        criteriaBuilder.makeExtendedData(
260          'ASECategory',
261          {
262            subCat:dialogOptions.values.subCat,
263            catIdList:dialogOptions.values.catIdList
264          }
265        )
266      );
267    }
268    else
269    {
270      // update item
271      dialogOptions.cBuilder.doAction(
272        'edit',
273        id,
274        content,
275        criteriaBuilder.makeExtendedData(
276          'ASECategory',
277          {
278            subCat:dialogOptions.values.subCat,
279            catIdList:dialogOptions.values.catIdList
280          }
281        )
282      );
283    }
284  }
285
286  initDialogBox();
287}
288
289
290</script>
291{/literal}
292
293<div id="iDialogASECategoryChoose" style='display:none;'>
294
295  <table class="formtable">
296    <tr>
297      <td>{'ase_categories'|@translate}</td>
298      <td>
299        <div id='iASECategoryCategory'></div>
300      </td>
301    </tr>
302
303    <tr>
304      <td>{'ase_searching_in_subcat'|@translate}</td>
305      <td>
306        <select id='iASECategorySubCat'>
307          <option value='y'>{'ase_y'|@translate}</option>
308          <option value='n'>{'ase_n'|@translate}</option>
309        </select>
310      </td>
311    </tr>
312  </table>
313
314</div>
315
316
Note: See TracBrowser for help on using the repository browser.