[8962] | 1 | /** |
---|
| 2 | * userPersonnalisedBlockManage |
---|
| 3 | * |
---|
[10247] | 4 | * release 1.0.2 |
---|
[8962] | 5 | */ |
---|
| 6 | function userPersonnalisedBlockManage(opt, keys, token, initValues) |
---|
| 7 | { |
---|
| 8 | var options = { |
---|
| 9 | ajaxUrl:'plugins/AMenuManager/amm_ajax.php' |
---|
| 10 | }, |
---|
| 11 | translatedKeys= { |
---|
| 12 | g002_ok:'g002_ok', |
---|
| 13 | g002_cancel:'g002_cancel', |
---|
| 14 | g002_loading: 'g002_loading', |
---|
| 15 | g002_editofpersonalised : 'g002_editofpersonalised', |
---|
| 16 | g002_createofpersonalised : 'g002_createofpersonalised' |
---|
| 17 | }, |
---|
| 18 | properties = { |
---|
| 19 | id:'', |
---|
| 20 | token:token |
---|
| 21 | }, |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * load blocks list |
---|
| 25 | */ |
---|
| 26 | load = function () |
---|
| 27 | { |
---|
| 28 | $('#iList').html("<br>"+translatedKeys.g002_loading+"<br><img src='./plugins/GrumPluginClasses/icons/processing.gif'>"); |
---|
| 29 | |
---|
| 30 | $.ajax( |
---|
| 31 | { |
---|
| 32 | type: "POST", |
---|
| 33 | url: options.ajaxUrl, |
---|
| 34 | async: true, |
---|
[16006] | 35 | data: { ajaxfct:"admin.blocks.list", token:properties.token }, |
---|
[8962] | 36 | success: |
---|
| 37 | function(msg) |
---|
| 38 | { |
---|
| 39 | $("#iList").html(msg); |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | ); |
---|
| 43 | }, |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * edit or create a new block |
---|
| 47 | * |
---|
| 48 | * @param String blockId : if empty, assume to create a new block |
---|
| 49 | */ |
---|
| 50 | edit = function (blockId) |
---|
| 51 | { |
---|
| 52 | properties.id=blockId; |
---|
| 53 | |
---|
| 54 | $('#iDialogEdit') |
---|
| 55 | .dialog('option', 'title', (blockId=='')?translatedKeys.g002_createofpersonalised:translatedKeys.g002_editofpersonalised) |
---|
| 56 | .dialog("open"); |
---|
| 57 | }, |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * remove a block |
---|
| 61 | * |
---|
| 62 | * @param String blockId : block to remove |
---|
| 63 | */ |
---|
| 64 | remove = function (blockId) |
---|
| 65 | { |
---|
| 66 | properties.id=blockId; |
---|
| 67 | |
---|
| 68 | $.ajax( |
---|
| 69 | { |
---|
| 70 | type: "POST", |
---|
| 71 | url: options.ajaxUrl, |
---|
| 72 | async: true, |
---|
| 73 | data: { ajaxfct:"admin.blocks.delete", id:properties.id, token:properties.token }, |
---|
| 74 | success: |
---|
| 75 | function(msg) |
---|
| 76 | { |
---|
| 77 | load(); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | ); |
---|
| 81 | }, |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | * check validity of form |
---|
| 85 | */ |
---|
| 86 | checkValidity = function () |
---|
| 87 | { |
---|
| 88 | $('.error').removeClass('error'); |
---|
| 89 | ok=true; |
---|
| 90 | /* |
---|
| 91 | if($('#iamm_label').inputText('value')=='') |
---|
| 92 | { |
---|
| 93 | $('#iamm_label').inputText('isValid', false); |
---|
| 94 | ok=false; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if($('#iamm_url').inputText('value')=='') |
---|
| 98 | { |
---|
| 99 | $('#iamm_url').inputText('isValid', false); |
---|
| 100 | ok=false; |
---|
| 101 | } |
---|
| 102 | */ |
---|
| 103 | return(ok); |
---|
| 104 | }, |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * update values of the dialog box |
---|
| 109 | * |
---|
| 110 | * @param String items : json string ; if empty assume to reset all fields |
---|
| 111 | * with default values |
---|
| 112 | */ |
---|
| 113 | updateDialog = function (items) |
---|
| 114 | { |
---|
| 115 | if(items=='') |
---|
| 116 | { |
---|
| 117 | $('#iamm_personalised_nfo').inputText('value', ''); |
---|
| 118 | $('#iamm_personalised_title') |
---|
| 119 | .inputText('value', '') |
---|
[9019] | 120 | .inputText('languagesValues', ':clear'); |
---|
[8962] | 121 | $('#iamm_personalised_content') |
---|
| 122 | .inputText('value', '') |
---|
[9019] | 123 | .inputText('languagesValues', ':clear'); |
---|
[8962] | 124 | $('#iamm_personalised_visible').inputRadio('value', 'y'); |
---|
| 125 | } |
---|
| 126 | else |
---|
| 127 | { |
---|
| 128 | var tmp=$.parseJSON(items), |
---|
| 129 | titles={}, |
---|
| 130 | contents={}; |
---|
| 131 | |
---|
| 132 | for(var lang in tmp.langs) |
---|
| 133 | { |
---|
| 134 | titles[lang]=tmp.langs[lang].title; |
---|
| 135 | contents[lang]=tmp.langs[lang].content; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | $('#iamm_personalised_nfo').inputText('value', tmp.nfo); |
---|
[9019] | 139 | $('#iamm_personalised_title').inputText('languagesValues', ':clear').inputText('languagesValues', titles); |
---|
| 140 | $('#iamm_personalised_content').inputText('languagesValues', ':clear').inputText('languagesValues', contents); |
---|
[8962] | 141 | $('#iamm_personalised_visible').inputRadio('value', tmp.visible); |
---|
| 142 | } |
---|
| 143 | }, |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | * update values on server |
---|
| 147 | */ |
---|
| 148 | doUpdate = function () |
---|
| 149 | { |
---|
| 150 | displayProcessing(true); |
---|
| 151 | |
---|
| 152 | // build datas |
---|
| 153 | var langs=[], |
---|
[9010] | 154 | titles=$('#iamm_personalised_title').inputText('languagesValues'), |
---|
| 155 | contents=$('#iamm_personalised_content').inputText('languagesValues'); |
---|
[8962] | 156 | |
---|
| 157 | for(var lang in titles) |
---|
| 158 | { |
---|
| 159 | langs.push( |
---|
| 160 | { |
---|
| 161 | lang:lang, |
---|
| 162 | title:titles[lang], |
---|
| 163 | content:contents[lang] |
---|
| 164 | } |
---|
| 165 | ); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | var datas = { |
---|
| 172 | nfo:$('#iamm_personalised_nfo').inputText('value'), |
---|
| 173 | visible:$('#iamm_personalised_visible').inputRadio('value'), |
---|
| 174 | langs:langs |
---|
| 175 | }; |
---|
| 176 | |
---|
| 177 | $.ajax( |
---|
| 178 | { |
---|
| 179 | type: "POST", |
---|
| 180 | url: options.ajaxUrl, |
---|
| 181 | async: true, |
---|
| 182 | data: { ajaxfct:"admin.blocks.set", id:properties.id, token:properties.token, datas:datas }, |
---|
| 183 | success: |
---|
| 184 | function(msg) |
---|
| 185 | { |
---|
| 186 | displayProcessing(false); |
---|
| 187 | |
---|
| 188 | if(msg.match(/^[0-9]+$/i)!=null) |
---|
| 189 | { |
---|
| 190 | // result Ok ! => close the dialog box and reload the list |
---|
| 191 | $('#iDialogEdit').dialog("close"); |
---|
| 192 | load(); |
---|
| 193 | } |
---|
| 194 | else |
---|
| 195 | { |
---|
| 196 | returned=msg.split('!'); |
---|
| 197 | $('#'+returned[0]).addClass('error'); |
---|
| 198 | alert(returned[1]); |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | ); |
---|
| 203 | }, |
---|
| 204 | |
---|
| 205 | /** |
---|
| 206 | * display or hide the processing flower |
---|
| 207 | */ |
---|
| 208 | displayProcessing = function (visible) |
---|
| 209 | { |
---|
| 210 | if(visible) |
---|
| 211 | { |
---|
| 212 | $('#iBDProcessing').css("display", "block"); |
---|
| 213 | } |
---|
| 214 | else |
---|
| 215 | { |
---|
| 216 | $('#iBDProcessing').css("display", "none"); |
---|
| 217 | } |
---|
| 218 | }, |
---|
| 219 | |
---|
| 220 | /** |
---|
| 221 | * initialize the object |
---|
| 222 | */ |
---|
| 223 | init = function (initValues) |
---|
| 224 | { |
---|
| 225 | var buttons={}; |
---|
| 226 | |
---|
| 227 | buttons[translatedKeys.g002_ok]=function() |
---|
| 228 | { |
---|
| 229 | if(checkValidity()) doUpdate(); |
---|
| 230 | }; |
---|
| 231 | buttons[translatedKeys.g002_cancel]=function() |
---|
| 232 | { |
---|
| 233 | $('#iDialogEdit').dialog("close"); |
---|
| 234 | }; |
---|
| 235 | |
---|
| 236 | $('#iDialogEdit') |
---|
| 237 | .dialog( |
---|
| 238 | { |
---|
| 239 | autoOpen:false, |
---|
| 240 | width:800, |
---|
| 241 | height:480, |
---|
| 242 | modal: true, |
---|
| 243 | dialogClass: 'gcBgTabSheet gcBorder', |
---|
| 244 | title: '', |
---|
| 245 | buttons:buttons |
---|
| 246 | } |
---|
| 247 | ) |
---|
| 248 | .bind('dialogopen', function () |
---|
| 249 | { |
---|
| 250 | if(properties.id!='') |
---|
| 251 | { |
---|
| 252 | displayProcessing(true); |
---|
| 253 | |
---|
| 254 | $.ajax( |
---|
| 255 | { |
---|
| 256 | type: "POST", |
---|
| 257 | url: options.ajaxUrl, |
---|
| 258 | async: true, |
---|
[16006] | 259 | data: { ajaxfct:"admin.blocks.get", token:properties.token, id:properties.id }, |
---|
[8962] | 260 | success: |
---|
| 261 | function(msg) |
---|
| 262 | { |
---|
| 263 | updateDialog(msg); |
---|
| 264 | displayProcessing(false); |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | ); |
---|
| 268 | } |
---|
| 269 | else |
---|
| 270 | { |
---|
| 271 | updateDialog(''); |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | ); |
---|
| 275 | |
---|
[16744] | 276 | $('#islang').inputList({popupMode:'mouseout', listMaxHeight:250}); |
---|
[8962] | 277 | |
---|
| 278 | |
---|
| 279 | $('#iamm_personalised_nfo').inputText( |
---|
| 280 | { |
---|
| 281 | displayChar:75, |
---|
| 282 | maxChar:255 |
---|
| 283 | } |
---|
| 284 | ); |
---|
| 285 | |
---|
| 286 | $('#iamm_personalised_title').inputText( |
---|
| 287 | { |
---|
| 288 | displayChar:75, |
---|
| 289 | maxChar:255, |
---|
| 290 | languages:initValues.langs, |
---|
| 291 | currentLanguage:initValues.userLang, |
---|
| 292 | languageSelector:'islang' |
---|
| 293 | } |
---|
| 294 | ); |
---|
| 295 | |
---|
| 296 | $('#iamm_personalised_content').inputText( |
---|
| 297 | { |
---|
| 298 | multilines:true, |
---|
| 299 | displayChar:70, |
---|
| 300 | numRows:13, |
---|
| 301 | languages:initValues.langs, |
---|
| 302 | currentLanguage:initValues.userLang, |
---|
| 303 | languageSelector:'islang' |
---|
| 304 | } |
---|
| 305 | ); |
---|
| 306 | |
---|
| 307 | $('#islang').inputList('value', initValues.userLang); |
---|
| 308 | |
---|
| 309 | $('#iamm_personalised_visible').inputRadio(); |
---|
| 310 | |
---|
| 311 | load(); |
---|
| 312 | }; |
---|
| 313 | |
---|
| 314 | $.extend(options, opt); |
---|
| 315 | $.extend(translatedKeys, keys); |
---|
| 316 | |
---|
| 317 | this.load = function () { load(); }; |
---|
| 318 | this.edit = function (linkId) { edit(linkId); }; |
---|
| 319 | this.remove = function (linkId) { remove(linkId); }; |
---|
| 320 | |
---|
| 321 | init(initValues); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | |
---|