1// declare main object of module 2var ModuleName = function(sName) 3{ 4 // set name 5 this.name = sName; 6 7 // set name 8 this.oldVersion = false; 9 10 // set translated js msgs 11 this.msgs = {}; 12 13 // stock error array 14 this.aError = []; 15 16 // set url of admin img 17 this.sImgUrl = ''; 18 19 // set this in obj context 20 var oThis = this; 21 22 /** 23 * show() method execute show effect and assign HTML in 24 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 25 * @param string sId : container to show in 26 * @param string sHtml : HTML to display 27 * @return - 28 */ 29 this.show = function(sId, sHtml) 30 { 31 $("#" + sId).html(sHtml).css('style', 'none'); 32 $("#" + sId).show('fast'); 33 }; 34 35 /** 36 * hide() method execute hide effect and delete html 37 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 38 * @param string sId : container to hide in 39 * @return - 40 */ 41 this.hide = function(sId) 42 { 43 $("#" + sId).hide('fast', function() 44 { 45 $("#" + sId).html(''); 46 } 47 ); 48 }; 49 50 /** 51 * form() method check all fields of current form and execute : XHR or submit => used for update all admin config 52 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 53 * @see ajax 54 * @param string sForm : form 55 * @param string sURI : query params used for XHR 56 * @param string sRequestParam : param action and type in order to send with post mode 57 * @param string sToDisplay : 58 * @param string sToHide : force to hide specific ID 59 * @param bool bSubmit : used only for sending main form 60 * @param bool bFancyBox : used only for fancybox in xhr 61 * @param string sCallback : 62 * @param string sErrorType : 63 * @return string : HTML returned by smarty 64 */ 65 this.form = function(sForm, sURI, sRequestParam, sToDisplay, sToHide, bSubmit, bFancyBox, sCallback, sErrorType, bFilter) 66 { 67 // set return validation 68 var aError = []; 69 70 if (bFilter) { 71 $('#bCheckReview, #sSelectAction').remove(); 72 $('#sType').val('moderation'); 73 $('#sAction').val('display'); 74 } 75 76 // get all fields of form 77 var fields = $("#" + sForm).serializeArray(); 78 79 // set counter 80 var iCounter = 0; 81 82 // set bIsError 83 var bIsError = false; 84 85 // set check review 86 var bCheckReview = false; 87 var bCheckedReview = false; 88 89 // check element form 90 jQuery.each(fields, function(i, field) { 91 bIsError = false; 92 93 switch(field.name) { 94 case oThis.name + 'DelayEmail' : 95 if (isNaN(field.value)) { 96 oThis.aError[iCounter] = oThis.msgs.delay; 97 bIsError = true; 98 } 99 break; 100 case oThis.name + 'ReviewTitle' : 101 if (field.value == '' && $('#bCheckFieldText').val() == 'true') { 102 oThis.aError[iCounter] = oThis.msgs.title; 103 bIsError = true; 104 } 105 break; 106 case oThis.name + 'ReviewComment' : 107 if (field.value == '' && $('#bCheckFieldText').val() == 'true') { 108 oThis.aError[iCounter] = oThis.msgs.description; 109 bIsError = true; 110 } 111 break; 112 case oThis.name + 'Email' : 113 if (field.value == '' && $('#' + oThis.name + 'EnableEmail :checked').val() == 'true') { 114 oThis.aError[iCounter] = oThis.msgs.email; 115 bIsError = true; 116 } 117 break; 118 case 'iRating' : 119 if (field.value == 0) { 120 oThis.aError[iCounter] = oThis.msgs.rating; 121 bIsError = true; 122 } 123 break; 124 case 'bCheckReview' : 125 bCheckReview = true; 126 break; 127 default: 128 // check if language field 129 if (field.name.indexOf('TabTitle') != -1 && field.value == '') { 130 var aLangId = field.name.split('_'); 131 oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]]; 132 133 bIsError = true; 134 } 135 // check if language field for subject email 136 if (field.name.indexOf('TabEmailTitle') != -1 && field.value == '' && $('#' + oThis.name + 'EnableCallbackDiv :checked').val() == 'true') { 137 var aLangId = field.name.split('_'); 138 oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]]; 139 140 bIsError = true; 141 } 142 // check if language field for sentence of FB post 143 if (field.name.indexOf('TabFBPostPhrase') != -1 && field.value == '' && $('#' + oThis.name + 'EnableFbPostDiv :checked').val() == 'true') { 144 var aLangId = field.name.split('_'); 145 oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]]; 146 147 bIsError = true; 148 } 149 // check if language field for label of FB post 150 if (field.name.indexOf('TabFBPostLabel') != -1 && field.value == '' && $('#' + oThis.name + 'EnableFbPostDiv :checked').val() == 'true') { 151 var aLangId = field.name.split('_'); 152 oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]]; 153 154 bIsError = true; 155 } 156 if (bCheckReview && (field.name.indexOf('CheckReview') != -1 || field.name.indexOf('CheckRating') != -1)) { 157 bCheckedReview = true; 158 } 159 break; 160 } 161 162 if ($('#' + field.name) != undefined && bIsError == true) { 163 $('#' + field.name).css('border', '1px solid red'); 164 ++iCounter; 165 } 166 }); 167 168 if (bCheckReview && !bCheckedReview) { 169 oThis.aError[iCounter] = oThis.msgs.checkreview; 170 bIsError = true; 171 } 172 173 // use case - no errors in form 174 if (oThis.aError.length == 0) { 175 // use case - Ajax request
176 if (bSubmit == undefined || bSubmit == null || !bSubmit) { 177 // format objet of fields in string to execute Ajax request 178 var sFormParams = $.param(fields); 179 180 if (sCallback != null) { 181 switch (sCallback) { 182 case 'updateDescSort' : 183 var sDescList = this.updateDescSort(); 184 185 if (sDescList != '') { 186 sFormParams += '&' + oThis.name + 'DescList=' + sDescList; 187 } 188 break; 189 default: 190 break; 191 } 192 } 193 194 // hide current 195 this.hide(sForm); 196 197 if (sRequestParam != null && sRequestParam != '') { 198 sFormParams = sRequestParam + '&' + sFormParams; 199 } 200 201 // execute Ajax request 202 this.ajax(sURI, sFormParams, sToDisplay, sToHide, bFancyBox); 203 204 return true; 205 } 206 // use case - send form 207 else { 208 document.forms[sForm].submit(); 209 return true; 210 } 211 } 212 // display errors 213 this.displayError(sErrorType); 214 215 return false; 216 }; 217 218 219 /** 220 * ajax() method execute XHR 221 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 222 * @param string sURI : query params used for XHR 223 * @param string sParams : 224 * @param string sToShow : 225 * @param string sToHide : 226 * @param bool bFancyBox : used only for fancybox in xhr 227 * @return string : HTML returned by smarty 228 */ 229 this.ajax = function(sURI, sParams, sToShow, sToHide, bFancyBox) 230 { 231 if(bFancyBox) { 232 $.fancybox.showActivity(); 233 } 234 235 sParams = 'sMode=xhr' + ((sParams == null || sParams == undefined) ? '' : '&' + sParams) ; 236 237 var $loader = sToHide ? $('#' + sToHide).next('.gsr-ajax-loader').show() : $(); 238 239 // configure XHR 240 $.ajax({ 241 type : 'POST', 242 url : sURI, 243 data : sParams, 244 dataType : 'html', 245 success: function(data) { 246 $loader.hide(); 247 if(bFancyBox) { 248 // update fancybox content 249 $.fancybox(data); 250 251 // replace query action and type 252 sParams = sParams.replace(/(sAction=)[a-zA-Z]+/, '$1' + 'display'); 253 sParams = sParams.replace(/(sType=)[a-zA-Z]+/, '$1' + 'moderation'); 254 255 // use case - update only widget list 256 if (sToShow == oThis.name + 'ModerationList') { 257 oThis.ajax('' + sURI + '', '' + sParams + '', '' + sToShow + '', '' + sToHide + ''); 258 } 259 } 260 else if (sToShow != null && sToHide != null) { 261 // same hide and show 262 if (sToShow == sToHide) { 263 $('#' + sToHide).hide('fast'); 264 $('#' + sToHide).empty(); 265 oThis.show(sToShow, data); 266 } 267 else { 268 oThis.hide(sToHide); 269 setTimeout('', 1000); 270 oThis.show(sToShow, data); 271 } 272 } 273 else if (sToShow != null) { 274 oThis.show(sToShow, data); 275 } 276 else if (sToHide != null) { 277 oThis.hide(sToHide); 278 } 279 }, 280 error: function(xhr, ajaxOptions, thrownError) { 281 $loader.hide(); 282 $("#" + oThis.name + "FormError").addClass('alert error'); 283 oThis.show("#" + oThis.name + "FormError", '<h3>internal error</h3>'); 284 } 285 }); 286 }; 287 288 /** 289 * displayError() method display errors 290 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 291 * @param string sType : type of container 292 * @return bool 293 */ 294 this.displayError = function(sType) 295 { 296 if (oThis.aError.length != 0) { 297 var sError = ''; 298 for (var i = 0; i < oThis.aError.length;++i) { 299 sError += '<li>' + oThis.aError[i] + '</li>'; 300 } 301 $("#" + oThis.name + sType + "Error ol").html(sError); 302 var singularPlural = 'singular'; 303 if (oThis.aError.length > 1) { 304 singularPlural = 'plural'; 305 } 306 $("#" + oThis.name + sType + "Error ."+singularPlural+" span").html(' '+oThis.aError.length+' '); 307 $("#" + oThis.name + sType + "Error ."+singularPlural).show(); 308 309 $("#" + oThis.name + sType + "Error").show(); 310 311 var fixed_header_height = 170; 312 if (window.innerWidth < 768) { 313 fixed_header_height = 110; 314 } 315 316 $("#" + oThis.name + sType + "Error a.button").live('click', function () { 317 $("#" + oThis.name + sType + "Error").hide(); 318 $("#" + oThis.name + sType + "Error ."+singularPlural+" span").html(''); 319 $("#" + oThis.name + sType + "Error ."+singularPlural).hide(); 320 }); 321 322 // flush errors 323 oThis.aError = []; 324 325 return false;
326 } 327 }; 328 329 /** 330 * sortDesc() method set sortable desc 331 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 332 * @param obj Current HTML elt 333 * @return - 334 */ 335 this.sortDesc = function() 336 { 337 // set sortable elt 338 $( "#" + oThis.name + "SortableDesc" ).sortable(); 339 $( "#" + oThis.name + "SortableDesc" ).disableSelection(); 340 }; 341 342 /** 343 * updateDescSort() method verify all childnodes of des list and determine position to manage snippets desc 344 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 345 * @param - 346 * @return string : HTML returned by smarty 347 */ 348 this.updateDescSort = function() 349 { 350 var sList = ''; 351 352 if ($("#" + oThis.name + "SortableDesc li").length != 0) { 353 var aDescId = []; 354 $("#" + oThis.name + "SortableDesc li").each(function(i, elt) 355 { 356 aDescId[i] = elt.id; 357 } 358 ); 359 sList = aDescId.toString(); 360 } 361 return sList; 362 }; 363 364 /** 365 * changeSelect() method displays or hide related option form 366 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 367 * @param string sId : type of container 368 * @param string sDestId 369 * @return 370 */ 371 this.changeSelect = function(sId, sDestId) 372 { 373 $("#" + sId).bind($.browser.msie ? 'click' : 'change', function (event) 374 { 375 $("#" + sId + " input:checked").each(function () 376 { 377 switch ($(this).val()) { 378 case 'true' : 379 // display option features 380 $("#" + sDestId).fadeIn('fast', function() {$("#" + sDestId).css('display', 'block')}); 381 break; 382 default: 383 // hide option features 384 $("#" + sDestId).fadeOut('fast'); 385 break; 386 } 387 }); 388 }); 389 }; 390 391 /** 392 * selectAll() method select / deselect all checkbox 393 * User: Business Tech (www.businesstech.fr) - Contact: [email protected] 394 * @param string sId : type of container 395 * @param string sCible : all checkbox to process 396 * @return 397 */ 398 this.selectAll = function(sId, sCible) 399 { 400 $("#" + sId).bind($.browser.msie ? 'click' : 'change', function (event) 401 { 402 if (this.checked == true) { 403 $(sCible).attr('checked', true); 404 } 405 else{ 406 $(sCible).attr('checked', false); 407 } 408 }); 409 }; 410};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.