| 6 | | |
| 7 | | |
| 8 | | {literal} |
| 9 | | <script type="text/javascript"> |
| 10 | | var cb=null; |
| 11 | | |
| 12 | | interfaceManager = function(optionsToSet) |
| 13 | | { |
| 14 | | var pn=null, |
| 15 | | requestNumber=0, |
| 16 | | options = |
| 17 | | { |
| 18 | | requestCriterionsVisible:'', |
| 19 | | requestCriterionsHidden:'', |
| 20 | | requestResult:'', |
| 21 | | requestResultContent:'', |
| 22 | | requestResultNfo:'', |
| 23 | | requestResultPagesNavigator:'', |
| 24 | | requestResultRequestNumber:0, |
| 25 | | onPageChange:null, |
| 26 | | numberPerPage:30, |
| 27 | | }; |
| 28 | | |
| 29 | | /** |
| 30 | | * |
| 31 | | */ |
| 32 | | this.doAction = function(fct) |
| 33 | | { |
| 34 | | switch(fct) |
| 35 | | { |
| 36 | | case 'queryResult': |
| 37 | | /* function 'queryResult' : when query is executed, prepare the interface |
| 38 | | */ |
| 39 | | if(arguments.length==3) |
| 40 | | { |
| 41 | | displayQueryResult(arguments[1], arguments[2]); |
| 42 | | } |
| 43 | | break; |
| 44 | | case 'queryPage': |
| 45 | | /* function 'queryPage' : display returned page |
| 46 | | */ |
| 47 | | if(arguments.length==3) |
| 48 | | { |
| 49 | | displayQueryPage(arguments[1], arguments[2]); |
| 50 | | } |
| 51 | | break; |
| 52 | | case 'show': |
| 53 | | /* function 'show' : show/hide the query/result |
| 54 | | */ |
| 55 | | if(arguments.length==2) |
| 56 | | { |
| 57 | | show(arguments[1]); |
| 58 | | } |
| 59 | | break; |
| 60 | | case 'setOptions': |
| 61 | | /* function 'setOptions' : allows to set options after the object was |
| 62 | | * created |
| 63 | | */ |
| 64 | | if(arguments.length==2) |
| 65 | | { |
| 66 | | setOptions(arguments[1]); |
| 67 | | } |
| 68 | | break; |
| 69 | | case 'fillCaddie': |
| 70 | | /* function 'fillCaddie' : allows to fill the caddie with the search result |
| 71 | | * |
| 72 | | */ |
| 73 | | if(arguments.length==2) |
| 74 | | { |
| 75 | | fillCaddie(arguments[1], this.getRequestNumber()); |
| 76 | | } |
| 77 | | break; |
| 78 | | } |
| 79 | | } |
| 80 | | |
| 81 | | /** |
| 82 | | * returns the current request number |
| 83 | | */ |
| 84 | | this.getRequestNumber = function () |
| 85 | | { |
| 86 | | return(requestNumber); |
| 87 | | } |
| 88 | | |
| 89 | | /** |
| 90 | | * returns the number of items per page |
| 91 | | */ |
| 92 | | this.getNumberPerPage = function () |
| 93 | | { |
| 94 | | return(options.numberPerPage); |
| 95 | | } |
| 96 | | |
| 97 | | /** |
| 98 | | * this function show/hide the different panels |
| 99 | | * 'buildQuery' : hide the result panel and display the panel to build query |
| 100 | | * 'resultQuery' : hide the panel to build query and display the result panel |
| 101 | | */ |
| 102 | | var show = function(mode) |
| 103 | | { |
| 104 | | switch(mode) |
| 105 | | { |
| 106 | | case 'buildQuery': |
| 107 | | $('.'+options.requestCriterionsVisible).css('display', 'block'); |
| 108 | | $('.'+options.requestCriterionsHidden).css('display', 'none'); |
| 109 | | $('.'+options.requestResult).css('display', 'none'); |
| 110 | | break; |
| 111 | | case 'resultQuery': |
| 112 | | $('#iResultQueryContent').html("<br><img class='waitingResult' src='./plugins/GrumPluginClasses/icons/processing.gif'>"); |
| 113 | | $('.'+options.requestCriterionsVisible).css('display', 'none'); |
| 114 | | $('.'+options.requestCriterionsHidden).css('display', 'block'); |
| 115 | | $('.'+options.requestResult).css('display', 'block'); |
| 116 | | break; |
| 117 | | } |
| 118 | | } |
| 119 | | |
| 120 | | /** |
| 121 | | * this function display the number of items found and prepare the page |
| 122 | | * navigator |
| 123 | | * |
| 124 | | * @param String nfo : 2 information separated with a semi-colon ';' |
| 125 | | * requestNumber;numberOfItems |
| 126 | | */ |
| 127 | | var displayQueryResult = function (isSuccess, nfo) |
| 128 | | { |
| 129 | | if(isSuccess) |
| 130 | | { |
| 131 | | nfo=nfo.split(';'); |
| 132 | | |
| 133 | | requestNumber=nfo[0]; |
| 134 | | $('#iResultQueryNfo').html(nfo[1]); |
| 135 | | pn.doAction('setOptions', { numberItem:nfo[1], defaultPage:1 } ); |
| 136 | | show('resultQuery'); |
| 137 | | } |
| 138 | | else |
| 139 | | { |
| 140 | | //$('#'+options.requestResultContent).html(""); |
| 141 | | show('buildQuery'); |
| 142 | | alert('{/literal}{"gpc_something_is_wrong_on_the_server_side"|@translate}{literal}'); |
| 143 | | } |
| 144 | | } |
| 145 | | |
| 146 | | |
| 147 | | /** |
| 148 | | * this function display the number of items found and prepare the page |
| 149 | | * navigator |
| 150 | | * |
| 151 | | * @param String nfo : 2 information separated with a semi-colon ';' |
| 152 | | * requestNumber;numberOfItems |
| 153 | | */ |
| 154 | | var displayQueryPage = function (isSuccess, nfo) |
| 155 | | { |
| 156 | | if(isSuccess) |
| 157 | | { |
| 158 | | $('#iResultQueryContent').html(nfo); |
| 159 | | $('.tiptip').tipTip( |
| 160 | | { |
| 161 | | 'delay' : 0, |
| 162 | | 'fadeIn' : 0, |
| 163 | | 'fadeOut' : 0, |
| 164 | | 'edgeOffset' : 5, |
| 165 | | } |
| 166 | | ); |
| 167 | | } |
| 168 | | else |
| 169 | | { |
| 170 | | alert('{/literal}{"gpc_something_is_wrong_on_the_server_side"|@translate}{literal}'); |
| 171 | | } |
| 172 | | } |
| 173 | | |
| 174 | | |
| 175 | | /** |
| 176 | | * |
| 177 | | * @param Object optionsToSet : set the given options |
| 178 | | */ |
| 179 | | var setOptions = function(optionsToSet) |
| 180 | | { |
| 181 | | if(typeof optionsToSet=='object') |
| 182 | | { |
| 183 | | options = jQuery.extend(options, optionsToSet); |
| 184 | | } |
| 185 | | } |
| 186 | | |
| 187 | | /** |
| 188 | | * initialize the object |
| 189 | | */ |
| 190 | | var init = function (optionsToSet) |
| 191 | | { |
| 192 | | setOptions(optionsToSet); |
| 193 | | |
| 194 | | pn = new pagesNavigator(options.requestResultPagesNavigator, |
| 195 | | { |
| 196 | | itemPerPage:options.numberPerPage, |
| 197 | | displayNumPage:9, |
| 198 | | classActive:'pnActive{/literal}{$datas.themeName}{literal}', |
| 199 | | classInactive:'pnInactive{/literal}{$datas.themeName}{literal}', |
| 200 | | onPageChange: function (page) |
| 201 | | { |
| 202 | | if(options.onPageChange!=null && jQuery.isFunction(options.onPageChange)) |
| 203 | | { |
| 204 | | options.onPageChange(requestNumber, page, options.numberPerPage); |
| 205 | | } |
| 206 | | }, |
| 207 | | } |
| 208 | | ); |
| 209 | | |
| 210 | | requestNumber=options.requestResultRequestNumber; |
| 211 | | } |
| 212 | | |
| 213 | | /** |
| 214 | | * fill the caddie with the search results |
| 215 | | * @param String mode : 'add' or 'fill' |
| 216 | | */ |
| 217 | | var fillCaddie = function (mode, requestNumber) |
| 218 | | { |
| 219 | | $('#iMenuCaddieImg').css('display', 'inline-block'); |
| 220 | | $('#iMenuCaddieItems ul').css('display', 'none'); |
| 221 | | |
| 222 | | $.ajax( |
| 223 | | { |
| 224 | | type: "POST", |
| 225 | | url: "plugins/GrumPluginClasses/gpc_ajax.php", |
| 226 | | async: true, |
| 227 | | data: { ajaxfct:"admin.rbuilder.fillCaddie", fillMode:mode, requestNumber:requestNumber }, |
| 228 | | success: |
| 229 | | function(msg) |
| 230 | | { |
| 231 | | $('#iMenuCaddieImg').css('display', 'none'); |
| 232 | | $('#iMenuCaddieItems ul').css('display', 'block'); |
| 233 | | alert('{/literal}{"gpc_the_caddie_is_updated"|@translate}{literal}'); |
| 234 | | }, |
| 235 | | error: |
| 236 | | function(msg) |
| 237 | | { |
| 238 | | $('#iMenuCaddieImg').css('display', 'none'); |
| 239 | | $('#iMenuCaddieItems ul').css('display', 'block'); |
| 240 | | alert('{/literal}{"gpc_something_is_wrong_on_the_server_side"|@translate}{literal}'); |
| 241 | | }, |
| 242 | | } |
| 243 | | ); |
| 244 | | } |
| 245 | | |
| 246 | | init(optionsToSet); |
| 247 | | } |
| 248 | | |
| 249 | | |
| 250 | | function init() |
| 251 | | { |
| 252 | | im = new interfaceManager( |
| 253 | | { |
| 254 | | requestCriterionsVisible:'cRequestCriterions', |
| 255 | | requestCriterionsHidden:'cModifyRequest', |
| 256 | | requestResult:'cResultQuery', |
| 257 | | requestResultContent:'iResultQueryContent', |
| 258 | | requestResultNfo:'iResultQueryNfo', |
| 259 | | requestResultPagesNavigator:'iPagesNavigator', |
| 260 | | } |
| 261 | | ); |
| 262 | | |
| 263 | | {/literal} |
| 264 | | |
| 265 | | |
| 266 | | |
| 267 | | {if defined('IN_ADMIN')} |
| 268 | | requestBuilderOptions.imgEditUrl='{$ROOT_URL}{$themeconf.admin_icon_dir}/edit_s.png'; |
| 269 | | requestBuilderOptions.imgDeleteUrl='{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png'; |
| 270 | | {else} |
| 271 | | requestBuilderOptions.imgEditUrl='{$ROOT_URL}{$themeconf.icon_dir}/edit.png'; |
| 272 | | requestBuilderOptions.imgDeleteUrl='{$ROOT_URL}{$themeconf.icon_dir}/delete.png'; |
| 273 | | {/if} |
| 274 | | {literal} |
| 275 | | |
| 276 | | requestBuilderOptions.classGroup='gcBorderInput gcTextInput'; |
| 277 | | requestBuilderOptions.classItem='gcBgInput gcTextInput'; |
| 278 | | requestBuilderOptions.classOperator='cbOperator cbOperatorBg{/literal}{$datas.themeName}{literal} gcLinkHover'; |
| 279 | | requestBuilderOptions.onRequestSuccess = function (msg) { im.doAction('queryResult', true, msg); cb.doAction('getPage', im.getRequestNumber(), 1, im.getNumberPerPage()); }; |
| 280 | | requestBuilderOptions.onRequestError = function (msg) { im.doAction('queryResult', false, msg); }; |
| 281 | | requestBuilderOptions.onGetPageSuccess = function (msg) { im.doAction('queryPage', true, msg); }; |
| 282 | | requestBuilderOptions.onGetPageError = function (msg) { im.doAction('queryPage', false, msg); }; |
| 283 | | |
| 284 | | cb = new criteriaBuilder('iListSelectedCriterions', requestBuilderOptions); |
| 285 | | |
| 286 | | im.doAction('setOptions', |
| 287 | | { |
| 288 | | onPageChange: |
| 289 | | function (requestNumber, page, numberPerPage) |
| 290 | | { |
| 291 | | $('#iResultQueryContent').html("<br><img class='waitingResult' src='./plugins/GrumPluginClasses/icons/processing.gif'>"); |
| 292 | | cb.doAction('getPage', requestNumber, page, numberPerPage); |
| 293 | | } |
| 294 | | } |
| 295 | | ); |
| 296 | | } |
| 297 | | </script> |
| 298 | | {/literal} |
| | 4 | {known_script id="gpc.rbSearch" src=$ROOT_URL|@cat:"plugins/GrumPluginClasses/js/rbSearch.packed.js"} |