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