vendor: 18,083 bytes, lines 1-658
1// ==ClosureCompiler== 2// @compilation_level SIMPLE_OPTIMIZATIONS 3 4/** 5 * @license jqGrid 4.6.0 - jQuery Grid 6 * Copyright (c) 2008, Tony Tomov, [email protected] 7 * Dual licensed under the MIT and GPL licenses 8 * http://www.opensource.org/licenses/mit-license.php 9 * http://www.gnu.org/licenses/gpl-2.0.html 10 * Date: 2014-02-20 11 */ 12//jsHint options 13/*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */ 14/*global jQuery */ 15 16(function ($) { 17"use strict"; 18$.jgrid = $.jgrid || {}; 19$.extend($.jgrid,{ 20 version : "4.6.0", 21 htmlDecode : function(value){ 22 if(value && (value===' ' || value===' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";} 23 return !value ? value : String(value).replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"').replace(/&/g, "&"); 24 }, 25 htmlEncode : function (value){ 26 return !value ? value : String(value).replace(/&/g, "&").replace(/\"/g, """).replace(/</g, "<").replace(/>/g, ">"); 27 }, 28 format : function(format){ //jqgformat 29 var args = $.makeArray(arguments).slice(1); 30 if(format==null) { format = ""; } 31 return format.replace(/\{(\d+)\}/g, function(m, i){ 32 return args[i]; 33 }); 34 }, 35 msie : navigator.appName === 'Microsoft Internet Explorer', 36 msiever : function () { 37 var rv = -1; 38 var ua = navigator.userAgent; 39 var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 40 if (re.exec(ua) != null) { 41 rv = parseFloat( RegExp.$1 ); 42 } 43 return rv; 44 }, 45 getCellIndex : function (cell) { 46 var c = $(cell); 47 if (c.is('tr')) { return -1; } 48 c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0]; 49 if ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); } 50 return c.cellIndex; 51 }, 52 stripHtml : function(v) { 53 v = String(v); 54 var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi; 55 if (v) { 56 v = v.replace(regexp,""); 57 return (v && v !== ' ' && v !== ' ') ? v.replace(/\"/g,"'") : ""; 58 } 59 return v; 60 }, 61 stripPref : function (pref, id) { 62 var obj = $.type( pref ); 63 if( obj === "string" || obj === "number") { 64 pref = String(pref); 65 id = pref !== "" ? String(id).replace(String(pref), "") : id; 66 } 67 return id; 68 }, 69 parse : function(jsonString) { 70 var js = jsonString; 71 if (js.substr(0,9) === "while(1);") { js = js.substr(9); } 72 if (js.substr(0,2) === "/*") { js = js.substr(2,js.length-4); } 73 if(!js) { js = "{}"; } 74 return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ? 75 JSON.parse(js) : 76 eval('(' + js + ')'); 77 }, 78 parseDate : function(format, date, newformat, opts) { 79 var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g, 80 timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, 81 timezoneClip = /[^-+\dA-Z]/g, 82 msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"), 83 msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null), 84 pad = function (value, length) { 85 value = String(value); 86 length = parseInt(length,10) || 2; 87 while (value.length < length) { value = '0' + value; } 88 return value; 89 }, 90 ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0}, 91 timestamp=0, dM, k,hl, 92 h12to24 = function(ampm, h){ 93 if (ampm === 0){ if (h === 12) { h = 0;} } 94 else { if (h !== 12) { h += 12; } } 95 return h; 96 }; 97 if(opts === undefined) { 98 opts = $.jgrid.formatter.date; 99 } 100 // old lang files 101 if(opts.parseRe === undefined ) { 102 opts.parseRe = /[#%\\\/:_;.,\t\s-]/; 103 } 104 if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; } 105 if(date && date != null) { 106 if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") { 107 //Unix timestamp 108 timestamp = new Date( parseFloat(date)*1000 ); 109 } else if(date.constructor === Date) { 110 timestamp = date; 111 // Microsoft date format support 112 } else if( msMatch !== null ) { 113 timestamp = new Date(parseInt(msMatch[1], 10)); 114 if (msMatch[3]) { 115 var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]); 116 offset *= ((msMatch[4] === '-') ? 1 : -1); 117 offset -= timestamp.getTimezoneOffset(); 118 timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000))); 119 } 120 } else { 121 var offset = 0; 122 //Support ISO8601Long that have Z at the end to indicate UTC timezone 123 if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') { 124 offset -= (new Date()).getTimezoneOffset(); 125 } 126 date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe); 127 format = format.replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe); 128 // parsing for month names 129 for(k=0,hl=format.length;k<hl;k++){ 130 if(format[k] === 'M') { 131 dM = $.inArray(date[k],opts.monthNames); 132 if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];} 133 } 134 if(format[k] === 'F') { 135 dM = $.inArray(date[k],opts.monthNames,12); 136 if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];} 137 } 138 if(format[k] === 'a') { 139 dM = $.inArray(date[k],opts.AmPm); 140 if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){ 141 date[k] = dM; 142 ts.h = h12to24(date[k], ts.h); 143 } 144 } 145 if(format[k] === 'A') { 146 dM = $.inArray(date[k],opts.AmPm); 147 if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){ 148 date[k] = dM-2; 149 ts.h = h12to24(date[k], ts.h); 150 } 151 } 152 if (format[k] === 'g') { 153 ts.h = parseInt(date[k], 10); 154 } 155 if(date[k] !== undefined) { 156 ts[format[k].toLowerCase()] = parseInt(date[k],10); 157 } 158 } 159 if(ts.f) {ts.m = ts.f;} 160 if( ts.m === 0 && ts.y === 0 && ts.d === 0) { 161 return " " ; 162 } 163 ts.m = parseInt(ts.m,10)-1; 164 var ty = ts.y; 165 if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;} 166 else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;} 167 timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u); 168 //Apply offset to show date as local time. 169 if(offset > 0) { 170 timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000))); 171 } 172 } 173 } else { 174 timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u); 175 } 176 if( newformat === undefined ) { 177 return timestamp; 178 } 179 if( opts.masks.hasOwnProperty(newformat) ) { 180 newformat = opts.masks[newformat]; 181 } else if ( !newformat ) { 182 newformat = 'Y-m-d'; 183 } 184 var 185 G = timestamp.getHours(), 186 i = timestamp.getMinutes(), 187 j = timestamp.getDate(), 188 n = timestamp.getMonth() + 1, 189 o = timestamp.getTimezoneOffset(), 190 s = timestamp.getSeconds(), 191 u = timestamp.getMilliseconds(), 192 w = timestamp.getDay(), 193 Y = timestamp.getFullYear(), 194 N = (w + 6) % 7 + 1, 195 z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000, 196 flags = { 197 // Day 198 d: pad(j), 199 D: opts.dayNames[w], 200 j: j, 201 l: opts.dayNames[w + 7], 202 N: N, 203 S: opts.S(j), 204 //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th', 205 w: w, 206 z: z, 207 // Week 208 W: N < 5 ? Math.floor((z + N - 1) / 7) + 1 : Math.floor((z + N - 1) / 7) || ((new Date(Y - 1, 0, 1).getDay() + 6) % 7 < 4 ? 53 : 52), 209 // Month 210 F: opts.monthNames[n - 1 + 12], 211 m: pad(n), 212 M: opts.monthNames[n - 1], 213 n: n, 214 t: '?', 215 // Year 216 L: '?', 217 o: '?', 218 Y: Y, 219 y: String(Y).substring(2), 220 // Time 221 a: G < 12 ? opts.AmPm[0] : opts.AmPm[1], 222 A: G < 12 ? opts.AmPm[2] : opts.AmPm[3], 223 B: '?', 224 g: G % 12 || 12, 225 G: G, 226 h: pad(G % 12 || 12), 227 H: pad(G), 228 i: pad(i), 229 s: pad(s), 230 u: u, 231 // Timezone 232 e: '?', 233 I: '?', 234 O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), 235 P: '?', 236 T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""), 237 Z: '?', 238 // Full Date/Time 239 c: '?', 240 r: '?', 241 U: Math.floor(timestamp / 1000) 242 }; 243 return newformat.replace(token, function ($0) { 244 return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1); 245 }); 246 }, 247 jqID : function(sid){ 248 return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&"); 249 }, 250 guid : 1, 251 uidPref: 'jqg', 252 randId : function( prefix ) { 253 return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++); 254 }, 255 getAccessor : function(obj, expr) { 256 var ret,p,prm = [], i; 257 if( typeof expr === 'function') { return expr(obj); } 258 ret = obj[expr]; 259 if(ret===undefined) { 260 try { 261 if ( typeof expr === 'string' ) { 262 prm = expr.split('.'); 263 } 264 i = prm.length; 265 if( i ) { 266 ret = obj; 267 while (ret && i--) { 268 p = prm.shift(); 269 ret = ret[p]; 270 } 271 } 272 } catch (e) {} 273 } 274 return ret; 275 }, 276 getXmlData: function (obj, expr, returnObj) { 277 var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null; 278 if (typeof expr === 'function') { return expr(obj); } 279 if (m && m[2]) { 280 // m[2] is the attribute selector 281 // m[1] is an optional element selector 282 // examples: "[id]", "rows[page]" 283 return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]); 284 } 285 ret = $(expr, obj); 286 if (returnObj) { return ret; } 287 //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid 288 return ret.length > 0 ? $(ret).text() : undefined; 289 }, 290 cellWidth : function () { 291 var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;display:block;'></td></tr></table></div>"), 292 testCell = $testDiv.appendTo("body") 293 .find("td") 294 .width(); 295 $testDiv.remove(); 296 return Math.abs(testCell-5) > 0.1; 297 }, 298 cell_width : true, 299 ajaxOptions: {}, 300 from : function(source){ 301 // Original Author Hugo Bonacci 302 // License MIT http://jlinq.codeplex.com/license 303 var QueryObject=function(d,q){ 304 if(typeof d==="string"){ 305 d=$.data(d); 306 } 307 var self=this, 308 _data=d, 309 _usecase=true, 310 _trim=false, 311 _query=q, 312 _stripNum = /[\$,%]/g, 313 _lastCommand=null, 314 _lastField=null, 315 _orDepth=0, 316 _negate=false, 317 _queuedOperator="", 318 _sorting=[], 319 _useProperties=true; 320 if(typeof d==="object"&&d.push) { 321 if(d.length>0){ 322 if(typeof d[0]!=="object"){ 323 _useProperties=false; 324 }else{ 325 _useProperties=true; 326 } 327 } 328 }else{ 329 throw "data provides is not an array"; 330 } 331 this._hasData=function(){ 332 return _data===null?false:_data.length===0?false:true; 333 }; 334 this._getStr=function(s){ 335 var phrase=[]; 336 if(_trim){ 337 phrase.push("jQuery.trim("); 338 } 339 phrase.push("String("+s+")"); 340 if(_trim){ 341 phrase.push(")"); 342 } 343 if(!_usecase){ 344 phrase.push(".toLowerCase()"); 345 } 346 return phrase.join(""); 347 }; 348 this._strComp=function(val){ 349 if(typeof val==="string"){ 350 return".toString()"; 351 } 352 return""; 353 }; 354 this._group=function(f,u){ 355 return({field:f.toString(),unique:u,items:[]}); 356 }; 357 this._toStr=function(phrase){ 358 if(_trim){ 359 phrase=$.trim(phrase); 360 } 361 phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"'); 362 return _usecase ? phrase : phrase.toLowerCase(); 363 }; 364 this._funcLoop=function(func){ 365 var results=[]; 366 $.each(_data,function(i,v){ 367 results.push(func(v)); 368 }); 369 return results; 370 }; 371 this._append=function(s){ 372 var i; 373 if(_query===null){ 374 _query=""; 375 } else { 376 _query+=_queuedOperator === "" ? " && " :_queuedOperator; 377 } 378 for (i=0;i<_orDepth;i++){ 379 _query+="("; 380 } 381 if(_negate){ 382 _query+="!"; 383 } 384 _query+="("+s+")"; 385 _negate=false; 386 _queuedOperator=""; 387 _orDepth=0; 388 }; 389 this._setCommand=function(f,c){ 390 _lastCommand=f; 391 _lastField=c; 392 }; 393 this._resetNegate=function(){ 394 _negate=false; 395 }; 396 this._repeatCommand=function(f,v){ 397 if(_lastCommand===null){ 398 return self; 399 } 400 if(f!==null&&v!==null){ 401 return _lastCommand(f,v); 402 } 403 if(_lastField===null){ 404 return _lastCommand(f); 405 } 406 if(!_useProperties){ 407 return _lastCommand(f); 408 } 409 return _lastCommand(_lastField,f); 410 }; 411 this._equals=function(a,b){ 412 return(self._compare(a,b,1)===0); 413 }; 414 this._compare=function(a,b,d){ 415 var toString = Object.prototype.toString; 416 if( d === undefined) { d = 1; } 417 if(a===undefined) { a = null; } 418 if(b===undefined) { b = null; } 419 if(a===null && b===null){ 420 return 0; 421 } 422 if(a===null&&b!==null){ 423 return 1; 424 } 425 if(a!==null&&b===null){ 426 return -1; 427 } 428 if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') { 429 if (a < b) { return -d; } 430 if (a > b) { return d; } 431 return 0; 432 } 433 if(!_usecase && typeof a !== "number" && typeof b !== "number" ) { 434 a=String(a); 435 b=String(b); 436 } 437 if(a<b){return -d;} 438 if(a>b){return d;} 439 return 0; 440 }; 441 this._performSort=function(){ 442 if(_sorting.length===0){return;} 443 _data=self._doSort(_data,0); 444 }; 445 this._doSort=function(d,q){ 446 var by=_sorting[q].by, 447 dir=_sorting[q].dir, 448 type = _sorting[q].type, 449 dfmt = _sorting[q].datefmt, 450 sfunc = _sorting[q].sfunc; 451 if(q===_sorting.length-1){ 452 return self._getOrder(d, by, dir, type, dfmt, sfunc); 453 } 454 q++; 455 var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted; 456 for(i=0;i<values.length;i++){ 457 sorted=self._doSort(values[i].items,q); 458 for(j=0;j<sorted.length;j++){ 459 results.push(sorted[j]); 460 } 461 } 462 return results; 463 }; 464 this._getOrder=function(data,by,dir,type, dfmt, sfunc){ 465 var sortData=[],_sortData=[], newDir = dir==="a" ? 1 : -1, i,ab,j, 466 findSortKey; 467 468 if(type === undefined ) { type = "text"; } 469 if (type === 'float' || type=== 'number' || type=== 'currency' || type=== 'numeric') { 470 findSortKey = function($cell) { 471 var key = parseFloat( String($cell).replace(_stripNum, '')); 472 return isNaN(key) ? Number.NEGATIVE_INFINITY : key; 473 }; 474 } else if (type==='int' || type==='integer') { 475 findSortKey = function($cell) { 476 return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : Number.NEGATIVE_INFINITY; 477 }; 478 } else if(type === 'date' || type === 'datetime') { 479 findSortKey = function($cell) { 480 return $.jgrid.parseDate(dfmt,$cell).getTime(); 481 }; 482 } else if($.isFunction(type)) { 483 findSortKey = type; 484 } else { 485 findSortKey = function($cell) { 486 $cell = $cell ? $.trim(String($cell)) : ""; 487 return _usecase ? $cell : $cell.toLowerCase(); 488 }; 489 } 490 $.each(data,function(i,v){ 491 ab = by!=="" ? $.jgrid.getAccessor(v,by) : v; 492 if(ab === undefined) { ab = ""; } 493 ab = findSortKey(ab, v); 494 _sortData.push({ 'vSort': ab,'index':i}); 495 }); 496 if($.isFunction(sfunc)) { 497 _sortData.sort(function(a,b){ 498 a = a.vSort; 499 b = b.vSort; 500 return sfunc.call(this,a,b,newDir); 501 }); 502 } else { 503 _sortData.sort(function(a,b){ 504 a = a.vSort; 505 b = b.vSort; 506 return self._compare(a,b,newDir); 507 }); 508 } 509 j=0; 510 var nrec= data.length; 511 // overhead, but we do not change the original data. 512 while(j<nrec) { 513 i = _sortData[j].index; 514 sortData.push(data[i]); 515 j++; 516 } 517 return sortData; 518 }; 519 this._getGroup=function(data,by,dir,type, dfmt){ 520 var results=[], 521 group=null, 522 last=null, val; 523 $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){ 524 val = $.jgrid.getAccessor(v, by); 525 if(val == null) { val = ""; } 526 if(!self._equals(last,val)){ 527 last=val; 528 if(group !== null){ 529 results.push(group); 530 } 531 group=self._group(by,val); 532 } 533 group.items.push(v); 534 }); 535 if(group !== null){ 536 results.push(group); 537 } 538 return results; 539 }; 540 this.ignoreCase=function(){ 541 _usecase=false; 542 return self; 543 }; 544 this.useCase=function(){ 545 _usecase=true; 546 return self; 547 }; 548 this.trim=function(){ 549 _trim=true; 550 return self; 551 }; 552 this.noTrim=function(){ 553 _trim=false; 554 return self; 555 }; 556 this.execute=function(){ 557 var match=_query, results=[]; 558 if(match === null){ 559 return self; 560 } 561 $.each(_data,function(){ 562 if(eval(match)){results.push(this);} 563 }); 564 _data=results; 565 return self; 566 }; 567 this.data=function(){ 568 return _data; 569 }; 570 this.select=function(f){ 571 self._performSort(); 572 if(!self._hasData()){ return[]; } 573 self.execute(); 574 if($.isFunction(f)){ 575 var results=[]; 576 $.each(_data,function(i,v){ 577 results.push(f(v)); 578 }); 579 return results; 580 } 581 return _data; 582 }; 583 this.hasMatch=function(){ 584 if(!self._hasData()) { return false; } 585 self.execute(); 586 return _data.length>0; 587 }; 588 this.andNot=function(f,v,x){ 589 _negate=!_negate; 590 return self.and(f,v,x); 591 }; 592 this.orNot=function(f,v,x){ 593 _negate=!_negate; 594 return self.or(f,v,x); 595 }; 596 this.not=function(f,v,x){ 597 return self.andNot(f,v,x); 598 }; 599 this.and=function(f,v,x){ 600 _queuedOperator=" && "; 601 if(f===undefined){ 602 return self; 603 } 604 return self._repeatCommand(f,v,x); 605 }; 606 this.or=function(f,v,x){ 607 _queuedOperator=" || "; 608 if(f===undefined) { return self; } 609 return self._repeatCommand(f,v,x); 610 }; 611 this.orBegin=function(){ 612 _orDepth++; 613 return self; 614 }; 615 this.orEnd=function(){ 616 if (_query !== null){ 617 _query+=")"; 618 } 619 return self; 620 }; 621 this.isNot=function(f){ 622 _negate=!_negate; 623 return self.is(f); 624 }; 625 this.is=function(f){ 626 self._append('this.'+f); 627 self._resetNegate(); 628 return self; 629 }; 630 this._compareValues=function(func,f,v,how,t){ 631 var fld; 632 if(_useProperties){ 633 fld='jQuery.jgrid.getAccessor(this,\''+f+'\')'; 634 }else{ 635 fld='this'; 636 } 637 if(v===undefined) { v = null; } 638 //var val=v===null?f:v, 639 var val =v, 640 swst = t.stype === undefined ? "text" : t.stype; 641 if(v !== null) { 642 switch(swst) { 643 case 'int': 644 case 'integer': 645 val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code 646 fld = 'parseInt('+fld+',10)'; 647 val = 'parseInt('+val+',10)'; 648 break; 649 case 'float': 650 case 'number': 651 case 'numeric': 652 val = String(val).replace(_stripNum, ''); 653 val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code 654 fld = 'parseFloat('+fld+')'; 655 val = 'parseFloat('+val+')'; 656 break; 657 case 'date': 658 case 'datetime':
659 val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime()); 660 fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()'; 661 break; 662 default : 663 fld=self._getStr(fld); 664 val=self._getStr('"'+self._toStr(val)+'"'); 665 } 666 } 667 self._append(fld+' '+how+' '+val); 668 self._setCommand(func,f); 669 self._resetNegate(); 670 return self; 671 }; 672 this.equals=function(f,v,t){ 673 return self._compareValues(self.equals,f,v,"==",t); 674 }; 675 this.notEquals=function(f,v,t){ 676 return self._compareValues(self.equals,f,v,"!==",t); 677 }; 678 this.isNull = function(f,v,t){ 679 return self._compareValues(self.equals,f,null,"===",t); 680 }; 681 this.greater=function(f,v,t){ 682 return self._compareValues(self.greater,f,v,">",t); 683 }; 684 this.less=function(f,v,t){ 685 return self._compareValues(self.less,f,v,"<",t); 686 }; 687 this.greaterOrEquals=function(f,v,t){ 688 return self._compareValues(self.greaterOrEquals,f,v,">=",t); 689 }; 690 this.lessOrEquals=function(f,v,t){ 691 return self._compareValues(self.lessOrEquals,f,v,"<=",t); 692 }; 693 this.startsWith=function(f,v){ 694 var val = (v==null) ? f: v, 695 length=_trim ? $.trim(val.toString()).length : val.toString().length; 696 if(_useProperties){ 697 self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"')); 698 }else{ 699 if (v!=null) { length=_trim?$.trim(v.toString()).length:v.toString().length; } 700 self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"')); 701 } 702 self._setCommand(self.startsWith,f); 703 self._resetNegate(); 704 return self; 705 }; 706 this.endsWith=function(f,v){ 707 var val = (v==null) ? f: v, 708 length=_trim ? $.trim(val.toString()).length:val.toString().length; 709 if(_useProperties){ 710 self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"'); 711 } else { 712 self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"'); 713 } 714 self._setCommand(self.endsWith,f);self._resetNegate(); 715 return self; 716 }; 717 this.contains=function(f,v){ 718 if(_useProperties){ 719 self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1'); 720 }else{ 721 self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1'); 722 } 723 self._setCommand(self.contains,f); 724 self._resetNegate(); 725 return self; 726 }; 727 this.groupBy=function(by,dir,type, datefmt){ 728 if(!self._hasData()){ 729 return null; 730 } 731 return self._getGroup(_data,by,dir,type, datefmt); 732 }; 733 this.orderBy=function(by,dir,stype, dfmt, sfunc){ 734 dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase()); 735 if(stype == null) { stype = "text"; } 736 if(dfmt == null) { dfmt = "Y-m-d"; } 737 if(sfunc == null) { sfunc = false; } 738 if(dir==="desc"||dir==="descending"){dir="d";} 739 if(dir==="asc"||dir==="ascending"){dir="a";} 740 _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc}); 741 return self; 742 }; 743 return self; 744 }; 745 return new QueryObject(source,null); 746 }, 747 getMethod: function (name) { 748 return this.getAccessor($.fn.jqGrid, name); 749 }, 750 extend : function(methods) { 751 $.extend($.fn.jqGrid,methods); 752 if (!this.no_legacy_api) { 753 $.fn.extend(methods); 754 } 755 } 756}); 757 758$.fn.jqGrid = function( pin ) { 759 if (typeof pin === 'string') { 760 var fn = $.jgrid.getMethod(pin); 761 if (!fn) { 762 throw ("jqGrid - No such method: " + pin); 763 } 764 var args = $.makeArray(arguments).slice(1); 765 return fn.apply(this,args); 766 } 767 return this.each( function() { 768 if(this.grid) {return;} 769 770 var p = $.extend(true,{ 771 url: "", 772 height: 150, 773 page: 1, 774 rowNum: 20, 775 rowTotal : null, 776 records: 0, 777 pager: "", 778 pgbuttons: true, 779 pginput: true, 780 colModel: [], 781 rowList: [], 782 colNames: [], 783 sortorder: "asc", 784 sortname: "", 785 datatype: "xml", 786 mtype: "GET", 787 altRows: false, 788 selarrrow: [], 789 savedRow: [], 790 shrinkToFit: true, 791 xmlReader: {}, 792 jsonReader: {}, 793 subGrid: false, 794 subGridModel :[], 795 reccount: 0, 796 lastpage: 0, 797 lastsort: 0, 798 selrow: null, 799 beforeSelectRow: null, 800 onSelectRow: null, 801 onSortCol: null,
802 ondblClickRow: null, 803 onRightClickRow: null, 804 onPaging: null, 805 onSelectAll: null, 806 onInitGrid : null, 807 loadComplete: null, 808 gridComplete: null, 809 loadError: null, 810 loadBeforeSend: null, 811 afterInsertRow: null, 812 beforeRequest: null, 813 beforeProcessing : null, 814 onHeaderClick: null, 815 viewrecords: false, 816 loadonce: false, 817 multiselect: false, 818 multikey: false, 819 editurl: null, 820 search: false, 821 caption: "", 822 hidegrid: true, 823 hiddengrid: false, 824 postData: {}, 825 userData: {}, 826 treeGrid : false, 827 treeGridModel : 'nested', 828 treeReader : {}, 829 treeANode : -1, 830 ExpandColumn: null, 831 tree_root_level : 0, 832 prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd", id:"id",oper:"oper",editoper:"edit",addoper:"add",deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"}, 833 forceFit : false, 834 gridstate : "visible", 835 cellEdit: false, 836 cellsubmit: "remote", 837 nv:0, 838 loadui: "enable", 839 toolbar: [false,""], 840 scroll: false, 841 multiboxonly : false, 842 deselectAfterSort : true, 843 scrollrows : false, 844 autowidth: false, 845 scrollOffset :18, 846 cellLayout: 5, 847 subGridWidth: 20, 848 multiselectWidth: 20, 849 gridview: false, 850 rownumWidth: 25, 851 rownumbers : false, 852 pagerpos: 'center', 853 recordpos: 'right', 854 footerrow : false, 855 userDataOnFooter : false, 856 hoverrows : true, 857 altclass : 'ui-priority-secondary',
858 viewsortcols : [false,'vertical',true], 859 resizeclass : '', 860 autoencode : false, 861 remapColumns : [], 862 ajaxGridOptions :{}, 863 direction : "ltr", 864 toppager: false, 865 headertitles: false, 866 scrollTimeout: 40, 867 data : [], 868 _index : {}, 869 grouping : false, 870 groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus', displayField: [], groupSummaryPos:[], formatDisplayField : [], _locgr : false}, 871 ignoreCase : false, 872 cmTemplate : {}, 873 idPrefix : "", 874 multiSort : false, 875 minColWidth : 33 876 }, $.jgrid.defaults, pin || {}); 877 var ts= this, grid={ 878 headers:[], 879 cols:[], 880 footers: [], 881 dragStart: function(i,x,y) { 882 var gridLeftPos = $(this.bDiv).offset().left; 883 this.resizing = { idx: i, startX: x.clientX, sOL : x.clientX - gridLeftPos }; 884 this.hDiv.style.cursor = "col-resize"; 885 this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id)); 886 this.curGbox.css({display:"block",left:x.clientX-gridLeftPos,top:y[1],height:y[2]}); 887 $(ts).triggerHandler("jqGridResizeStart", [x, i]); 888 if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); } 889 document.onselectstart=function(){return false;}; 890 }, 891 dragMove: function(x) { 892 if(this.resizing) { 893 var diff = x.clientX-this.resizing.startX, 894 h = this.headers[this.resizing.idx], 895 newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn; 896 if(newWidth > 33) { 897 this.curGbox.css({left:this.resizing.sOL+diff}); 898 if(p.forceFit===true ){ 899 hn = this.headers[this.resizing.idx+p.nv]; 900 nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff; 901 if(nWn > p.minColWidth ) { 902 h.newWidth = newWidth; 903 hn.newWidth = nWn; 904 } 905 } else { 906 this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff; 907 h.newWidth = newWidth; 908 } 909 } 910 } 911 }, 912 dragEnd: function() { 913 this.hDiv.style.cursor = "default"; 914 if(this.resizing) { 915 var idx = this.resizing.idx, 916 nw = this.headers[idx].newWidth || this.headers[idx].width; 917 nw = parseInt(nw,10); 918 this.resizing = false; 919 $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none"); 920 p.colModel[idx].width = nw; 921 this.headers[idx].width = nw; 922 this.headers[idx].el.style.width = nw + "px"; 923 this.cols[idx].style.width = nw+"px"; 924 if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";} 925 if(p.forceFit===true){ 926 nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width; 927 this.headers[idx+p.nv].width = nw; 928 this.headers[idx+p.nv].el.style.width = nw + "px"; 929 this.cols[idx+p.nv].style.width = nw+"px"; 930 if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";} 931 p.colModel[idx+p.nv].width = nw; 932 } else { 933 p.tblwidth = this.newWidth || p.tblwidth; 934 $('table:first',this.bDiv).css("width",p.tblwidth+"px"); 935 $('table:first',this.hDiv).css("width",p.tblwidth+"px"); 936 this.hDiv.scrollLeft = this.bDiv.scrollLeft; 937 if(p.footerrow) { 938 $('table:first',this.sDiv).css("width",p.tblwidth+"px"); 939 this.sDiv.scrollLeft = this.bDiv.scrollLeft; 940 } 941 } 942 $(ts).triggerHandler("jqGridResizeStop", [nw, idx]); 943 if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,nw,idx); } 944 } 945 this.curGbox = null; 946 document.onselectstart=function(){return true;}; 947 }, 948 populateVisible: function() { 949 if (grid.timer) { clearTimeout(grid.timer); } 950 grid.timer = null; 951 var dh = $(grid.bDiv).height(); 952 if (!dh) { return; } 953 var table = $("table:first", grid.bDiv); 954 var rows, rh; 955 if(table[0].rows.length) { 956 try { 957 rows = table[0].rows[1]; 958 rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight; 959 } catch (pv) { 960 rh = grid.prevRowHeight; 961 } 962 } 963 if (!rh) { return; } 964 grid.prevRowHeight = rh; 965 var rn = p.rowNum; 966 var scrollTop = grid.scrollTop = grid.bDiv.scrollTop; 967 var ttop = Math.round(table.position().top) - scrollTop; 968 var tbot = ttop + table.height(); 969 var div = rh * rn; 970 var page, npage, empty; 971 if ( tbot < dh && ttop <= 0 && 972 (p.lastpage===undefined||(parseInt((tbot + scrollTop + div - 1) / div,10) || 0) <= p.lastpage)) 973 { 974 npage = parseInt((dh - tbot + div - 1) / div,10) || 1; 975 if (tbot >= 0 || npage < 2 || p.scroll === true) { 976 page = ( Math.round((tbot + scrollTop) / div) || 0) + 1; 977 ttop = -1; 978 } else { 979 ttop = 1; 980 } 981 } 982 if (ttop > 0) { 983 page = ( parseInt(scrollTop / div,10) || 0 ) + 1; 984 npage = (parseInt((scrollTop + dh) / div,10) || 0) + 2 - page; 985 empty = true; 986 } 987 if (npage) { 988 if (p.lastpage && (page > p.lastpage || p.lastpage===1 || (page === p.page && page===p.lastpage)) ) { 989 return; 990 } 991 if (grid.hDiv.loading) { 992 grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout); 993 } else { 994 p.page = page; 995 if (empty) { 996 grid.selectionPreserver(table[0]); 997 grid.emptyRows.call(table[0], false, false); 998 } 999 grid.populate(npage); 1000 } 1001 } 1002 }, 1003 scrollGrid: function( e ) { 1004 if(p.scroll) { 1005 var scrollTop = grid.bDiv.scrollTop; 1006 if(grid.scrollTop === undefined) { grid.scrollTop = 0; } 1007 if (scrollTop !== grid.scrollTop) { 1008 grid.scrollTop = scrollTop; 1009 if (grid.timer) { clearTimeout(grid.timer); } 1010 grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout); 1011 } 1012 } 1013 grid.hDiv.scrollLeft = grid.bDiv.scrollLeft; 1014 if(p.footerrow) { 1015 grid.sDiv.scrollLeft = grid.bDiv.scrollLeft; 1016 } 1017 if( e ) { e.stopPropagation(); } 1018 }, 1019 selectionPreserver : function(ts) { 1020 var p = ts.p, 1021 sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null, 1022 left = ts.grid.bDiv.scrollLeft, 1023 restoreSelection = function() { 1024 var i; 1025 p.selrow = null; 1026 p.selarrrow = []; 1027 if(p.multiselect && sra && sra.length>0) { 1028 for(i=0;i<sra.length;i++){ 1029 if (sra[i] !== sr) { 1030 $(ts).jqGrid("setSelection",sra[i],false, null); 1031 } 1032 } 1033 } 1034 if (sr) {
1035 $(ts).jqGrid("setSelection",sr,false,null); 1036 } 1037 ts.grid.bDiv.scrollLeft = left; 1038 $(ts).unbind('.selectionPreserver', restoreSelection); 1039 }; 1040 $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection); 1041 } 1042 }; 1043 if(this.tagName.toUpperCase() !== 'TABLE' || this.id == null) { 1044 alert("Element is not a table or has no id!"); 1045 return; 1046 } 1047 if(document.documentMode !== undefined ) { // IE only 1048 if(document.documentMode <= 5) { 1049 alert("Grid can not be used in this ('quirks') mode!"); 1050 return; 1051 } 1052 } 1053 $(this).empty().attr("tabindex","0"); 1054 this.p = p ; 1055 this.p.useProp = !!$.fn.prop; 1056 var i, dir; 1057 if(this.p.colNames.length === 0) { 1058 for (i=0;i<this.p.colModel.length;i++){ 1059 this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name; 1060 } 1061 } 1062 if( this.p.colNames.length !== this.p.colModel.length ) { 1063 alert($.jgrid.errors.model); 1064 return; 1065 } 1066 var gv = $("<div class='ui-jqgrid-view'></div>"), 1067 isMSIE = $.jgrid.msie; 1068 ts.p.direction = $.trim(ts.p.direction.toLowerCase()); 1069 if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; } 1070 dir = ts.p.direction; 1071 1072 $(gv).insertBefore(this); 1073 $(this).removeClass("scroll").appendTo(gv); 1074 var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>"); 1075 $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv); 1076 $(gv).attr("id","gview_"+this.id).appendTo(eg); 1077 $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").insertBefore(gv); 1078 $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv); 1079 $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id}); 1080 var sortkeys = ["shiftKey","altKey","ctrlKey"], 1081 intNum = function(val,defval) { 1082 val = parseInt(val,10); 1083 if (isNaN(val)) { return defval || 0;} 1084 return val; 1085 }, 1086 formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){ 1087 var cm = ts.p.colModel[pos], 1088 ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[]; 1089 if(ral) { result += "text-align:"+ral+";"; } 1090 if(cm.hidden===true) { result += "display:none;"; } 1091 if(rowInd===0) { 1092 result += "width: "+grid.headers[pos].width+"px;"; 1093 } else if (cm.cellattr && $.isFunction(cm.cellattr)) 1094 { 1095 celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata); 1096 if(celp && typeof celp === "string") { 1097 celp = celp.replace(/style/i,'style').replace(/title/i,'title'); 1098 if(celp.indexOf('title') > -1) { cm.title=false;} 1099 if(celp.indexOf('class') > -1) { clas = undefined;} 1100 acp = celp.replace('-style','-sti').split(/style/); 1101 if(acp.length === 2 ) { 1102 acp[1] = $.trim(acp[1].replace('-sti','-style').replace("=","")); 1103 if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) { 1104 acp[1] = acp[1].substring(1); 1105 } 1106 result += acp[1].replace(/'/gi,'"'); 1107 } else { 1108 result += "\""; 1109 } 1110 } 1111 } 1112 if(!acp.length) { acp[0] = ""; result += "\"";} 1113 result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :""); 1114 result += " aria-describedby=\""+ts.p.id+"_"+nm+"\""; 1115 return result + acp[0]; 1116 }, 1117 cellVal = function (val) { 1118 return val == null || val === "" ? " " : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val)); 1119 }, 1120 formatter = function (rowId, cellval , colpos, rwdat, _act){ 1121 var cm = ts.p.colModel[colpos],v; 1122 if(cm.formatter !== undefined) { 1123 rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId; 1124 var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos }; 1125 if($.isFunction( cm.formatter ) ) { 1126 v = cm.formatter.call(ts,cellval,opts,rwdat,_act); 1127 } else if($.fmatter){ 1128 v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act); 1129 } else { 1130 v = cellVal(cellval); 1131 } 1132 } else { 1133 v = cellVal(cellval); 1134 } 1135 return v; 1136 }, 1137 addCell = function(rowId,cell,pos,irow, srvr, rdata) { 1138 var v,prp; 1139 v = formatter(rowId,cell,pos,srvr,'add'); 1140 prp = formatCol( pos,irow, v, srvr, rowId, rdata); 1141 return "<td role=\"gridcell\" "+prp+">"+v+"</td>"; 1142 }, 1143 addMulti = function(rowid,pos,irow,checked){ 1144 var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>", 1145 prp = formatCol( pos,irow,'',null, rowid, true); 1146 return "<td role=\"gridcell\" "+prp+">"+v+"</td>"; 1147 }, 1148 addRowNum = function (pos,irow,pG,rN) { 1149 var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow, 1150 prp = formatCol( pos,irow,v, null, irow, true); 1151 return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>"; 1152 }, 1153 reader = function (datatype) { 1154 var field, f=[], j=0, i; 1155 for(i =0; i<ts.p.colModel.length; i++){ 1156 field = ts.p.colModel[i]; 1157 if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') { 1158 f[j]= datatype === "local" ? 1159 field.name : 1160 ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name ); 1161 if(ts.p.keyName !== false && field.key===true ) { 1162 ts.p.keyName = f[j]; 1163 } 1164 j++; 1165 } 1166 } 1167 return f; 1168 }, 1169 orderedCols = function (offset) { 1170 var order = ts.p.remapColumns; 1171 if (!order || !order.length) { 1172 order = $.map(ts.p.colModel, function(v,i) { return i; }); 1173 } 1174 if (offset) { 1175 order = $.map(order, function(v) { return v<offset?null:v-offset; }); 1176 } 1177 return order; 1178 }, 1179 emptyRows = function (scroll, locdata) { 1180 var firstrow; 1181 if (this.p.deepempty) { 1182 $(this.rows).slice(1).remove(); 1183 } else { 1184 firstrow = this.rows.length > 0 ? this.rows[0] : null; 1185 $(this.firstChild).empty().append(firstrow); 1186 } 1187 if (scroll && this.p.scroll) { 1188 $(this.grid.bDiv.firstChild).css({height: "auto"}); 1189 $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"}); 1190 if (this.grid.bDiv.scrollTop !== 0) { 1191 this.grid.bDiv.scrollTop = 0; 1192 } 1193 } 1194 if(locdata === true && this.p.treeGrid) { 1195 this.p.data = []; this.p._index = {}; 1196 } 1197 }, 1198 refreshIndex = function() { 1199 var datalen = ts.p.data.length, idname, i, val; 1200 1201 if(ts.p.keyName === false || ts.p.loadonce === true) { 1202 idname = ts.p.localReader.id; 1203 } else { 1204 idname = ts.p.keyName; 1205 } 1206 for(i =0;i < datalen; i++) { 1207 val = $.jgrid.getAccessor(ts.p.data[i],idname); 1208 if (val === undefined) { val=String(i+1); } 1209 ts.p._index[val] = i; 1210 } 1211 }, 1212 constructTr = function(id, hide, altClass, rd, cur, selected) { 1213 var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '', 1214 classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''),
1215 rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]); 1216 if( typeof rowAttrObj !== "object" ) { 1217 rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :{}; 1218 } 1219 if(!$.isEmptyObject( rowAttrObj )) { 1220 if (rowAttrObj.hasOwnProperty("id")) { 1221 id = rowAttrObj.id; 1222 delete rowAttrObj.id; 1223 } 1224 if (rowAttrObj.hasOwnProperty("tabindex")) { 1225 tabindex = rowAttrObj.tabindex; 1226 delete rowAttrObj.tabindex; 1227 } 1228 if (rowAttrObj.hasOwnProperty("style")) { 1229 style += rowAttrObj.style; 1230 delete rowAttrObj.style; 1231 } 1232 if (rowAttrObj.hasOwnProperty("class")) { 1233 classes += ' ' + rowAttrObj['class']; 1234 delete rowAttrObj['class']; 1235 } 1236 // dot't allow to change role attribute 1237 try { delete rowAttrObj.role; } catch(ra){} 1238 for (attrName in rowAttrObj) { 1239 if (rowAttrObj.hasOwnProperty(attrName)) { 1240 restAttr += ' ' + attrName + '=' + rowAttrObj[attrName]; 1241 } 1242 } 1243 } 1244 return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' + 1245 (style === '' ? '' : ' style="' + style + '"') + restAttr + '>'; 1246 }, 1247 addXmlData = function (xml,t, rcnt, more, adjust) { 1248 var startReq = new Date(), 1249 locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring", 1250 xmlid = "_id_", xmlRd = ts.p.xmlReader, 1251 frd = ts.p.datatype === "local" ? "local" : "xml"; 1252 if(locdata) { 1253 ts.p.data = []; 1254 ts.p._index = {}; 1255 ts.p.localReader.id = xmlid; 1256 } 1257 ts.p.reccount = 0; 1258 if($.isXMLDoc(xml)) { 1259 if(ts.p.treeANode===-1 && !ts.p.scroll) { 1260 emptyRows.call(ts, false, true); 1261 rcnt=1; 1262 } else { rcnt = rcnt > 1 ? rcnt :1; } 1263 } else { return; } 1264 var self= $(ts), i,fpos,ir=0,v,gi=ts.p.multiselect===true?1:0,si=0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,idn, getId,f=[],F,rd ={}, xmlr,rid, rowData=[], cn=(ts.p.altRows === true) ? ts.p.altclass:"",cn1; 1265 if(ts.p.subGrid===true) { 1266 si = 1; 1267 addSubGridCell = $.jgrid.getMethod("addSubGridCell"); 1268 } 1269 if(!xmlRd.repeatitems) {f = reader(frd);} 1270 if( ts.p.keyName===false) { 1271 idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id; 1272 } else { 1273 idn = ts.p.keyName; 1274 } 1275 if( String(idn).indexOf("[") === -1 ) { 1276 if (f.length) { 1277 getId = function( trow, k) {return $(idn,trow).text() || k;}; 1278 } else { 1279 getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;}; 1280 } 1281 } 1282 else { 1283 getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;}; 1284 } 1285 ts.p.userData = {}; 1286 ts.p.page = intNum($.jgrid.getXmlData(xml, xmlRd.page), ts.p.page); 1287 ts.p.lastpage = intNum($.jgrid.getXmlData(xml, xmlRd.total), 1); 1288 ts.p.records = intNum($.jgrid.getXmlData(xml, xmlRd.records)); 1289 if($.isFunction(xmlRd.userdata)) { 1290 ts.p.userData = xmlRd.userdata.call(ts, xml) || {}; 1291 } else { 1292 $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();}); 1293 } 1294 var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true); 1295 gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true); 1296 if (!gxml) { gxml = []; } 1297 var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr; 1298 if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; } 1299 if(gxml && gl){ 1300 if (adjust) { rn *= adjust+1; } 1301 var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare; 1302 if(ts.p.grouping) { 1303 hiderow = ts.p.groupingView.groupCollapse === true; 1304 groupingPrepare = $.jgrid.getMethod("groupingPrepare"); 1305 } 1306 while (j<gl) { 1307 xmlr = gxml[j]; 1308 rid = getId(xmlr,br+j); 1309 rid = ts.p.idPrefix + rid; 1310 altr = rcnt === 0 ? 0 : rcnt+1; 1311 cn1 = (altr+j)%2 === 1 ? cn : ''; 1312 var iStartTrTag = rowData.length; 1313 rowData.push(""); 1314 if( ni ) { 1315 rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) ); 1316 } 1317 if( gi ) { 1318 rowData.push( addMulti(rid,ni,j, false) ); 1319 } 1320 if( si ) { 1321 rowData.push( addSubGridCell.call(self,gi+ni,j+rcnt) ); 1322 } 1323 if(xmlRd.repeatitems){ 1324 if (!F) { F=orderedCols(gi+si+ni); } 1325 var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true); 1326 $.each(F, function (k) { 1327 var cell = cells[this]; 1328 if (!cell) { return false; } 1329 v = cell.textContent || cell.text; 1330 rd[ts.p.colModel[k+gi+si+ni].name] = v; 1331 rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) ); 1332 }); 1333 } else { 1334 for(i = 0; i < f.length;i++) { 1335 v = $.jgrid.getXmlData( xmlr, f[i]); 1336 rd[ts.p.colModel[i+gi+si+ni].name] = v; 1337 rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) ); 1338 } 1339 } 1340 rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false); 1341 rowData.push("</tr>"); 1342 if(ts.p.grouping) { 1343 grpdata.push( rowData ); 1344 if(!ts.p.groupingView._locgr) { 1345 groupingPrepare.call(self, rd, j ); 1346 } 1347 rowData = []; 1348 } 1349 if(locdata || ts.p.treeGrid === true) {
1350 rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid); 1351 ts.p.data.push(rd); 1352 ts.p._index[rd[xmlid]] = ts.p.data.length-1; 1353 } 1354 if(ts.p.gridview === false ) { 1355 $("tbody:first",t).append(rowData.join('')); 1356 self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]); 1357 if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);} 1358 rowData=[]; 1359 } 1360 rd={}; 1361 ir++; 1362 j++; 1363 if(ir===rn) {break;} 1364 } 1365 } 1366 if(ts.p.gridview === true) { 1367 fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0; 1368 if(ts.p.grouping) { 1369 if(!locdata) { 1370 self.jqGrid('groupingRender',grpdata,ts.p.colModel.length, ts.p.page, rn); 1371 grpdata = null; 1372 } 1373 } else if(ts.p.treeGrid === true && fpos > 0) { 1374 $(ts.rows[fpos]).after(rowData.join('')); 1375 } else { 1376 $("tbody:first",t).append(rowData.join('')); 1377 } 1378 } 1379 if(ts.p.subGrid === true ) { 1380 try {self.jqGrid("addSubGrid",gi+ni);} catch (_){} 1381 } 1382 ts.p.totaltime = new Date() - startReq; 1383 if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} } 1384 rowData =null; 1385 if( ts.p.treeGrid === true) { 1386 try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {} 1387 } 1388 if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;} 1389 ts.p.reccount=ir; 1390 ts.p.treeANode = -1; 1391 if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); } 1392 if(locdata) { 1393 ts.p.records = gl; 1394 ts.p.lastpage = Math.ceil(gl/ rn); 1395 } 1396 if (!more) { ts.updatepager(false,true); } 1397 if(locdata) { 1398 while (ir<gl) { 1399 xmlr = gxml[ir]; 1400 rid = getId(xmlr,ir+br); 1401 rid = ts.p.idPrefix + rid; 1402 if(xmlRd.repeatitems){ 1403 if (!F) { F=orderedCols(gi+si+ni); } 1404 var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true); 1405 $.each(F, function (k) { 1406 var cell = cells2[this]; 1407 if (!cell) { return false; } 1408 v = cell.textContent || cell.text; 1409 rd[ts.p.colModel[k+gi+si+ni].name] = v; 1410 }); 1411 } else { 1412 for(i = 0; i < f.length;i++) { 1413 v = $.jgrid.getXmlData( xmlr, f[i]); 1414 rd[ts.p.colModel[i+gi+si+ni].name] = v; 1415 } 1416 } 1417 rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid); 1418 if(ts.p.grouping) { 1419 groupingPrepare.call(self, rd, ir ); 1420 } 1421 ts.p.data.push(rd); 1422 ts.p._index[rd[xmlid]] = ts.p.data.length-1; 1423 rd = {}; 1424 ir++; 1425 } 1426 if(ts.p.grouping) { 1427 ts.p.groupingView._locgr = true; 1428 self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn); 1429 grpdata = null; 1430 } 1431 } 1432 }, 1433 addJSONData = function(data,t, rcnt, more, adjust) { 1434 var startReq = new Date(); 1435 if(data) { 1436 if(ts.p.treeANode === -1 && !ts.p.scroll) { 1437 emptyRows.call(ts, false, true); 1438 rcnt=1; 1439 } else { rcnt = rcnt > 1 ? rcnt :1; } 1440 } else { return; } 1441 1442 var dReader, locid = "_id_", frd, 1443 locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "jsonstring"; 1444 if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;} 1445 ts.p.reccount = 0; 1446 if(ts.p.datatype === "local") { 1447 dReader = ts.p.localReader; 1448 frd= 'local'; 1449 } else { 1450 dReader = ts.p.jsonReader; 1451 frd='json'; 1452 } 1453 var self = $(ts), ir=0,v,i,j,f=[],cur,gi=ts.p.multiselect?1:0,si=ts.p.subGrid===true?1:0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,arrayReader=orderedCols(gi+si+ni),objectReader=reader(frd),rowReader,len,drows,idn,rd={}, fpos, idr,rowData=[],cn=(ts.p.altRows === true) ? ts.p.altclass:"",cn1; 1454 ts.p.page = intNum($.jgrid.getAccessor(data,dReader.page), ts.p.page); 1455 ts.p.lastpage = intNum($.jgrid.getAccessor(data,dReader.total), 1); 1456 ts.p.records = intNum($.jgrid.getAccessor(data,dReader.records)); 1457 ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {}; 1458 if(si) { 1459 addSubGridCell = $.jgrid.getMethod("addSubGridCell"); 1460 } 1461 if( ts.p.keyName===false ) { 1462 idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id; 1463 } else { 1464 idn = ts.p.keyName; 1465 } 1466 drows = $.jgrid.getAccessor(data,dReader.root); 1467 if (drows == null && $.isArray(data)) { drows = data; }
1468 if (!drows) { drows = []; } 1469 len = drows.length; i=0; 1470 if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; } 1471 var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr, selected=false, selr; 1472 if (adjust) { rn *= adjust+1; } 1473 if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) { 1474 selected = true; 1475 } 1476 var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare; 1477 if(ts.p.grouping) { 1478 hiderow = ts.p.groupingView.groupCollapse === true; 1479 groupingPrepare = $.jgrid.getMethod("groupingPrepare"); 1480 } 1481 while (i<len) { 1482 cur = drows[i]; 1483 idr = $.jgrid.getAccessor(cur,idn); 1484 if(idr === undefined) { 1485 if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) { 1486 // reread id by name 1487 idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name); 1488 } 1489 if(idr === undefined) { 1490 idr = br+i; 1491 if(f.length===0){ 1492 if(dReader.cell){ 1493 var ccur = $.jgrid.getAccessor(cur,dReader.cell) || cur; 1494 idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr; 1495 ccur=null; 1496 } 1497 } 1498 } 1499 } 1500 idr = ts.p.idPrefix + idr; 1501 altr = rcnt === 1 ? 0 : rcnt; 1502 cn1 = (altr+i)%2 === 1 ? cn : ''; 1503 if( selected) { 1504 if( ts.p.multiselect) { 1505 selr = ($.inArray(idr, ts.p.selarrrow) !== -1); 1506 } else { 1507 selr = (idr === ts.p.selrow); 1508 } 1509 } 1510 var iStartTrTag = rowData.length; 1511 rowData.push(""); 1512 if( ni ) { 1513 rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) ); 1514 } 1515 if( gi ){ 1516 rowData.push( addMulti(idr,ni,i,selr) ); 1517 } 1518 if( si ) { 1519 rowData.push( addSubGridCell.call(self,gi+ni,i+rcnt) ); 1520 } 1521 rowReader=objectReader; 1522 if (dReader.repeatitems) { 1523 if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;} 1524 if ($.isArray(cur)) { rowReader=arrayReader; } 1525 } 1526 for (j=0;j<rowReader.length;j++) { 1527 v = $.jgrid.getAccessor(cur,rowReader[j]); 1528 rd[ts.p.colModel[j+gi+si+ni].name] = v; 1529 rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) ); 1530 } 1531 rowData[iStartTrTag] = constructTr(idr, hiderow, cn1, rd, cur, selr); 1532 rowData.push( "</tr>" ); 1533 if(ts.p.grouping) { 1534 grpdata.push( rowData ); 1535 if(!ts.p.groupingView._locgr) { 1536 groupingPrepare.call(self, rd, i); 1537 } 1538 rowData = []; 1539 } 1540 if(locdata || ts.p.treeGrid===true) { 1541 rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr); 1542 ts.p.data.push(rd); 1543 ts.p._index[rd[locid]] = ts.p.data.length-1; 1544 } 1545 if(ts.p.gridview === false ) { 1546 $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join('')); 1547 self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]); 1548 if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);} 1549 rowData=[];//ari=0; 1550 } 1551 rd={}; 1552 ir++; 1553 i++; 1554 if(ir===rn) { break; } 1555 } 1556 if(ts.p.gridview === true ) { 1557 fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0; 1558 if(ts.p.grouping) { 1559 if(!locdata) { 1560 self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn); 1561 grpdata = null; 1562 } 1563 } else if(ts.p.treeGrid === true && fpos > 0) { 1564 $(ts.rows[fpos]).after(rowData.join('')); 1565 } else { 1566 $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join('')); 1567 } 1568 } 1569 if(ts.p.subGrid === true ) { 1570 try { self.jqGrid("addSubGrid",gi+ni);} catch (_){} 1571 } 1572 ts.p.totaltime = new Date() - startReq; 1573 if(ir>0) { 1574 if(ts.p.records===0) { ts.p.records=len; } 1575 } 1576 rowData = null; 1577 if( ts.p.treeGrid === true) { 1578 try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {} 1579 } 1580 if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;} 1581 ts.p.reccount=ir; 1582 ts.p.treeANode = -1; 1583 if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); } 1584 if(locdata) { 1585 ts.p.records = len; 1586 ts.p.lastpage = Math.ceil(len/ rn); 1587 } 1588 if (!more) { ts.updatepager(false,true); } 1589 if(locdata) { 1590 while (ir<len && drows[ir]) { 1591 cur = drows[ir]; 1592 idr = $.jgrid.getAccessor(cur,idn); 1593 if(idr === undefined) { 1594 if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) { 1595 // reread id by name 1596 idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name); 1597 } 1598 if(idr === undefined) { 1599 idr = br+ir; 1600 if(f.length===0){ 1601 if(dReader.cell){ 1602 var ccur2 = $.jgrid.getAccessor(cur,dReader.cell) || cur; 1603 idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr; 1604 ccur2=null; 1605 } 1606 } 1607 } 1608 } 1609 if(cur) { 1610 idr = ts.p.idPrefix + idr; 1611 rowReader=objectReader; 1612 if (dReader.repeatitems) { 1613 if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;} 1614 if ($.isArray(cur)) { rowReader=arrayReader; } 1615 } 1616 1617 for (j=0;j<rowReader.length;j++) { 1618 rd[ts.p.colModel[j+gi+si+ni].name] = $.jgrid.getAccessor(cur,rowReader[j]); 1619 }
1620 rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr); 1621 if(ts.p.grouping) { 1622 groupingPrepare.call(self, rd, ir ); 1623 } 1624 ts.p.data.push(rd); 1625 ts.p._index[rd[locid]] = ts.p.data.length-1; 1626 rd = {}; 1627 } 1628 ir++; 1629 } 1630 if(ts.p.grouping) { 1631 ts.p.groupingView._locgr = true; 1632 self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn); 1633 grpdata = null; 1634 } 1635 } 1636 }, 1637 addLocalData = function() { 1638 var st = ts.p.multiSort ? [] : "", sto=[], fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat; 1639 if(!$.isArray(ts.p.data)) { 1640 return; 1641 } 1642 var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin; 1643 $.each(ts.p.colModel,function(){ 1644 sorttype = this.sorttype || "text"; 1645 if(sorttype === "date" || sorttype === "datetime") { 1646 if(this.formatter && typeof this.formatter === 'string' && this.formatter === 'date') { 1647 if(this.formatoptions && this.formatoptions.srcformat) { 1648 srcformat = this.formatoptions.srcformat; 1649 } else { 1650 srcformat = $.jgrid.formatter.date.srcformat; 1651 } 1652 if(this.formatoptions && this.formatoptions.newformat) { 1653 newformat = this.formatoptions.newformat; 1654 } else { 1655 newformat = $.jgrid.formatter.date.newformat; 1656 } 1657 } else { 1658 srcformat = newformat = this.datefmt || "Y-m-d"; 1659 } 1660 cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat, "sfunc": this.sortfunc || null}; 1661 } else { 1662 cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":'', "sfunc": this.sortfunc || null}; 1663 } 1664 if(ts.p.grouping ) { 1665 for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) { 1666 if( this.name === grpview.groupField[gin]) { 1667 var grindex = this.name; 1668 if (this.index) { 1669 grindex = this.index; 1670 } 1671 grtypes[gin] = cmtypes[grindex]; 1672 grindexes[gin]= grindex; 1673 } 1674 } 1675 } 1676 if(ts.p.multiSort) { 1677 if(this.lso) { 1678 st.push(this.name); 1679 var tmplso= this.lso.split("-"); 1680 sto.push( tmplso[tmplso.length-1] ); 1681 } 1682 } else { 1683 if(!fndsort && (this.index === ts.p.sortname || this.name === ts.p.sortname)){ 1684 st = this.name; // ??? 1685 fndsort = true; 1686 } 1687 } 1688 }); 1689 if(ts.p.treeGrid) { 1690 $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype || 'text', cmtypes[st].srcfmt || ''); 1691 return; 1692 } 1693 var compareFnMap = { 1694 'eq':function(queryObj) {return queryObj.equals;}, 1695 'ne':function(queryObj) {return queryObj.notEquals;}, 1696 'lt':function(queryObj) {return queryObj.less;}, 1697 'le':function(queryObj) {return queryObj.lessOrEquals;}, 1698 'gt':function(queryObj) {return queryObj.greater;}, 1699 'ge':function(queryObj) {return queryObj.greaterOrEquals;}, 1700 'cn':function(queryObj) {return queryObj.contains;}, 1701 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;}, 1702 'bw':function(queryObj) {return queryObj.startsWith;}, 1703 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;}, 1704 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;}, 1705 'ew':function(queryObj) {return queryObj.endsWith;}, 1706 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;}, 1707 'in':function(queryObj) {return queryObj.equals;}, 1708 'nu':function(queryObj) {return queryObj.isNull;}, 1709 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;} 1710 1711 }, 1712 query = $.jgrid.from(ts.p.data); 1713 if (ts.p.ignoreCase) { query = query.ignoreCase(); } 1714 function tojLinq ( group ) { 1715 var s = 0, index, gor, ror, opr, rule; 1716 if (group.groups != null) { 1717 gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR"; 1718 if (gor) { 1719 query.orBegin(); 1720 } 1721 for (index = 0; index < group.groups.length; index++) { 1722 if (s > 0 && gor) { 1723 query.or(); 1724 } 1725 try { 1726 tojLinq(group.groups[index]); 1727 } catch (e) {alert(e);} 1728 s++; 1729 } 1730 if (gor) { 1731 query.orEnd(); 1732 } 1733 } 1734 if (group.rules != null) { 1735 //if(s>0) { 1736 // var result = query.select(); 1737 // query = $.jgrid.from( result); 1738 // if (ts.p.ignoreCase) { query = query.ignoreCase(); } 1739 //} 1740 try{ 1741 ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR"; 1742 if (ror) { 1743 query.orBegin(); 1744 } 1745 for (index = 0; index < group.rules.length; index++) { 1746 rule = group.rules[index]; 1747 opr = group.groupOp.toString().toUpperCase(); 1748 if (compareFnMap[rule.op] && rule.field ) { 1749 if(s > 0 && opr && opr === "OR") { 1750 query = query.or(); 1751 } 1752 query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]); 1753 } 1754 s++; 1755 } 1756 if (ror) { 1757 query.orEnd(); 1758 } 1759 } catch (g) {alert(g);} 1760 } 1761 } 1762 1763 if (ts.p.search === true) { 1764 var srules = ts.p.postData.filters; 1765 if(srules) { 1766 if(typeof srules === "string") { srules = $.jgrid.parse(srules);} 1767 tojLinq( srules ); 1768 } else { 1769 try { 1770 query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]); 1771 } catch (se){} 1772 } 1773 } 1774 if(ts.p.grouping) { 1775 for(gin=0; gin<lengrp;gin++) { 1776 query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt); 1777 } 1778 } 1779 if(ts.p.multiSort) { 1780 $.each(st,function(i){ 1781 query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc); 1782 }); 1783 } else { 1784 if (st && ts.p.sortorder && fndsort) { 1785 if(ts.p.sortorder.toUpperCase() === "DESC") { 1786 query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc); 1787 } else { 1788 query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc); 1789 } 1790 } 1791 } 1792 var queryResults = query.select(), 1793 recordsperpage = parseInt(ts.p.rowNum,10), 1794 total = queryResults.length, 1795 page = parseInt(ts.p.page,10), 1796 totalpages = Math.ceil(total / recordsperpage), 1797 retresult = {}; 1798 if((ts.p.search || ts.p.resetsearch) && ts.p.grouping && ts.p.groupingView._locgr) { 1799 ts.p.groupingView.groups =[]; 1800 var j, grPrepare = $.jgrid.getMethod("groupingPrepare"), key, udc; 1801 if(ts.p.footerrow && ts.p.userDataOnFooter) { 1802 for (key in ts.p.userData) { 1803 if(ts.p.userData.hasOwnProperty(key)) { 1804 ts.p.userData[key] = 0; 1805 } 1806 } 1807 udc = true; 1808 }
1809 for(j=0; j<total; j++) { 1810 if(udc) { 1811 for(key in ts.p.userData){ 1812 ts.p.userData[key] += parseFloat(queryResults[j][key] || 0); 1813 } 1814 } 1815 grPrepare.call($(ts),queryResults[j],j, recordsperpage ); 1816 } 1817 } 1818 queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage ); 1819 query = null; 1820 cmtypes = null; 1821 retresult[ts.p.localReader.total] = totalpages; 1822 retresult[ts.p.localReader.page] = page; 1823 retresult[ts.p.localReader.records] = total; 1824 retresult[ts.p.localReader.root] = queryResults; 1825 retresult[ts.p.localReader.userdata] = ts.p.userData; 1826 queryResults = null; 1827 return retresult; 1828 }, 1829 updatepager = function(rn, dnd) { 1830 var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg, 1831 tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "", 1832 tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : ""; 1833 base = parseInt(ts.p.page,10)-1; 1834 if(base < 0) { base = 0; } 1835 base = base*parseInt(ts.p.rowNum,10); 1836 to = base + ts.p.reccount; 1837 if (ts.p.scroll) { 1838 var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv); 1839 base = to - rows.length; 1840 ts.p.reccount = rows.length; 1841 var rh = rows.outerHeight() || ts.grid.prevRowHeight; 1842 if (rh) { 1843 var top = base * rh; 1844 var height = parseInt(ts.p.records,10) * rh; 1845 $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"}); 1846 if (ts.grid.bDiv.scrollTop == 0 && ts.p.page > 1) { 1847 ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh; 1848 } 1849 } 1850 ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft; 1851 } 1852 pgboxes = ts.p.pager || ""; 1853 pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : ""; 1854 if(pgboxes) { 1855 fmt = $.jgrid.formatter.integer || {}; 1856 cp = intNum(ts.p.page); 1857 last = intNum(ts.p.lastpage); 1858 $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false); 1859 if(ts.p.pginput===true) { 1860 $('.ui-pg-input',pgboxes).val(ts.p.page); 1861 sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg; 1862 $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage); 1863 1864 } 1865 if (ts.p.viewrecords){ 1866 if(ts.p.reccount === 0) { 1867 $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords); 1868 } else { 1869 from = base+1; 1870 tot=ts.p.records; 1871 if($.fmatter) { 1872 from = $.fmatter.util.NumberFormat(from,fmt); 1873 to = $.fmatter.util.NumberFormat(to,fmt); 1874 tot = $.fmatter.util.NumberFormat(tot,fmt); 1875 } 1876 $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot)); 1877 } 1878 } 1879 if(ts.p.pgbuttons===true) { 1880 if(cp<=0) {cp = last = 0;} 1881 if(cp===1 || cp === 0) { 1882 $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover'); 1883 if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); } 1884 } else { 1885 $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled'); 1886 if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); } 1887 } 1888 if(cp===last || cp === 0) { 1889 $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover'); 1890 if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); } 1891 } else { 1892 $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled'); 1893 if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); } 1894 } 1895 } 1896 } 1897 if(rn===true && ts.p.rownumbers === true) { 1898 $(">td.jqgrid-rownum",ts.rows).each(function(i){ 1899 $(this).html(base+1+i); 1900 }); 1901 } 1902 if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');} 1903 $(ts).triggerHandler("jqGridGridComplete"); 1904 if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);} 1905 $(ts).triggerHandler("jqGridAfterGridComplete"); 1906 }, 1907 beginReq = function() { 1908 ts.grid.hDiv.loading = true; 1909 if(ts.p.hiddengrid) { return;} 1910 switch(ts.p.loadui) { 1911 case "disable": 1912 break; 1913 case "enable": 1914 $("#load_"+$.jgrid.jqID(ts.p.id)).show(); 1915 break; 1916 case "block": 1917 $("#lui_"+$.jgrid.jqID(ts.p.id)).show(); 1918 $("#load_"+$.jgrid.jqID(ts.p.id)).show(); 1919 break; 1920 } 1921 }, 1922 endReq = function() { 1923 ts.grid.hDiv.loading = false;
1924 switch(ts.p.loadui) { 1925 case "disable": 1926 break; 1927 case "enable": 1928 $("#load_"+$.jgrid.jqID(ts.p.id)).hide(); 1929 break; 1930 case "block": 1931 $("#lui_"+$.jgrid.jqID(ts.p.id)).hide(); 1932 $("#load_"+$.jgrid.jqID(ts.p.id)).hide(); 1933 break; 1934 } 1935 }, 1936 populate = function (npage) { 1937 if(!ts.grid.hDiv.loading) { 1938 var pvis = ts.p.scroll && npage === false, 1939 prm = {}, dt, dstr, pN=ts.p.prmNames; 1940 if(ts.p.page <=0) { ts.p.page = Math.min(1,ts.p.lastpage); } 1941 if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();} 1942 if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;} 1943 if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;} 1944 if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; } 1945 var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null; 1946 var adjust = 0; 1947 npage = npage || 1; 1948 if (npage > 1) { 1949 if(pN.npage !== null) { 1950 prm[pN.npage] = npage; 1951 adjust = npage - 1; 1952 npage = 1; 1953 } else { 1954 lc = function(req) { 1955 ts.p.page++; 1956 ts.grid.hDiv.loading = false; 1957 if (lcf) { 1958 ts.p.loadComplete.call(ts,req); 1959 } 1960 populate(npage-1); 1961 }; 1962 } 1963 } else if (pN.npage !== null) { 1964 delete ts.p.postData[pN.npage]; 1965 } 1966 if(ts.p.grouping) { 1967 $(ts).jqGrid('groupingSetup'); 1968 var grp = ts.p.groupingView, gi, gs=""; 1969 for(gi=0;gi<grp.groupField.length;gi++) { 1970 var index = grp.groupField[gi]; 1971 $.each(ts.p.colModel, function(cmIndex, cmValue) { 1972 if (cmValue.name === index && cmValue.index){ 1973 index = cmValue.index; 1974 } 1975 } ); 1976 gs += index +" "+grp.groupOrder[gi]+", "; 1977 } 1978 prm[pN.sort] = gs + prm[pN.sort]; 1979 } 1980 $.extend(ts.p.postData,prm); 1981 var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1; 1982 var bfr = $(ts).triggerHandler("jqGridBeforeRequest"); 1983 if (bfr === false || bfr === 'stop') { return; } 1984 if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id, rcnt, npage, adjust); return;} 1985 if ($.isFunction(ts.p.beforeRequest)) { 1986 bfr = ts.p.beforeRequest.call(ts); 1987 if(bfr === undefined) { bfr = true; } 1988 if ( bfr === false ) { return; } 1989 } 1990 dt = ts.p.datatype.toLowerCase(); 1991 switch(dt) 1992 { 1993 case "json": 1994 case "jsonp": 1995 case "xml": 1996 case "script": 1997 $.ajax($.extend({ 1998 url:ts.p.url, 1999 type:ts.p.mtype, 2000 dataType: dt , 2001 data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData, 2002 success:function(data,st, xhr) { 2003 if ($.isFunction(ts.p.beforeProcessing)) { 2004 if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) { 2005 endReq(); 2006 return; 2007 } 2008 } 2009 if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); } 2010 else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); } 2011 $(ts).triggerHandler("jqGridLoadComplete", [data]); 2012 if(lc) { lc.call(ts,data); } 2013 $(ts).triggerHandler("jqGridAfterLoadComplete", [data]); 2014 if (pvis) { ts.grid.populateVisible(); } 2015 if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";} 2016 data=null; 2017 if (npage === 1) { endReq(); } 2018 }, 2019 error:function(xhr,st,err){ 2020 if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); } 2021 if (npage === 1) { endReq(); } 2022 xhr=null; 2023 }, 2024 beforeSend: function(xhr, settings ){ 2025 var gotoreq = true; 2026 if($.isFunction(ts.p.loadBeforeSend)) { 2027 gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings); 2028 } 2029 if(gotoreq === undefined) { gotoreq = true; } 2030 if(gotoreq === false) { 2031 return false; 2032 } 2033 beginReq(); 2034 } 2035 },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions)); 2036 break; 2037 case "xmlstring": 2038 beginReq(); 2039 dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr); 2040 addXmlData(dstr,ts.grid.bDiv); 2041 $(ts).triggerHandler("jqGridLoadComplete", [dstr]); 2042 if(lcf) {ts.p.loadComplete.call(ts,dstr);} 2043 $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]); 2044 ts.p.datatype = "local"; 2045 ts.p.datastr = null; 2046 endReq(); 2047 break; 2048 case "jsonstring": 2049 beginReq(); 2050 if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); } 2051 else { dstr = ts.p.datastr; } 2052 addJSONData(dstr,ts.grid.bDiv); 2053 $(ts).triggerHandler("jqGridLoadComplete", [dstr]); 2054 if(lcf) {ts.p.loadComplete.call(ts,dstr);} 2055 $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]); 2056 ts.p.datatype = "local"; 2057 ts.p.datastr = null; 2058 endReq(); 2059 break; 2060 case "local": 2061 case "clientside": 2062 beginReq(); 2063 ts.p.datatype = "local"; 2064 var req = addLocalData(); 2065 addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust); 2066 $(ts).triggerHandler("jqGridLoadComplete", [req]); 2067 if(lc) { lc.call(ts,req); } 2068 $(ts).triggerHandler("jqGridAfterLoadComplete", [req]); 2069 if (pvis) { ts.grid.populateVisible(); } 2070 endReq(); 2071 break; 2072 } 2073 } 2074 }, 2075 setHeadCheckBox = function ( checked ) {
2076 $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked); 2077 var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : ""; 2078 if(fid) { 2079 $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked); 2080 } 2081 }, 2082 setPager = function (pgid, tp){ 2083 // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid); 2084 var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>", 2085 pginp = "", 2086 pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>", 2087 str="", pgcnt, lft, cent, rgt, twd, tdw, i, 2088 clearVals = function(onpaging){ 2089 var ret; 2090 if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); } 2091 if(ret==='stop') {return false;} 2092 ts.p.selrow = null; 2093 if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );} 2094 ts.p.savedRow = []; 2095 return true; 2096 }; 2097 pgid = pgid.substr(1); 2098 tp += "_" + pgid; 2099 pgcnt = "pg_"+pgid; 2100 lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right"; 2101 $("#"+$.jgrid.jqID(pgid) ) 2102 .append("<div id='"+pgcnt+"' class='ui-pager-control' role='group'><table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table' style='width:100%;table-layout:fixed;height:100%;' role='row'><tbody><tr><td id='"+lft+"' align='left'></td><td id='"+cent+"' align='center' style='white-space:pre;'></td><td id='"+rgt+"' align='right'></td></tr></tbody></table></div>") 2103 .attr("dir","ltr"); //explicit setting 2104 if(ts.p.rowList.length >0){ 2105 str = "<td dir='"+dir+"'>"; 2106 str +="<select class='ui-pg-selbox' role='listbox'>"; 2107 var strnm; 2108 for(i=0;i<ts.p.rowList.length;i++){ 2109 strnm = ts.p.rowList[i].toString().split(":"); 2110 if(strnm.length === 1) { 2111 strnm[1] = strnm[0]; 2112 } 2113 str +="<option role=\"option\" value=\""+strnm[0]+"\""+(( intNum(ts.p.rowNum,0) === intNum(strnm[0],0))?" selected=\"selected\"":"")+">"+strnm[1]+"</option>"; 2114 } 2115 str +="</select></td>"; 2116 } 2117 if(dir==="rtl") { pgl += str; } 2118 if(ts.p.pginput===true) { pginp= "<td dir='"+dir+"'>"+$.jgrid.format(ts.p.pgtext || "","<input class='ui-pg-input' type='text' size='2' maxlength='7' value='0' role='textbox'/>","<span id='sp_1_"+$.jgrid.jqID(pgid)+"'></span>")+"</td>";} 2119 if(ts.p.pgbuttons===true) { 2120 var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir==="rtl") { po.reverse(); } 2121 pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-first'></span></td>"; 2122 pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-prev'></span></td>"; 2123 pgl += pginp !== "" ? sep+pginp+sep:""; 2124 pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-next'></span></td>"; 2125 pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-end'></span></td>"; 2126 } else if (pginp !== "") { pgl += pginp; } 2127 if(dir==="ltr") { pgl += str; } 2128 pgl += "</tr></tbody></table>"; 2129 if(ts.p.viewrecords===true) {$("td#"+pgid+"_"+ts.p.recordpos,"#"+pgcnt).append("<div dir='"+dir+"' style='text-align:"+ts.p.recordpos+"' class='ui-paging-info'></div>");} 2130 $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl); 2131 tdw = $(".ui-jqgrid").css("font-size") || "11px"; 2132 $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>"); 2133 twd = $(pgl).clone().appendTo("#testpg").width(); 2134 $("#testpg").remove(); 2135 if(twd > 0) { 2136 if(pginp !== "") { twd += 50; } //should be param 2137 $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd); 2138 } 2139 ts.p._nvtd = []; 2140 ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3); 2141 ts.p._nvtd[1] = 0; 2142 pgl=null; 2143 $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() { 2144 if(!clearVals('records')) { return false; } 2145 ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1; 2146 ts.p.rowNum = this.value; 2147 if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); } 2148 if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); } 2149 populate(); 2150 return false;
2151 }); 2152 if(ts.p.pgbuttons===true) { 2153 $(".ui-pg-button","#"+pgcnt).hover(function(){ 2154 if($(this).hasClass('ui-state-disabled')) { 2155 this.style.cursor='default'; 2156 } else { 2157 $(this).addClass('ui-state-hover'); 2158 this.style.cursor='pointer'; 2159 } 2160 },function() { 2161 if(!$(this).hasClass('ui-state-disabled')) { 2162 $(this).removeClass('ui-state-hover'); 2163 this.style.cursor= "default"; 2164 } 2165 }); 2166 $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() { 2167 if ($(this).hasClass("ui-state-disabled")) { 2168 return false; 2169 } 2170 var cp = intNum(ts.p.page,1), 2171 last = intNum(ts.p.lastpage,1), selclick = false, 2172 fp=true, pp=true, np=true,lp=true; 2173 if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; } 2174 else if( last>1 && cp >=1) { 2175 if( cp === 1) { fp=false; pp=false; } 2176 //else if( cp>1 && cp <last){ } 2177 else if( cp===last){ np=false;lp=false; } 2178 } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;} 2179 if(!clearVals(this.id)) { return false; } 2180 if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;} 2181 if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;} 2182 if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;} 2183 if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;} 2184 if(selclick) { 2185 populate(); 2186 } 2187 return false; 2188 }); 2189 } 2190 if(ts.p.pginput===true) { 2191 $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) { 2192 var key = e.charCode || e.keyCode || 0; 2193 if(key === 13) { 2194 if(!clearVals('user')) { return false; } 2195 $(this).val( intNum( $(this).val(), 1)); 2196 ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page; 2197 populate(); 2198 return false; 2199 } 2200 return this; 2201 }); 2202 } 2203 }, 2204 multiSort = function(iCol, obj ) { 2205 var splas, sort="", cm = ts.p.colModel, fs=false, ls, 2206 selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so=""; 2207 $("span.ui-grid-ico-sort",selTh).addClass('ui-state-disabled'); 2208 $(selTh).attr("aria-selected","false"); 2209 2210 if(cm[iCol].lso) { 2211 if(cm[iCol].lso==="asc") { 2212 cm[iCol].lso += "-desc"; 2213 so = "desc"; 2214 } else if(cm[iCol].lso==="desc") { 2215 cm[iCol].lso += "-asc"; 2216 so = "asc"; 2217 } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") { 2218 cm[iCol].lso=""; 2219 } 2220 } else { 2221 cm[iCol].lso = so = cm[iCol].firstsortorder || 'asc'; 2222 } 2223 if( so ) { 2224 $("span.s-ico",selTh).show(); 2225 $("span.ui-icon-"+so,selTh).removeClass('ui-state-disabled'); 2226 $(selTh).attr("aria-selected","true"); 2227 } else { 2228 if(!ts.p.viewsortcols[0]) { 2229 $("span.s-ico",selTh).hide(); 2230 } 2231 } 2232 ts.p.sortorder = ""; 2233 $.each(cm, function(i){ 2234 if(this.lso) { 2235 if(i>0 && fs) { 2236 sort += ", "; 2237 } 2238 splas = this.lso.split("-"); 2239 sort += cm[i].index || cm[i].name; 2240 sort += " "+splas[splas.length-1]; 2241 fs = true; 2242 ts.p.sortorder = splas[splas.length-1]; 2243 } 2244 }); 2245 ls = sort.lastIndexOf(ts.p.sortorder); 2246 sort = sort.substring(0, ls); 2247 ts.p.sortname = sort; 2248 }, 2249 sortData = function (index, idxcol,reload,sor, obj){ 2250 if(!ts.p.colModel[idxcol].sortable) { return; } 2251 if(ts.p.savedRow.length > 0) {return;} 2252 if(!reload) { 2253 if( ts.p.lastsort === idxcol ) { 2254 if( ts.p.sortorder === 'asc') { 2255 ts.p.sortorder = 'desc'; 2256 } else if(ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc';} 2257 } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; } 2258 ts.p.page = 1; 2259 } 2260 if(ts.p.multiSort) { 2261 multiSort( idxcol, obj); 2262 } else { 2263 if(sor) { 2264 if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; } 2265 ts.p.sortorder = sor; 2266 } 2267 var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el; 2268 2269 $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled'); 2270 $(previousSelectedTh).attr("aria-selected","false"); 2271 if(ts.p.frozenColumns) { 2272 ts.grid.fhDiv.find("span.ui-grid-ico-sort").addClass('ui-state-disabled'); 2273 ts.grid.fhDiv.find("th").attr("aria-selected","false"); 2274 } 2275 $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled'); 2276 $(newSelectedTh).attr("aria-selected","true"); 2277 if(!ts.p.viewsortcols[0]) { 2278 if(ts.p.lastsort !== idxcol) { 2279 if(ts.p.frozenColumns){ 2280 ts.grid.fhDiv.find("span.s-ico").hide(); 2281 } 2282 $("span.s-ico",previousSelectedTh).hide(); 2283 $("span.s-ico",newSelectedTh).show(); 2284 } 2285 } 2286 index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
2287 ts.p.sortname = ts.p.colModel[idxcol].index || index; 2288 } 2289 if ($(ts).triggerHandler("jqGridSortCol", [ts.p.sortname, idxcol, ts.p.sortorder]) === 'stop') { 2290 ts.p.lastsort = idxcol; 2291 return; 2292 } 2293 if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts, ts.p.sortname, idxcol, ts.p.sortorder)==='stop') {ts.p.lastsort = idxcol; return;}} 2294 if(ts.p.datatype === "local") { 2295 if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");} 2296 } else { 2297 ts.p.selrow = null; 2298 if(ts.p.multiselect){setHeadCheckBox( false );} 2299 ts.p.selarrrow =[]; 2300 ts.p.savedRow =[]; 2301 } 2302 if(ts.p.scroll) { 2303 var sscroll = ts.grid.bDiv.scrollLeft; 2304 emptyRows.call(ts, true, false); 2305 ts.grid.hDiv.scrollLeft = sscroll; 2306 } 2307 if(ts.p.subGrid && ts.p.datatype === 'local') { 2308 $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){ 2309 $(this).trigger("click"); 2310 }); 2311 } 2312 populate(); 2313 ts.p.lastsort = idxcol; 2314 if(ts.p.sortname !== index && idxcol) {ts.p.lastsort = idxcol;} 2315 }, 2316 setColWidth = function () { 2317 var initwidth = 0, brd=$.jgrid.cell_width? 0: intNum(ts.p.cellLayout,0), vc=0, lvc, scw=intNum(ts.p.scrollOffset,0),cw,hs=false,aw,gw=0,cr; 2318 $.each(ts.p.colModel, function() { 2319 if(this.hidden === undefined) {this.hidden=false;} 2320 if(ts.p.grouping && ts.p.autowidth) { 2321 var ind = $.inArray(this.name, ts.p.groupingView.groupField); 2322 if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) { 2323 this.hidden = !ts.p.groupingView.groupColumnShow[ind]; 2324 } 2325 } 2326 this.widthOrg = cw = intNum(this.width,0); 2327 if(this.hidden===false){ 2328 initwidth += cw+brd; 2329 if(this.fixed) { 2330 gw += cw+brd; 2331 } else { 2332 vc++; 2333 } 2334 } 2335 }); 2336 if(isNaN(ts.p.width)) { 2337 ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0); 2338 } 2339 grid.width = ts.p.width; 2340 ts.p.tblwidth = initwidth; 2341 if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;} 2342 if(ts.p.shrinkToFit===true && vc > 0) { 2343 aw = grid.width-brd*vc-gw; 2344 if(!isNaN(ts.p.height)) { 2345 aw -= scw; 2346 hs = true; 2347 } 2348 initwidth =0; 2349 $.each(ts.p.colModel, function(i) { 2350 if(this.hidden === false && !this.fixed){ 2351 cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw)); 2352 this.width =cw; 2353 initwidth += cw; 2354 lvc = i; 2355 } 2356 }); 2357 cr =0; 2358 if (hs) { 2359 if(grid.width-gw-(initwidth+brd*vc) !== scw){ 2360 cr = grid.width-gw-(initwidth+brd*vc)-scw; 2361 } 2362 } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) { 2363 cr = grid.width-gw-(initwidth+brd*vc); 2364 } 2365 ts.p.colModel[lvc].width += cr; 2366 ts.p.tblwidth = initwidth+cr+brd*vc+gw; 2367 if(ts.p.tblwidth > ts.p.width) { 2368 ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10)); 2369 ts.p.tblwidth = ts.p.width; 2370 } 2371 } 2372 }, 2373 nextVisible= function(iCol) { 2374 var ret = iCol, j=iCol, i; 2375 for (i = iCol+1;i<ts.p.colModel.length;i++){ 2376 if(ts.p.colModel[i].hidden !== true ) { 2377 j=i; break; 2378 } 2379 } 2380 return j-ret; 2381 }, 2382 getOffset = function (iCol) { 2383 var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()]; 2384 if(ts.p.direction==="rtl") { ret[0] = ts.p.width - ret[0]; } 2385 ret[0] -= ts.grid.bDiv.scrollLeft; 2386 ret.push($(ts.grid.hDiv).position().top); 2387 ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height()); 2388 return ret; 2389 }, 2390 getColumnHeaderIndex = function (th) { 2391 var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th); 2392 for (i = 0; i < headers.length; i++) { 2393 if (th === headers[i].el) { 2394 ci = i; 2395 break; 2396 } 2397 } 2398 return ci; 2399 }; 2400 this.p.id = this.id; 2401 if ($.inArray(ts.p.multikey,sortkeys) === -1 ) {ts.p.multikey = false;} 2402 ts.p.keyName=false; 2403 for (i=0; i<ts.p.colModel.length;i++) { 2404 ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, ts.p.colModel[i].template || {}, ts.p.colModel[i]); 2405 if (ts.p.keyName === false && ts.p.colModel[i].key===true) { 2406 ts.p.keyName = ts.p.colModel[i].name; 2407 } 2408 } 2409 ts.p.sortorder = ts.p.sortorder.toLowerCase(); 2410 $.jgrid.cell_width = $.jgrid.cellWidth(); 2411 if(ts.p.grouping===true) { 2412 ts.p.scroll = false;
2413 ts.p.rownumbers = false; 2414 //ts.p.subGrid = false; expiremental 2415 ts.p.treeGrid = false; 2416 ts.p.gridview = true; 2417 } 2418 if(this.p.treeGrid === true) { 2419 try { $(this).jqGrid("setTreeGrid");} catch (_) {} 2420 if(ts.p.datatype !== "local") { ts.p.localReader = {id: "_id_"}; } 2421 } 2422 if(this.p.subGrid) { 2423 try { $(ts).jqGrid("setSubGrid");} catch (s){} 2424 } 2425 if(this.p.multiselect) { 2426 this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>"); 2427 this.p.colModel.unshift({name:'cb',width:$.jgrid.cell_width ? ts.p.multiselectWidth+ts.p.cellLayout : ts.p.multiselectWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true}); 2428 } 2429 if(this.p.rownumbers) { 2430 this.p.colNames.unshift(""); 2431 this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true}); 2432 } 2433 ts.p.xmlReader = $.extend(true,{ 2434 root: "rows", 2435 row: "row", 2436 page: "rows>page", 2437 total: "rows>total", 2438 records : "rows>records", 2439 repeatitems: true, 2440 cell: "cell", 2441 id: "[id]", 2442 userdata: "userdata", 2443 subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"} 2444 }, ts.p.xmlReader); 2445 ts.p.jsonReader = $.extend(true,{ 2446 root: "rows", 2447 page: "page", 2448 total: "total", 2449 records: "records", 2450 repeatitems: true, 2451 cell: "cell", 2452 id: "id", 2453 userdata: "userdata", 2454 subgrid: {root:"rows", repeatitems: true, cell:"cell"} 2455 },ts.p.jsonReader); 2456 ts.p.localReader = $.extend(true,{ 2457 root: "rows", 2458 page: "page", 2459 total: "total", 2460 records: "records", 2461 repeatitems: false, 2462 cell: "cell", 2463 id: "id", 2464 userdata: "userdata", 2465 subgrid: {root:"rows", repeatitems: true, cell:"cell"} 2466 },ts.p.localReader); 2467 if(ts.p.scroll){ 2468 ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[]; 2469 } 2470 if(ts.p.data.length) { refreshIndex(); } 2471 var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>", 2472 tdc, idn, w, res, sort, 2473 td, ptr, tbody, imgs,iac="",idc="",sortarr=[], sortord=[], sotmp=[]; 2474 if(ts.p.shrinkToFit===true && ts.p.forceFit===true) { 2475 for (i=ts.p.colModel.length-1;i>=0;i--){ 2476 if(!ts.p.colModel[i].hidden) { 2477 ts.p.colModel[i].resizable=false; 2478 break; 2479 } 2480 } 2481 } 2482 if(ts.p.viewsortcols[1] === 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";} 2483 tdc = isMSIE ? "class='ui-th-div-ie'" :""; 2484 imgs = "<span class='s-ico' style='display:none'><span sort='asc' class='ui-grid-ico-sort ui-icon-asc"+iac+" ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-"+dir+"'></span>"; 2485 imgs += "<span sort='desc' class='ui-grid-ico-sort ui-icon-desc"+idc+" ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-"+dir+"'></span></span>"; 2486 if(ts.p.multiSort) { 2487 sortarr = ts.p.sortname.split(","); 2488 for (i=0; i<sortarr.length; i++) { 2489 sotmp = $.trim(sortarr[i]).split(" "); 2490 sortarr[i] = $.trim(sotmp[0]); 2491 sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc"; 2492 } 2493 } 2494 for(i=0;i<this.p.colNames.length;i++){ 2495 var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :""; 2496 thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">"; 2497 idn = ts.p.colModel[i].index || ts.p.colModel[i].name; 2498 thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i]; 2499 if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; } 2500 else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); } 2501 if(typeof ts.p.colModel[i].title !== "boolean") { ts.p.colModel[i].title = true; } 2502 ts.p.colModel[i].lso = ""; 2503 if (idn === ts.p.sortname) { 2504 ts.p.lastsort = i; 2505 } 2506 if(ts.p.multiSort) { 2507 sotmp = $.inArray(idn,sortarr); 2508 if( sotmp !== -1 ) { 2509 ts.p.colModel[i].lso = sortord[sotmp]; 2510 } 2511 } 2512 thead += imgs+"</div></th>"; 2513 } 2514 thead += "</tr></thead>"; 2515 imgs = null; 2516 $(this).append(thead); 2517 $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');}); 2518 if(this.p.multiselect) { 2519 var emp=[], chk;
2520 $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){ 2521 ts.p.selarrrow = []; 2522 var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : ""; 2523 if (this.checked) { 2524 $(ts.rows).each(function(i) { 2525 if (i>0) { 2526 if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){ 2527 $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true); 2528 $(this).addClass("ui-state-highlight").attr("aria-selected","true"); 2529 ts.p.selarrrow.push(this.id); 2530 ts.p.selrow = this.id; 2531 if(froz) { 2532 $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true); 2533 $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight"); 2534 } 2535 } 2536 } 2537 }); 2538 chk=true; 2539 emp=[]; 2540 } 2541 else { 2542 $(ts.rows).each(function(i) { 2543 if(i>0) { 2544 if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass('ui-state-disabled')){ 2545 $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false); 2546 $(this).removeClass("ui-state-highlight").attr("aria-selected","false"); 2547 emp.push(this.id); 2548 if(froz) { 2549 $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false); 2550 $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight"); 2551 } 2552 } 2553 } 2554 }); 2555 ts.p.selrow = null; 2556 chk=false; 2557 } 2558 $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]); 2559 if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);} 2560 }); 2561 } 2562 2563 if(ts.p.autowidth===true) { 2564 var pw = $(eg).innerWidth(); 2565 ts.p.width = pw > 0? pw: 'nw'; 2566 } 2567 setColWidth(); 2568 $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'> </div>"); 2569 $(gv).css("width",grid.width+"px"); 2570 thead = $("thead:first",ts).get(0); 2571 var tfoot = ""; 2572 if(ts.p.footerrow) { tfoot += "<table role='grid' style='width:"+ts.p.tblwidth+"px' class='ui-jqgrid-ftable' cellspacing='0' cellpadding='0' border='0'><tbody><tr role='row' class='ui-widget-content footrow footrow-"+dir+"'>"; } 2573 var thr = $("tr:first",thead), 2574 firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>"; 2575 ts.p.disableClick=false; 2576 $("th",thr).each(function ( j ) { 2577 w = ts.p.colModel[j].width; 2578 if(ts.p.colModel[j].resizable === undefined) {ts.p.colModel[j].resizable = true;} 2579 if(ts.p.colModel[j].resizable){ 2580 res = document.createElement("span"); 2581 $(res).html(" ").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir) 2582 .css("cursor","col-resize"); 2583 $(this).addClass(ts.p.resizeclass); 2584 } else { 2585 res = ""; 2586 } 2587 $(this).css("width",w+"px").prepend(res); 2588 res = null; 2589 var hdcol = ""; 2590 if( ts.p.colModel[j].hidden ) { 2591 $(this).css("display","none"); 2592 hdcol = "display:none;"; 2593 } 2594 firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>"; 2595 grid.headers[j] = { width: w, el: this }; 2596 sort = ts.p.colModel[j].sortable; 2597 if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;} 2598 var nm = ts.p.colModel[j].name; 2599 if( !(nm === 'cb' || nm==='subgrid' || nm==='rn') ) { 2600 if(ts.p.viewsortcols[2]){ 2601 $(">div",this).addClass('ui-jqgrid-sortable'); 2602 } 2603 } 2604 if(sort) { 2605 if(ts.p.multiSort) { 2606 if(ts.p.viewsortcols[0]) { 2607 $("div span.s-ico",this).show(); 2608 if(ts.p.colModel[j].lso){ 2609 $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled"); 2610 } 2611 } else if( ts.p.colModel[j].lso) { 2612 $("div span.s-ico",this).show(); 2613 $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled"); 2614 } 2615 } else { 2616 if(ts.p.viewsortcols[0]) {$("div span.s-ico",this).show(); if(j===ts.p.lastsort){ $("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}} 2617 else if( j === ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");} 2618 } 2619 } 2620 if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+"> </td>"; } 2621 }).mousedown(function(e) { 2622 if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; } 2623 var ci = getColumnHeaderIndex(this); 2624 if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);} 2625 grid.dragStart(ci, e, getOffset(ci)); 2626 return false;
2627 }).click(function(e) { 2628 if (ts.p.disableClick) { 2629 ts.p.disableClick = false; 2630 return false; 2631 } 2632 var s = "th>div.ui-jqgrid-sortable",r,d; 2633 if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; } 2634 var t = $(e.target).closest(s); 2635 if (t.length !== 1) { return; } 2636 var ci; 2637 if(ts.p.frozenColumns) { 2638 var tid = $(this)[0].id.substring( ts.p.id.length + 1 ); 2639 $(ts.p.colModel).each(function(i){ 2640 if (this.name === tid) { 2641 ci = i;return false; 2642 } 2643 }); 2644 } else { 2645 ci = getColumnHeaderIndex(this); 2646 } 2647 if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); } 2648 if(ci != null){ 2649 sortData( $('div',this)[0].id, ci, r, d, this); 2650 } 2651 return false; 2652 }); 2653 if (ts.p.sortable && $.fn.sortable) { 2654 try { 2655 $(ts).jqGrid("sortableColumns", thr); 2656 } catch (e){} 2657 } 2658 if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; } 2659 firstr += "</tr>"; 2660 tbody = document.createElement("tbody"); 2661 this.appendChild(tbody); 2662 $(this).addClass('ui-jqgrid-btable').append(firstr); 2663 firstr = null; 2664 var hTable = $("<table class='ui-jqgrid-htable' style='width:"+ts.p.tblwidth+"px' role='grid' aria-labelledby='gbox_"+this.id+"' cellspacing='0' cellpadding='0' border='0'></table>").append(thead), 2665 hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false, 2666 hb = $("<div class='ui-jqgrid-hbox" + (dir==="rtl" ? "-rtl" : "" )+"'></div>"); 2667 thead = null; 2668 grid.hDiv = document.createElement("div"); 2669 $(grid.hDiv) 2670 .css({ width: grid.width+"px"}) 2671 .addClass("ui-state-default ui-jqgrid-hdiv") 2672 .append(hb); 2673 $(hb).append(hTable); 2674 hTable = null; 2675 if(hg) { $(grid.hDiv).hide(); } 2676 if(ts.p.pager){ 2677 // TBD -- escape ts.p.pager here? 2678 if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !== "#") { ts.p.pager = "#"+ts.p.pager;} } 2679 else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");} 2680 $(ts.p.pager).css({width: grid.width+"px"}).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom').appendTo(eg); 2681 if(hg) {$(ts.p.pager).hide();} 2682 setPager(ts.p.pager,''); 2683 } 2684 if( ts.p.cellEdit === false && ts.p.hoverrows === true) { 2685 $(ts).bind('mouseover',function(e) { 2686 ptr = $(e.target).closest("tr.jqgrow"); 2687 if($(ptr).attr("class") !== "ui-subgrid") { 2688 $(ptr).addClass("ui-state-hover"); 2689 } 2690 }).bind('mouseout',function(e) { 2691 ptr = $(e.target).closest("tr.jqgrow"); 2692 $(ptr).removeClass("ui-state-hover"); 2693 }); 2694 } 2695 var ri,ci, tdHtml; 2696 $(ts).before(grid.hDiv).click(function(e) { 2697 td = e.target; 2698 ptr = $(td,ts.rows).closest("tr.jqgrow"); 2699 if($(ptr).length === 0 || ptr[0].className.indexOf( 'ui-state-disabled' ) > -1 || ($(td,ts).closest("table.ui-jqgrid-btable").attr('id') || '').replace("_frozen","") !== ts.id ) { 2700 return this; 2701 } 2702 var scb = $(td).hasClass("cbox"), 2703 cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]); 2704 cSel = (cSel === false || cSel === 'stop') ? false : true; 2705 if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); } 2706 if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT' ) && !scb) ) { return; } 2707 if(cSel === true) { 2708 ri = ptr[0].id; 2709 ci = $.jgrid.getCellIndex(td); 2710 tdHtml = $(td).closest("td,th").html(); 2711 $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]); 2712 if($.isFunction(ts.p.onCellSelect)) { 2713 ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e); 2714 } 2715 if(ts.p.cellEdit === true) { 2716 if(ts.p.multiselect && scb){ 2717 $(ts).jqGrid("setSelection", ri ,true,e); 2718 } else { 2719 ri = ptr[0].rowIndex; 2720 try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {} 2721 } 2722 } else if ( !ts.p.multikey ) { 2723 if(ts.p.multiselect && ts.p.multiboxonly) { 2724 if(scb){$(ts).jqGrid("setSelection",ri,true,e);} 2725 else { 2726 var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : ""; 2727 $(ts.p.selarrrow).each(function(i,n){ 2728 var trid = $(ts).jqGrid('getGridRowById',n); 2729 if(trid) { $( trid ).removeClass("ui-state-highlight"); }
2730 $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false); 2731 if(frz) { 2732 $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight"); 2733 $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false); 2734 } 2735 }); 2736 ts.p.selarrrow = []; 2737 $(ts).jqGrid("setSelection",ri,true,e); 2738 } 2739 } else { 2740 $(ts).jqGrid("setSelection",ri,true,e); 2741 } 2742 } else { 2743 if(e[ts.p.multikey]) { 2744 $(ts).jqGrid("setSelection",ri,true,e); 2745 } else if(ts.p.multiselect && scb) { 2746 scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked"); 2747 $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb); 2748 } 2749 } 2750 } 2751 }).bind('reloadGrid', function(e,opts) { 2752 if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;} 2753 if (opts && opts.current) { 2754 ts.grid.selectionPreserver(ts); 2755 } 2756 if(ts.p.datatype==="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} } 2757 else if(!ts.p.treeGrid) { 2758 ts.p.selrow=null; 2759 if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);} 2760 ts.p.savedRow = []; 2761 } 2762 if(ts.p.scroll) {emptyRows.call(ts, true, false);} 2763 if (opts && opts.page) { 2764 var page = opts.page; 2765 if (page > ts.p.lastpage) { page = ts.p.lastpage; } 2766 if (page < 1) { page = 1; } 2767 ts.p.page = page; 2768 if (ts.grid.prevRowHeight) { 2769 ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum; 2770 } else { 2771 ts.grid.bDiv.scrollTop = 0; 2772 } 2773 } 2774 if (ts.grid.prevRowHeight && ts.p.scroll) { 2775 delete ts.p.lastpage; 2776 ts.grid.populateVisible(); 2777 } else { 2778 ts.grid.populate(); 2779 } 2780 if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');} 2781 return false; 2782 }) 2783 .dblclick(function(e) { 2784 td = e.target; 2785 ptr = $(td,ts.rows).closest("tr.jqgrow"); 2786 if($(ptr).length === 0 ){return;} 2787 ri = ptr[0].rowIndex; 2788 ci = $.jgrid.getCellIndex(td); 2789 $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]); 2790 if ($.isFunction(ts.p.ondblClickRow)) { ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); } 2791 }) 2792 .bind('contextmenu', function(e) { 2793 td = e.target; 2794 ptr = $(td,ts.rows).closest("tr.jqgrow"); 2795 if($(ptr).length === 0 ){return;} 2796 if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); } 2797 ri = ptr[0].rowIndex; 2798 ci = $.jgrid.getCellIndex(td); 2799 $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]); 2800 if ($.isFunction(ts.p.onRightClickRow)) { ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); } 2801 }); 2802 grid.bDiv = document.createElement("div"); 2803 if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } } 2804 $(grid.bDiv) 2805 .append($('<div style="position:relative;'+(isMSIE && $.jgrid.msiever() < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this)) 2806 .addClass("ui-jqgrid-bdiv") 2807 .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"}) 2808 .scroll(grid.scrollGrid); 2809 $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"}); 2810 if( !$.support.tbody ) { //IE 2811 if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();} 2812 } 2813 if(ts.p.multikey){ 2814 if( $.jgrid.msie) { 2815 $(grid.bDiv).bind("selectstart",function(){return false;}); 2816 } else { 2817 $(grid.bDiv).bind("mousedown",function(){return false;}); 2818 } 2819 } 2820 if(hg) {$(grid.bDiv).hide();} 2821 grid.cDiv = document.createElement("div"); 2822 var arf = ts.p.hidegrid===true ? $("<a role='link' class='ui-jqgrid-titlebar-close ui-corner-all HeaderButton' />").hover( 2823 function(){ arf.addClass('ui-state-hover');}, 2824 function() {arf.removeClass('ui-state-hover');}) 2825 .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir==="rtl"?"left":"right"),"0px") : ""; 2826 $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title'>"+ts.p.caption+"</span>") 2827 .addClass("ui-jqgrid-titlebar ui-jqgrid-caption"+(dir==="rtl" ? "-rtl" :"" )+" ui-widget-header ui-corner-top ui-helper-clearfix"); 2828 $(grid.cDiv).insertBefore(grid.hDiv); 2829 if( ts.p.toolbar[0] ) { 2830 grid.uDiv = document.createElement("div"); 2831 if(ts.p.toolbar[1] === "top") {$(grid.uDiv).insertBefore(grid.hDiv);} 2832 else if (ts.p.toolbar[1]==="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);} 2833 if(ts.p.toolbar[1]==="both") { 2834 grid.ubDiv = document.createElement("div"); 2835 $(grid.uDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id
2835).insertBefore(grid.hDiv); 2836 $(grid.ubDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id).insertAfter(grid.hDiv); 2837 if(hg) {$(grid.ubDiv).hide();} 2838 } else { 2839 $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id); 2840 } 2841 if(hg) {$(grid.uDiv).hide();} 2842 } 2843 if(ts.p.toppager) { 2844 ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager"; 2845 grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0]; 2846 ts.p.toppager = "#"+ts.p.toppager; 2847 $(grid.topDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width).insertBefore(grid.hDiv); 2848 setPager(ts.p.toppager,'_t'); 2849 } 2850 if(ts.p.footerrow) { 2851 grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0]; 2852 hb = $("<div class='ui-jqgrid-hbox"+(dir==="rtl"?"-rtl":"")+"'></div>"); 2853 $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv); 2854 $(hb).append(tfoot); 2855 grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells; 2856 if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; } 2857 if(hg) {$(grid.sDiv).hide();} 2858 } 2859 hb = null; 2860 if(ts.p.caption) { 2861 var tdt = ts.p.datatype; 2862 if(ts.p.hidegrid===true) { 2863 $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){ 2864 var onHdCl = $.isFunction(ts.p.onHeaderClick), 2865 elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv", 2866 counter, self = this; 2867 if(ts.p.toolbar[0]===true) { 2868 if( ts.p.toolbar[1]==='both') { 2869 elems += ', #' + $(grid.ubDiv).attr('id'); 2870 } 2871 elems += ', #' + $(grid.uDiv).attr('id'); 2872 } 2873 counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length; 2874 2875 if(ts.p.gridstate === 'visible') { 2876 $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() { 2877 counter--; 2878 if (counter === 0) { 2879 $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s"); 2880 ts.p.gridstate = 'hidden'; 2881 if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); } 2882 $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]); 2883 if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}} 2884 } 2885 }); 2886 } else if(ts.p.gridstate === 'hidden'){ 2887 $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() { 2888 counter--; 2889 if (counter === 0) { 2890 $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n"); 2891 if(hg) {ts.p.datatype = tdt;populate();hg=false;} 2892 ts.p.gridstate = 'visible'; 2893 if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); } 2894 $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]); 2895 if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}} 2896 } 2897 }); 2898 } 2899 return false; 2900 }); 2901 if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");} 2902 } 2903 } else {$(grid.cDiv).hide();} 2904 $(grid.hDiv).after(grid.bDiv) 2905 .mousemove(function (e) { 2906 if(grid.resizing){grid.dragMove(e);return false;} 2907 }); 2908 $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; }); 2909 $(document).bind( "mouseup.jqGrid" + ts.p.id, function () { 2910 if(grid.resizing) { grid.dragEnd(); return false;} 2911 return true; 2912 }); 2913 ts.formatCol = formatCol; 2914 ts.sortData = sortData; 2915 ts.updatepager = updatepager; 2916 ts.refreshIndex = refreshIndex; 2917 ts.setHeadCheckBox = setHeadCheckBox; 2918 ts.constructTr = constructTr; 2919 ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);}; 2920 $.extend(grid,{populate : populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq}); 2921 this.grid = grid; 2922 ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);}; 2923 ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);}; 2924 this.grid.cols = this.rows[0].cells; 2925 $(ts).triggerHandler("jqGridInitGrid"); 2926 if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); } 2927 2928 populate();ts.p.hiddengrid=false; 2929 }); 2930}; 2931$.jgrid.extend({ 2932 getGridParam : function(pName) { 2933 var $t = this[0]; 2934 if (!$t || !$t.grid) {return;} 2935 if (!pName) { return $t.p; } 2936 return $t.p[pName] !== undefined ? $t.p[pName] : null; 2937 }, 2938 setGridParam : function (newParams){ 2939 return this.each(function(){ 2940 if (this.grid && typeof newParams === 'object') {$.extend(true,this.p,newParams);} 2941 }); 2942 }, 2943 getGridRowById: function ( rowid ) { 2944 var row; 2945 this.each( function(){ 2946 try { 2947 //row = this.rows.namedItem( rowid ); 2948 var i = this.rows.length; 2949 while(i--) { 2950 if( rowid.toString() === this.rows[i].id) {
2951 row = this.rows[i]; 2952 break; 2953 } 2954 } 2955 } catch ( e ) { 2956 row = $(this.grid.bDiv).find( "#" + $.jgrid.jqID( rowid )); 2957 } 2958 }); 2959 return row; 2960 }, 2961 getDataIDs : function () { 2962 var ids=[], i=0, len, j=0; 2963 this.each(function(){ 2964 len = this.rows.length; 2965 if(len && len>0){ 2966 while(i<len) { 2967 if($(this.rows[i]).hasClass('jqgrow')) { 2968 ids[j] = this.rows[i].id; 2969 j++; 2970 } 2971 i++; 2972 } 2973 } 2974 }); 2975 return ids; 2976 }, 2977 setSelection : function(selection,onsr, e) { 2978 return this.each(function(){ 2979 var $t = this, stat,pt, ner, ia, tpsr, fid, csr; 2980 if(selection === undefined) { return; } 2981 onsr = onsr === false ? false : true; 2982 pt=$($t).jqGrid('getGridRowById', selection); 2983 if(!pt || !pt.className || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; } 2984 function scrGrid(iR){ 2985 var ch = $($t.grid.bDiv)[0].clientHeight, 2986 st = $($t.grid.bDiv)[0].scrollTop, 2987 rpos = $($t.rows[iR]).position().top, 2988 rh = $t.rows[iR].clientHeight; 2989 if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; } 2990 else if(rpos < ch+st) { 2991 if(rpos < st) { 2992 $($t.grid.bDiv)[0].scrollTop = rpos; 2993 } 2994 } 2995 } 2996 if($t.p.scrollrows===true) { 2997 ner = $($t).jqGrid('getGridRowById',selection).rowIndex; 2998 if(ner >=0 ){ 2999 scrGrid(ner); 3000 } 3001 } 3002 if($t.p.frozenColumns === true ) { 3003 fid = $t.p.id+"_frozen"; 3004 } 3005 if(!$t.p.multiselect) { 3006 if(pt.className !== "ui-subgrid") { 3007 if( $t.p.selrow !== pt.id ) { 3008 csr = $($t).jqGrid('getGridRowById', $t.p.selrow); 3009 if( csr ) { 3010 $( csr ).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"}); 3011 } 3012 $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus(); 3013 if(fid) { 3014 $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); 3015 $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight"); 3016 } 3017 stat = true; 3018 } else { 3019 stat = false; 3020 } 3021 $t.p.selrow = pt.id; 3022 if( onsr ) { 3023 $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); 3024 if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); } 3025 } 3026 } 3027 } else { 3028 //unselect selectall checkbox when deselecting a specific row 3029 $t.setHeadCheckBox( false ); 3030 $t.p.selrow = pt.id; 3031 ia = $.inArray($t.p.selrow,$t.p.selarrrow); 3032 if ( ia === -1 ){ 3033 if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");} 3034 stat = true; 3035 $t.p.selarrrow.push($t.p.selrow); 3036 } else { 3037 if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");} 3038 stat = false; 3039 $t.p.selarrrow.splice(ia,1); 3040 tpsr = $t.p.selarrrow[0]; 3041 $t.p.selrow = (tpsr === undefined) ? null : tpsr; 3042 } 3043 $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat); 3044 if(fid) { 3045 if(ia === -1) { 3046 $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight"); 3047 } else { 3048 $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); 3049 } 3050 $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat); 3051 } 3052 if( onsr ) { 3053 $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); 3054 if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id , stat, e); } 3055 } 3056 } 3057 }); 3058 }, 3059 resetSelection : function( rowid ){ 3060 return this.each(function(){ 3061 var t = this, sr, fid; 3062 if( t.p.frozenColumns === true ) { 3063 fid = t.p.id+"_frozen"; 3064 } 3065 if(rowid !== undefined ) { 3066 sr = rowid === t.p.selrow ? t.p.selrow : rowid; 3067 $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false"); 3068 if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); } 3069 if(t.p.multiselect) {
3070 $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false); 3071 if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); } 3072 t.setHeadCheckBox( false); 3073 } 3074 sr = null; 3075 } else if(!t.p.multiselect) { 3076 if(t.p.selrow) { 3077 $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false"); 3078 if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); } 3079 t.p.selrow = null; 3080 } 3081 } else { 3082 $(t.p.selarrrow).each(function(i,n){ 3083 $( $(t).jqGrid('getGridRowById',n) ).removeClass("ui-state-highlight").attr("aria-selected","false"); 3084 $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false); 3085 if(fid) { 3086 $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); 3087 $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); 3088 } 3089 }); 3090 t.setHeadCheckBox( false ); 3091 t.p.selarrrow = []; 3092 t.p.selrow = null; 3093 } 3094 if(t.p.cellEdit === true) { 3095 if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) { 3096 $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight"); 3097 $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover"); 3098 } 3099 } 3100 t.p.savedRow = []; 3101 }); 3102 }, 3103 getRowData : function( rowid ) { 3104 var res = {}, resall, getall=false, len, j=0; 3105 this.each(function(){ 3106 var $t = this,nm,ind; 3107 if(rowid === undefined) { 3108 getall = true; 3109 resall = []; 3110 len = $t.rows.length; 3111 } else { 3112 ind = $($t).jqGrid('getGridRowById', rowid); 3113 if(!ind) { return res; } 3114 len = 2; 3115 } 3116 while(j<len){ 3117 if(getall) { ind = $t.rows[j]; } 3118 if( $(ind).hasClass('jqgrow') ) { 3119 $('td[role="gridcell"]',ind).each( function(i) { 3120 nm = $t.p.colModel[i].name; 3121 if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') { 3122 if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) { 3123 res[nm] = $.jgrid.htmlDecode($("span:first",this).html()); 3124 } else { 3125 try { 3126 res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i); 3127 } catch (e){ 3128 res[nm] = $.jgrid.htmlDecode($(this).html()); 3129 } 3130 } 3131 } 3132 }); 3133 if(getall) { resall.push(res); res={}; } 3134 } 3135 j++; 3136 } 3137 }); 3138 return resall || res; 3139 }, 3140 delRowData : function(rowid) { 3141 var success = false, rowInd, ia, nextRow; 3142 this.each(function() { 3143 var $t = this; 3144 rowInd = $($t).jqGrid('getGridRowById', rowid); 3145 if(!rowInd) {return false;} 3146 if($t.p.subGrid) { 3147 nextRow = $(rowInd).next(); 3148 if(nextRow.hasClass('ui-subgrid')) { 3149 nextRow.remove(); 3150 } 3151 } 3152 $(rowInd).remove(); 3153 $t.p.records--; 3154 $t.p.reccount--; 3155 $t.updatepager(true,false); 3156 success=true; 3157 if($t.p.multiselect) { 3158 ia = $.inArray(rowid,$t.p.selarrrow); 3159 if(ia !== -1) { $t.p.selarrrow.splice(ia,1);} 3160 } 3161 if ($t.p.multiselect && $t.p.selarrrow.length > 0) { 3162 $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1]; 3163 } else { 3164 $t.p.selrow = null; 3165 } 3166 if($t.p.datatype === 'local') { 3167 var id = $.jgrid.stripPref($t.p.idPrefix, rowid), 3168 pos = $t.p._index[id]; 3169 if(pos !== undefined) { 3170 $t.p.data.splice(pos,1); 3171 $t.refreshIndex(); 3172 } 3173 } 3174 if( $t.p.altRows === true && success ) { 3175 var cn = $t.p.altclass; 3176 $($t.rows).each(function(i){ 3177 if(i % 2 === 1) { $(this).addClass(cn); } 3178 else { $(this).removeClass(cn); } 3179 }); 3180 } 3181 }); 3182 return success; 3183 }, 3184 setRowData : function(rowid, data, cssp) { 3185 var nm, success=true, title; 3186 this.each(function(){ 3187 if(!this.grid) {return false;} 3188 var t = this, vl, ind, cp = typeof cssp, lcdata={}; 3189 ind = $(this).jqGrid('getGridRowById', rowid); 3190 if(!ind) { return false; } 3191 if( data ) { 3192 try { 3193 $(this.p.colModel).each(function(i){ 3194 nm = this.name; 3195 var dval =$.jgrid.getAccessor(data,nm); 3196 if( dval !== undefined) { 3197 lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval; 3198 vl = t.formatter( rowid, dval, i, data, 'edit');
3199 title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {}; 3200 if(t.p.treeGrid===true && nm === t.p.ExpandColumn) { 3201 $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title); 3202 } else { 3203 $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title); 3204 } 3205 } 3206 }); 3207 if(t.p.datatype === 'local') { 3208 var id = $.jgrid.stripPref(t.p.idPrefix, rowid), 3209 pos = t.p._index[id], key; 3210 if(t.p.treeGrid) { 3211 for(key in t.p.treeReader){ 3212 if(t.p.treeReader.hasOwnProperty(key)) { 3213 delete lcdata[t.p.treeReader[key]]; 3214 } 3215 } 3216 } 3217 if(pos !== undefined) { 3218 t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata); 3219 } 3220 lcdata = null; 3221 } 3222 } catch (e) { 3223 success = false; 3224 } 3225 } 3226 if(success) { 3227 if(cp === 'string') {$(ind).addClass(cssp);} else if(cssp !== null && cp === 'object') {$(ind).css(cssp);} 3228 $(t).triggerHandler("jqGridAfterGridComplete"); 3229 } 3230 }); 3231 return success; 3232 }, 3233 addRowData : function(rowid,rdata,pos,src) { 3234 if(!pos) {pos = "last";} 3235 var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id; 3236 if(rdata) { 3237 if($.isArray(rdata)) { 3238 aradd=true; 3239 pos = "last"; 3240 cnm = rowid; 3241 } else { 3242 rdata = [rdata]; 3243 aradd = false; 3244 } 3245 this.each(function() { 3246 var t = this, datalen = rdata.length; 3247 ni = t.p.rownumbers===true ? 1 :0; 3248 gi = t.p.multiselect ===true ? 1 :0; 3249 si = t.p.subGrid===true ? 1 :0; 3250 if(!aradd) { 3251 if(rowid !== undefined) { rowid = String(rowid);} 3252 else { 3253 rowid = $.jgrid.randId(); 3254 if(t.p.keyName !== false) { 3255 cnm = t.p.keyName; 3256 if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; } 3257 } 3258 } 3259 } 3260 cn = t.p.altclass; 3261 var k = 0, cna ="", lcdata = {}, 3262 air = $.isFunction(t.p.afterInsertRow) ? true : false; 3263 while(k < datalen) { 3264 data = rdata[k]; 3265 row=[]; 3266 if(aradd) { 3267 try { 3268 rowid = data[cnm]; 3269 if(rowid===undefined) { 3270 rowid = $.jgrid.randId(); 3271 } 3272 } 3273 catch (e) {rowid = $.jgrid.randId();} 3274 cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : ""; 3275 } 3276 id = rowid; 3277 rowid = t.p.idPrefix + rowid; 3278 if(ni){ 3279 prp = t.formatCol(0,1,'',null,rowid, true); 3280 row[row.length] = "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>"; 3281 } 3282 if(gi) { 3283 v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>"; 3284 prp = t.formatCol(ni,1,'', null, rowid, true); 3285 row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>"; 3286 } 3287 if(si) { 3288 row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1); 3289 } 3290 for(i = gi+si+ni; i < t.p.colModel.length;i++){ 3291 cm = t.p.colModel[i]; 3292 nm = cm.name; 3293 lcdata[nm] = data[nm]; 3294 v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data ); 3295 prp = t.formatCol(i,1,v, data, rowid, lcdata); 3296 row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>"; 3297 } 3298 row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) ); 3299 row[row.length] = "</tr>"; 3300 if(t.rows.length === 0){ 3301 $("table:first",t.grid.bDiv).append(row.join('')); 3302 } else { 3303 switch (pos) { 3304 case 'last': 3305 $(t.rows[t.rows.length-1]).after(row.join('')); 3306 sind = t.rows.length-1; 3307 break; 3308 case 'first': 3309 $(t.rows[0]).after(row.join('')); 3310 sind = 1; 3311 break; 3312 case 'after': 3313 sind = $(t).jqGrid('getGridRowById', src); 3314 if (sind) { 3315 if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); } 3316 else { $(sind).after(row.join('')); } 3317 sind=sind.rowIndex + 1; 3318 } 3319 break; 3320 case 'before': 3321 sind = $(t).jqGrid('getGridRowById', src); 3322 if(sind) { 3323 $(sind).before(row.join('')); 3324 sind=sind.rowIndex - 1; 3325 } 3326 break; 3327 } 3328 } 3329 if(t.p.subGrid===true) { 3330 $(t).jqGrid("addSubGrid",gi+ni, sind); 3331 } 3332 t.p.records++; 3333 t.p.reccount++; 3334 $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]); 3335 if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
3336 k++; 3337 if(t.p.datatype === 'local') { 3338 lcdata[t.p.localReader.id] = id; 3339 t.p._index[id] = t.p.data.length; 3340 t.p.data.push(lcdata); 3341 lcdata = {}; 3342 } 3343 } 3344 if( t.p.altRows === true && !aradd) { 3345 if (pos === "last") { 3346 if ((t.rows.length-1)%2 === 1) {$(t.rows[t.rows.length-1]).addClass(cn);} 3347 } else { 3348 $(t.rows).each(function(i){ 3349 if(i % 2 ===1) { $(this).addClass(cn); } 3350 else { $(this).removeClass(cn); } 3351 }); 3352 } 3353 } 3354 t.updatepager(true,true); 3355 success = true; 3356 }); 3357 } 3358 return success; 3359 }, 3360 footerData : function(action,data, format) { 3361 var nm, success=false, res={}, title; 3362 function isEmpty(obj) { 3363 var i; 3364 for(i in obj) { 3365 if (obj.hasOwnProperty(i)) { return false; } 3366 } 3367 return true; 3368 } 3369 if(action == undefined) { action = "get"; } 3370 if(typeof format !== "boolean") { format = true; } 3371 action = action.toLowerCase(); 3372 this.each(function(){ 3373 var t = this, vl; 3374 if(!t.grid || !t.p.footerrow) {return false;} 3375 if(action === "set") { if(isEmpty(data)) { return false; } } 3376 success=true; 3377 $(this.p.colModel).each(function(i){ 3378 nm = this.name; 3379 if(action === "set") { 3380 if( data[nm] !== undefined) { 3381 vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm]; 3382 title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {}; 3383 $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title); 3384 success = true; 3385 } 3386 } else if(action === "get") { 3387 res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(); 3388 } 3389 }); 3390 }); 3391 return action === "get" ? res : success; 3392 }, 3393 showHideCol : function(colname,show) { 3394 return this.each(function() { 3395 var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw; 3396 if (!$t.grid ) {return;} 3397 if( typeof colname === 'string') {colname=[colname];} 3398 show = show !== "none" ? "" : "none"; 3399 var sw = show === "" ? true :false, 3400 gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) ); 3401 if(gh) { $($t).jqGrid('destroyGroupHeader', false); } 3402 $(this.p.colModel).each(function(i) { 3403 if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) { 3404 if($t.p.frozenColumns === true && this.frozen === true) { 3405 return true; 3406 } 3407 $("tr[role=rowheader]",$t.grid.hDiv).each(function(){ 3408 $(this.cells[i]).css("display", show); 3409 }); 3410 $($t.rows).each(function(){ 3411 if (!$(this).hasClass("jqgroup")) { 3412 $(this.cells[i]).css("display", show); 3413 } 3414 }); 3415 if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); } 3416 cw = parseInt(this.width,10); 3417 if(show === "none") { 3418 $t.p.tblwidth -= cw+brd; 3419 } else { 3420 $t.p.tblwidth += cw+brd; 3421 } 3422 this.hidden = !sw; 3423 fndh=true; 3424 $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]); 3425 } 3426 }); 3427 if(fndh===true) { 3428 if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);} 3429 $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width ); 3430 } 3431 if( gh ) { 3432 $($t).jqGrid('setGroupHeaders',$t.p.groupHeader); 3433 } 3434 }); 3435 }, 3436 hideCol : function (colname) { 3437 return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");}); 3438 }, 3439 showCol : function(colname) { 3440 return this.each(function(){$(this).jqGrid("showHideCol",colname,"");}); 3441 }, 3442 remapColumns : function(permutation, updateCells, keepHeader) 3443 { 3444 function resortArray(a) { 3445 var ac; 3446 if (a.length) { 3447 ac = $.makeArray(a); 3448 } else { 3449 ac = $.extend({}, a); 3450 } 3451 $.each(permutation, function(i) { 3452 a[i] = ac[this]; 3453 }); 3454 } 3455 var ts = this.get(0); 3456 function resortRows(parent, clobj) { 3457 $(">tr"+(clobj||""), parent).each(function() { 3458 var row = this; 3459 var elems = $.makeArray(row.cells); 3460 $.each(permutation, function() { 3461 var e = elems[this]; 3462 if (e) { 3463 row.appendChild(e); 3464 } 3465 }); 3466 }); 3467 } 3468 resortArray(ts.p.colModel); 3469 resortArray(ts.p.colNames); 3470 resortArray(ts.grid.headers); 3471 resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)"); 3472 if (updateCells) { 3473 resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot"); 3474 } 3475 if (ts.p.footerrow) { 3476 resortRows($("tbody:first", ts.grid.sDiv)); 3477 } 3478 if (ts.p.remapColumns) { 3479 if (!ts.p.remapColumns.length){ 3480 ts.p.remapColumns = $.makeArray(permutation); 3481 } else { 3482 resortArray(ts.p.remapColumns); 3483 } 3484 } 3485 ts.p.lastsort = $.inArray(ts.p.lastsort, permutation); 3486 if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
3487 $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]); 3488 }, 3489 setGridWidth : function(nwidth, shrink) { 3490 return this.each(function(){ 3491 if (!this.grid ) {return;} 3492 var $t = this, cw, 3493 initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr; 3494 if(typeof shrink !== 'boolean') { 3495 shrink=$t.p.shrinkToFit; 3496 } 3497 if(isNaN(nwidth)) {return;} 3498 nwidth = parseInt(nwidth,10); 3499 $t.grid.width = $t.p.width = nwidth; 3500 $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px"); 3501 $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px"); 3502 $($t.grid.bDiv).css("width",nwidth+"px"); 3503 $($t.grid.hDiv).css("width",nwidth+"px"); 3504 if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");} 3505 if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");} 3506 if($t.p.toolbar[0] === true){ 3507 $($t.grid.uDiv).css("width",nwidth+"px"); 3508 if($t.p.toolbar[1]==="both") {$($t.grid.ubDiv).css("width",nwidth+"px");} 3509 } 3510 if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); } 3511 if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;} 3512 if(shrink===true) { 3513 $.each($t.p.colModel, function() { 3514 if(this.hidden===false){ 3515 cw = this.widthOrg; 3516 initwidth += cw+brd; 3517 if(this.fixed) { 3518 gw += cw+brd; 3519 } else { 3520 vc++; 3521 } 3522 } 3523 }); 3524 if(vc === 0) { return; } 3525 $t.p.tblwidth = initwidth; 3526 aw = nwidth-brd*vc-gw; 3527 if(!isNaN($t.p.height)) { 3528 if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){ 3529 hs = true; 3530 aw -= scw; 3531 } 3532 } 3533 initwidth =0; 3534 var cle = $t.grid.cols.length >0; 3535 $.each($t.p.colModel, function(i) { 3536 if(this.hidden === false && !this.fixed){ 3537 cw = this.widthOrg; 3538 cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw)); 3539 if (cw < 0) { return; } 3540 this.width =cw; 3541 initwidth += cw; 3542 $t.grid.headers[i].width=cw; 3543 $t.grid.headers[i].el.style.width=cw+"px"; 3544 if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; } 3545 if(cle) { $t.grid.cols[i].style.width = cw+"px"; } 3546 lvc = i; 3547 } 3548 }); 3549 3550 if (!lvc) { return; } 3551 3552 cr =0; 3553 if (hs) { 3554 if(nwidth-gw-(initwidth+brd*vc) !== scw){ 3555 cr = nwidth-gw-(initwidth+brd*vc)-scw; 3556 } 3557 } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) { 3558 cr = nwidth-gw-(initwidth+brd*vc); 3559 } 3560 $t.p.colModel[lvc].width += cr; 3561 $t.p.tblwidth = initwidth+cr+brd*vc+gw; 3562 if($t.p.tblwidth > nwidth) { 3563 var delta = $t.p.tblwidth - parseInt(nwidth,10); 3564 $t.p.tblwidth = nwidth; 3565 cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta; 3566 } else { 3567 cw= $t.p.colModel[lvc].width; 3568 } 3569 $t.grid.headers[lvc].width = cw; 3570 $t.grid.headers[lvc].el.style.width=cw+"px"; 3571 if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; } 3572 if($t.p.footerrow) { 3573 $t.grid.footers[lvc].style.width = cw+"px"; 3574 } 3575 } 3576 if($t.p.tblwidth) { 3577 $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px"); 3578 $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px"); 3579 $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; 3580 if($t.p.footerrow) { 3581 $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px"); 3582 } 3583 } 3584 }); 3585 }, 3586 setGridHeight : function (nh) { 3587 return this.each(function (){ 3588 var $t = this; 3589 if(!$t.grid) {return;} 3590 var bDiv = $($t.grid.bDiv); 3591 bDiv.css({height: nh+(isNaN(nh)?"":"px")}); 3592 if($t.p.frozenColumns === true){ 3593 //follow the original set height to use 16, better scrollbar width detection 3594 $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16); 3595 } 3596 $t.p.height = nh; 3597 if ($t.p.scroll) { $t.grid.populateVisible(); } 3598 }); 3599 }, 3600 setCaption : function (newcap){ 3601 return this.each(function(){ 3602 this.p.caption=newcap; 3603 $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap); 3604 $(this.grid.cDiv).show(); 3605 }); 3606 }, 3607 setLabel : function(colname, nData, prop, attrp ){ 3608 return this.each(function(){ 3609 var $t = this, pos=-1; 3610 if(!$t.grid) {return;} 3611 if(colname !== undefined) { 3612 $($t.p.colModel).each(function(i){ 3613 if (this.name === colname) { 3614 pos = i;return false;
3615 } 3616 }); 3617 } else { return; } 3618 if(pos>=0) { 3619 var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv); 3620 if (nData){ 3621 var ico = $(".s-ico",thecol); 3622 $("[id^=jqgh_]",thecol).empty().html(nData).append(ico); 3623 $t.p.colNames[pos] = nData; 3624 } 3625 if (prop) { 3626 if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);} 3627 } 3628 if(typeof attrp === 'object') {$(thecol).attr(attrp);} 3629 } 3630 }); 3631 }, 3632 setCell : function(rowid,colname,nData,cssp,attrp, forceupd) { 3633 return this.each(function(){ 3634 var $t = this, pos =-1,v, title; 3635 if(!$t.grid) {return;} 3636 if(isNaN(colname)) { 3637 $($t.p.colModel).each(function(i){ 3638 if (this.name === colname) { 3639 pos = i;return false; 3640 } 3641 }); 3642 } else {pos = parseInt(colname,10);} 3643 if(pos>=0) { 3644 var ind = $($t).jqGrid('getGridRowById', rowid); 3645 if (ind){ 3646 var tcell = $("td:eq("+pos+")",ind); 3647 if(nData !== "" || forceupd === true) { 3648 v = $t.formatter(rowid, nData, pos,ind,'edit'); 3649 title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {}; 3650 if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) { 3651 $("span",$(tcell)).html(v).attr(title); 3652 } else { 3653 $(tcell).html(v).attr(title); 3654 } 3655 if($t.p.datatype === "local") { 3656 var cm = $t.p.colModel[pos], index; 3657 nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t,nData,cm) : nData; 3658 index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)]; 3659 if(index !== undefined) { 3660 $t.p.data[index][cm.name] = nData; 3661 } 3662 } 3663 } 3664 if(typeof cssp === 'string'){ 3665 $(tcell).addClass(cssp); 3666 } else if(cssp) { 3667 $(tcell).css(cssp); 3668 } 3669 if(typeof attrp === 'object') {$(tcell).attr(attrp);} 3670 } 3671 } 3672 }); 3673 }, 3674 getCell : function(rowid,col) { 3675 var ret = false;
3676 this.each(function(){ 3677 var $t=this, pos=-1; 3678 if(!$t.grid) {return;} 3679 if(isNaN(col)) { 3680 $($t.p.colModel).each(function(i){ 3681 if (this.name === col) { 3682 pos = i;return false; 3683 } 3684 }); 3685 } else {pos = parseInt(col,10);} 3686 if(pos>=0) { 3687 var ind = $($t).jqGrid('getGridRowById', rowid); 3688 if(ind) { 3689 try { 3690 ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos); 3691 } catch (e){ 3692 ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html()); 3693 } 3694 } 3695 } 3696 }); 3697 return ret; 3698 }, 3699 getCol : function (col, obj, mathopr) { 3700 var ret = [], val, sum=0, min, max, v; 3701 obj = typeof obj !== 'boolean' ? false : obj; 3702 if(mathopr === undefined) { mathopr = false; } 3703 this.each(function(){ 3704 var $t=this, pos=-1; 3705 if(!$t.grid) {return;} 3706 if(isNaN(col)) { 3707 $($t.p.colModel).each(function(i){ 3708 if (this.name === col) { 3709 pos = i;return false; 3710 } 3711 }); 3712 } else {pos = parseInt(col,10);} 3713 if(pos>=0) { 3714 var ln = $t.rows.length, i =0, dlen=0; 3715 if (ln && ln>0){ 3716 while(i<ln){ 3717 if($($t.rows[i]).hasClass('jqgrow')) { 3718 try { 3719 val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos); 3720 } catch (e) { 3721 val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML); 3722 } 3723 if(mathopr) { 3724 v = parseFloat(val); 3725 if(!isNaN(v)) { 3726 sum += v; 3727 if (max === undefined) {max = min = v;} 3728 min = Math.min(min, v); 3729 max = Math.max(max, v); 3730 dlen++; 3731 } 3732 } 3733 else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); } 3734 else { ret.push( val ); } 3735 } 3736 i++; 3737 } 3738 if(mathopr) { 3739 switch(mathopr.toLowerCase()){ 3740 case 'sum': ret =sum; break; 3741 case 'avg': ret = sum/dlen; break; 3742 case 'count': ret = (ln-1); break; 3743 case 'min': ret = min; break; 3744 case 'max': ret = max; break; 3745 } 3746 } 3747 } 3748 } 3749 }); 3750 return ret; 3751 }, 3752 clearGridData : function(clearfooter) { 3753 return this.each(function(){ 3754 var $t = this; 3755 if(!$t.grid) {return;} 3756 if(typeof clearfooter !== 'boolean') { clearfooter = false; } 3757 if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();} 3758 else { 3759 var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0]; 3760 $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf); 3761 } 3762 if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html(" "); } 3763 $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = []; 3764 $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0; 3765 $t.p.data = []; $t.p._index = {}; 3766 $t.updatepager(true,false); 3767 }); 3768 }, 3769 getInd : function(rowid,rc){ 3770 var ret =false,rw; 3771 this.each(function(){ 3772 rw = $(this).jqGrid('getGridRowById', rowid); 3773 if(rw) { 3774 ret = rc===true ? rw: rw.rowIndex; 3775 } 3776 }); 3777 return ret; 3778 }, 3779 bindKeys : function( settings ){ 3780 var o = $.extend({ 3781 onEnter: null, 3782 onSpace: null, 3783 onLeftKey: null, 3784 onRightKey: null, 3785 scrollingRows : true 3786 },settings || {}); 3787 return this.each(function(){ 3788 var $t = this; 3789 if( !$('body').is('[role]') ){$('body').attr('role','application');} 3790 $t.p.scrollrows = o.scrollingRows; 3791 $($t).keydown(function(event){ 3792 var target = $($t).find('tr[tabindex=0]')[0], id, r, mind, 3793 expanded = $t.p.treeReader.expanded_field; 3794 //check for arrow keys 3795 if(target) { 3796 mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)]; 3797 if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){ 3798 // up key 3799 if(event.keyCode === 38 ){ 3800 r = target.previousSibling; 3801 id = ""; 3802 if(r) { 3803 if($(r).is(":hidden")) { 3804 while(r) { 3805 r = r.previousSibling; 3806 if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;} 3807 } 3808 } else { 3809 id = r.id; 3810 } 3811 } 3812 $($t).jqGrid('setSelection', id, true, event); 3813 event.preventDefault(); 3814 } 3815 //if key is down arrow 3816 if(event.keyCode === 40){ 3817 r = target.nextSibling; 3818 id =""; 3819 if(r) { 3820 if($(r).is(":hidden")) { 3821 while(r) { 3822 r = r.nextSibling; 3823 if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;} 3824 } 3825 } else { 3826 id = r.id; 3827 } 3828 } 3829 $($t).jqGrid('setSelection', id, true, event); 3830 event.preventDefault(); 3831 } 3832 // left 3833 if(event.keyCode === 37 ){
3834 if($t.p.treeGrid && $t.p.data[mind][expanded]) { 3835 $(target).find("div.treeclick").trigger('click'); 3836 } 3837 $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]); 3838 if($.isFunction(o.onLeftKey)) { 3839 o.onLeftKey.call($t, $t.p.selrow); 3840 } 3841 } 3842 // right 3843 if(event.keyCode === 39 ){ 3844 if($t.p.treeGrid && !$t.p.data[mind][expanded]) { 3845 $(target).find("div.treeclick").trigger('click'); 3846 } 3847 $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]); 3848 if($.isFunction(o.onRightKey)) { 3849 o.onRightKey.call($t, $t.p.selrow); 3850 } 3851 } 3852 } 3853 //check if enter was pressed on a grid or treegrid node 3854 else if( event.keyCode === 13 ){ 3855 $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]); 3856 if($.isFunction(o.onEnter)) { 3857 o.onEnter.call($t, $t.p.selrow); 3858 } 3859 } else if(event.keyCode === 32) { 3860 $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]); 3861 if($.isFunction(o.onSpace)) { 3862 o.onSpace.call($t, $t.p.selrow); 3863 } 3864 } 3865 } 3866 }); 3867 }); 3868 }, 3869 unbindKeys : function(){ 3870 return this.each(function(){ 3871 $(this).unbind('keydown'); 3872 }); 3873 }, 3874 getLocalRow : function (rowid) { 3875 var ret = false, ind; 3876 this.each(function(){ 3877 if(rowid !== undefined) { 3878 ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)]; 3879 if(ind >= 0 ) { 3880 ret = this.p.data[ind]; 3881 } 3882 } 3883 }); 3884 return ret; 3885 } 3886}); 3887})(jQuery); 3888/*jshint eqeqeq:false */ 3889/*global jQuery */ 3890(function($){ 3891/** 3892 * jqGrid extension for custom methods 3893 * Tony Tomov [email protected] 3894 * http://trirand.com/blog/ 3895 * 3896 * Wildraid [email protected] 3897 * Oleg Kiriljuk [email protected] 3898 * Dual licensed under the MIT and GPL licenses: 3899 * http://www.opensource.org/licenses/mit-license.php 3900 * http://www.gnu.org/licenses/gpl-2.0.html 3901**/ 3902"use strict"; 3903$.jgrid.extend({ 3904 getColProp : function(colname){ 3905 var ret ={}, $t = this[0]; 3906 if ( !$t.grid ) { return false; } 3907 var cM = $t.p.colModel, i; 3908 for ( i=0;i<cM.length;i++ ) { 3909 if ( cM[i].name === colname ) { 3910 ret = cM[i]; 3911 break; 3912 } 3913 } 3914 return ret; 3915 }, 3916 setColProp : function(colname, obj){ 3917 //do not set width will not work 3918 return this.each(function(){ 3919 if ( this.grid ) { 3920 if ( obj ) { 3921 var cM = this.p.colModel, i; 3922 for ( i=0;i<cM.length;i++ ) { 3923 if ( cM[i].name === colname ) { 3924 $.extend(true, this.p.colModel[i],obj); 3925 break; 3926 } 3927 } 3928 } 3929 } 3930 }); 3931 }, 3932 sortGrid : function(colname,reload, sor){ 3933 return this.each(function(){ 3934 var $t=this,idx=-1,i, sobj=false; 3935 if ( !$t.grid ) { return;} 3936 if ( !colname ) { colname = $t.p.sortname; } 3937 for ( i=0;i<$t.p.colModel.length;i++ ) { 3938 if ( $t.p.colModel[i].index === colname || $t.p.colModel[i].name === colname ) { 3939 idx = i; 3940 if($t.p.frozenColumns === true && $t.p.colModel[i].frozen === true) { 3941 sobj = $t.grid.fhDiv.find("#" + $t.p.id + "_" + colname); 3942 } 3943 break; 3944 } 3945 } 3946 if ( idx !== -1 ){ 3947 var sort = $t.p.colModel[idx].sortable; 3948 if(!sobj) { 3949 sobj = $t.grid.headers[idx].el; 3950 } 3951 if ( typeof sort !== 'boolean' ) { sort = true; } 3952 if ( typeof reload !=='boolean' ) { reload = false; } 3953 if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor, sobj); } 3954 } 3955 }); 3956 }, 3957 clearBeforeUnload : function () { 3958 return this.each(function(){ 3959 var grid = this.grid; 3960 if ($.isFunction(grid.emptyRows)) { 3961 grid.emptyRows.call(this, true, true); // this work quick enough and reduce the size of memory leaks if we have someone 3962 } 3963 3964 $(document).unbind("mouseup.jqGrid" + this.p.id ); 3965 $(grid.hDiv).unbind("mousemove"); // TODO add namespace 3966 $(this).unbind(); 3967 3968 grid.dragEnd = null; 3969 grid.dragMove = null; 3970 grid.dragStart = null; 3971 grid.emptyRows = null; 3972 grid.populate = null; 3973 grid.populateVisible = null; 3974 grid.scrollGrid = null; 3975 grid.selectionPreserver = null; 3976 3977 grid.bDiv = null; 3978 grid.cDiv = null; 3979 grid.hDiv = null; 3980 grid.cols = null; 3981 var i, l = grid.headers.length; 3982 for (i = 0; i < l; i++) { 3983 grid.headers[i].el = null; 3984 } 3985 3986 this.formatCol = null; 3987 this.sortData = null; 3988 this.updatepager = null; 3989 this.refreshIndex = null; 3990 this.setHeadCheckBox = null; 3991 this.constructTr = null; 3992 this.formatter = null; 3993 this.addXmlData = null; 3994 this.addJSONData = null; 3995 this.grid = null; 3996 }); 3997 }, 3998 GridDestroy : function () { 3999 return this.each(function(){ 4000 if ( this.grid ) { 4001 if ( this.p.pager ) { // if not part of grid 4002 $(this.p.pager).remove(); 4003 } 4004 try { 4005 $(this).jqGrid('clearBeforeUnload'); 4006 $("#gbox_"+$.jgrid.jqID(this.id)).remove(); 4007 } catch (_) {} 4008 } 4009 }); 4010 }, 4011 GridUnload : function(){ 4012 return this.each(function(){ 4013 if ( !this.grid ) {return;} 4014 var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')}; 4015 if (this.p.pager) { 4016 $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager ui-corner-bottom"); 4017 } 4018 var newtable = document.createElement('table'); 4019 $(newtable).attr({id:defgrid.id}); 4020 newtable.className = defgrid.cl; 4021 var gid = $.jgrid.jqID(this.id); 4022 $(newtable).removeClass("ui-jqgrid-btable"); 4023 if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) { 4024 $(newtable).insertBefore("#gbox_"+gid).show(); 4025 $(this.p.pager).insertBefore("#gbox_"+gid); 4026 } else { 4027 $(newtable).insertBefore("#gbox_"+gid).show(); 4028 } 4029 $(this).jqGrid('clearBeforeUnload'); 4030 $("#gbox_"+gid).remove(); 4031 }); 4032 }, 4033 setGridState : function(state) { 4034 return this.each(function(){ 4035 if ( !this.grid ) {return;} 4036 var $t = this; 4037 if(state === 'hidden'){ 4038 $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); 4039 if($t.p.pager) {$($t.p.pager).slideUp("fast");} 4040 if($t.p.toppager) {$($t.p.toppager).slideUp("fast");} 4041 if($t.p.toolbar[0]===true) { 4042 if( $t.p.toolbar[1] === 'both') { 4043 $($t.grid.ubDiv).slideUp("fast"); 4044 } 4045 $($t.grid.uDiv).slideUp("fast"); 4046 } 4047 if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); } 4048 $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s"); 4049 $t.p.gridstate = 'hidden'; 4050 } else if(state === 'visible') { 4051 $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); 4052 if($t.p.pager) {$($t.p.pager).slideDown("fast");} 4053 if($t.p.toppager) {$($t.p.toppager).slideDown("fast");} 4054 if($t.p.toolbar[0]===true) { 4055 if( $t.p.toolbar[1] === 'both') { 4056 $($t.grid.ubDiv).slideDown("fast"); 4057 } 4058 $($t.grid.uDiv).slideDown("fast"); 4059 } 4060 if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); } 4061 $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n"); 4062 $t.p.gridstate = 'visible'; 4063 } 4064 4065 }); 4066 }, 4067 filterToolbar : function(p){ 4068 p = $.extend({ 4069 autosearch: true, 4070 searchOnEnter : true, 4071 beforeSearch: null, 4072 afterSearch: null, 4073 beforeClear: null, 4074 afterClear: null, 4075 searchurl : '', 4076 stringResult: false, 4077 groupOp: 'AND', 4078 defaultSearch : "bw", 4079 searchOperators : false, 4080 resetIcon : "x", 4081 operands : { "eq" :"==", "ne":"!","lt":"<","le":"<=","gt":">","ge":">=","bw":"^","bn":"!^","in":"=","ni":"!=","ew":"|","en":"!@","cn":"~","nc":"!~","nu":"#","nn":"!#"} 4082 }, $.jgrid.search , p || {}); 4083 return this.each(function(){ 4084 var $t = this; 4085 if(this.ftoolbar) { return; } 4086 var triggerToolbar = function() { 4087 var sdata={}, j=0, v, nm, sopt={},so; 4088 $.each($t.p.colModel,function(){ 4089 var $elem = $("#gs_"+$.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv); 4090 nm = this.index || this.name; 4091 if(p.searchOperators ) { 4092 so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch; 4093 } else { 4094 so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : this.stype==='select'? 'eq' : p.defaultSearch; 4095 } 4096 v = this.stype === "custom" && $.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN" ? 4097 this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "get") : 4098 $elem.val(); 4099 if(v || so==="nu" || so==="nn") { 4100 sdata[nm] = v; 4101 sopt[nm] = so; 4102 j++; 4103 } else { 4104 try { 4105 delete $t.p.postData[nm]; 4106 } catch (z) {} 4107 } 4108 }); 4109 var sd = j>0 ? true : false;
4110 if(p.stringResult === true || $t.p.datatype === "local" || p.searchOperators === true) { 4111 var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":["; 4112 var gi=0; 4113 $.each(sdata,function(i,n){ 4114 if (gi > 0) {ruleGroup += ",";} 4115 ruleGroup += "{\"field\":\"" + i + "\","; 4116 ruleGroup += "\"op\":\"" + sopt[i] + "\","; 4117 n+=""; 4118 ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}"; 4119 gi++; 4120 }); 4121 ruleGroup += "]}"; 4122 $.extend($t.p.postData,{filters:ruleGroup}); 4123 $.each(['searchField', 'searchString', 'searchOper'], function(i, n){ 4124 if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];} 4125 }); 4126 } else { 4127 $.extend($t.p.postData,sdata); 4128 } 4129 var saveurl; 4130 if($t.p.searchurl) { 4131 saveurl = $t.p.url; 4132 $($t).jqGrid("setGridParam",{url:$t.p.searchurl}); 4133 } 4134 var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false; 4135 if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);} 4136 if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); } 4137 if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});} 4138 $($t).triggerHandler("jqGridToolbarAfterSearch"); 4139 if($.isFunction(p.afterSearch)){p.afterSearch.call($t);} 4140 }, 4141 clearToolbar = function(trigger){ 4142 var sdata={}, j=0, nm; 4143 trigger = (typeof trigger !== 'boolean') ? true : trigger; 4144 $.each($t.p.colModel,function(){ 4145 var v, $elem = $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv); 4146 if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; } 4147 nm = this.index || this.name; 4148 switch (this.stype) { 4149 case 'select' : 4150 $elem.find("option").each(function (i){ 4151 if(i===0) { this.selected = true; } 4152 if ($(this).val() === v) { 4153 this.selected = true; 4154 return false; 4155 } 4156 }); 4157 if ( v !== undefined ) { 4158 // post the key and not the text 4159 sdata[nm] = v; 4160 j++; 4161 } else { 4162 try { 4163 delete $t.p.postData[nm]; 4164 } catch(e) {} 4165 } 4166 break; 4167 case 'text': 4168 $elem.val(v || ""); 4169 if(v !== undefined) { 4170 sdata[nm] = v; 4171 j++; 4172 } else { 4173 try { 4174 delete $t.p.postData[nm]; 4175 } catch (y){} 4176 } 4177 break; 4178 case 'custom': 4179 if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN") { 4180 this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "set", v || ""); 4181 } 4182 break; 4183 } 4184 }); 4185 var sd = j>0 ? true : false; 4186 $t.p.resetsearch = true; 4187 if(p.stringResult === true || $t.p.datatype === "local") { 4188 var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":["; 4189 var gi=0; 4190 $.each(sdata,function(i,n){ 4191 if (gi > 0) {ruleGroup += ",";} 4192 ruleGroup += "{\"field\":\"" + i + "\","; 4193 ruleGroup += "\"op\":\"" + "eq" + "\","; 4194 n+=""; 4195 ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}"; 4196 gi++; 4197 }); 4198 ruleGroup += "]}"; 4199 $.extend($t.p.postData,{filters:ruleGroup}); 4200 $.each(['searchField', 'searchString', 'searchOper'], function(i, n){ 4201 if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];} 4202 }); 4203 } else { 4204 $.extend($t.p.postData,sdata); 4205 } 4206 var saveurl; 4207 if($t.p.searchurl) { 4208 saveurl = $t.p.url; 4209 $($t).jqGrid("setGridParam",{url:$t.p.searchurl}); 4210 } 4211 var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false; 4212 if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);} 4213 if(!bcv) { 4214 if(trigger) { 4215 $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); 4216 } 4217 } 4218 if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});} 4219 $($t).triggerHandler("jqGridToolbarAfterClear"); 4220 if($.isFunction(p.afterClear)){p.afterClear();} 4221 }, 4222 toggleToolbar = function(){ 4223 var trow = $("tr.ui-search-toolbar",$t.grid.hDiv), 4224 trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar",$t.grid.fhDiv) : false;
4225 if(trow.css("display") === 'none') { 4226 trow.show(); 4227 if(trow2) { 4228 trow2.show(); 4229 } 4230 } else { 4231 trow.hide(); 4232 if(trow2) { 4233 trow2.hide(); 4234 } 4235 } 4236 }, 4237 buildRuleMenu = function( elem, left, top ){ 4238 $("#sopt_menu").remove(); 4239 4240 left=parseInt(left,10); 4241 top=parseInt(top,10) + 18; 4242 4243 var fs = $('.ui-jqgrid-view').css('font-size') || '11px'; 4244 var str = '<ul id="sopt_menu" class="ui-search-menu" role="menu" tabindex="0" style="font-size:'+fs+';left:'+left+'px;top:'+top+'px;">', 4245 selected = $(elem).attr("soper"), selclass, 4246 aoprs = [], ina; 4247 var i=0, nm =$(elem).attr("colname"),len = $t.p.colModel.length; 4248 while(i<len) { 4249 if($t.p.colModel[i].name === nm) { 4250 break; 4251 } 4252 i++; 4253 } 4254 var cm = $t.p.colModel[i], options = $.extend({}, cm.searchoptions); 4255 if(!options.sopt) { 4256 options.sopt = []; 4257 options.sopt[0]= cm.stype==='select' ? 'eq' : p.defaultSearch; 4258 } 4259 $.each(p.odata, function() { aoprs.push(this.oper); }); 4260 for ( i = 0 ; i < options.sopt.length; i++) { 4261 ina = $.inArray(options.sopt[i],aoprs); 4262 if(ina !== -1) { 4263 selclass = selected === p.odata[ina].oper ? "ui-state-highlight" : ""; 4264 str += '<li class="ui-menu-item '+selclass+'" role="presentation"><a class="ui-corner-all g-menu-item" tabindex="0" role="menuitem" value="'+p.odata[ina].oper+'" oper="'+p.operands[p.odata[ina].oper]+'"><table cellspacing="0" cellpadding="0" border="0"><tr><td width="25px">'+p.operands[p.odata[ina].oper]+'</td><td>'+ p.odata[ina].text+'</td></tr></table></a></li>'; 4265 } 4266 } 4267 str += "</ul>"; 4268 $('body').append(str); 4269 $("#sopt_menu").addClass("ui-menu ui-widget ui-widget-content ui-corner-all"); 4270 $("#sopt_menu > li > a").hover( 4271 function(){ $(this).addClass("ui-state-hover"); }, 4272 function(){ $(this).removeClass("ui-state-hover"); } 4273 ).click(function( e ){ 4274 var v = $(this).attr("value"), 4275 oper = $(this).attr("oper"); 4276 $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]); 4277 $("#sopt_menu").hide(); 4278 $(elem).text(oper).attr("soper",v); 4279 if(p.autosearch===true){ 4280 var inpelm = $(elem).parent().next().children()[0]; 4281 if( $(inpelm).val() || v==="nu" || v ==="nn") { 4282 triggerToolbar(); 4283 } 4284 } 4285 }); 4286 }; 4287 // create the row 4288 var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>"); 4289 var timeoutHnd; 4290 $.each($t.p.colModel,function(ci){ 4291 var cm=this, soptions, surl, self, select = "", sot="=", so, i, 4292 th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>"), 4293 thd = $("<div style='position:relative;height:auto;padding-right:0.3em;padding-left:0.3em;'></div>"), 4294 stbl = $("<table class='ui-search-table' cellspacing='0'><tr><td class='ui-search-oper'></td><td class='ui-search-input'></td><td class='ui-search-clear'></td></tr></table>"); 4295 if(this.hidden===true) { $(th).css("display","none");} 4296 this.search = this.search === false ? false : true; 4297 if(this.stype === undefined) {this.stype='text';} 4298 soptions = $.extend({},this.searchoptions || {}); 4299 if(this.search){ 4300 if(p.searchOperators) { 4301 so = (soptions.sopt) ? soptions.sopt[0] : cm.stype==='select' ? 'eq' : p.defaultSearch; 4302 for(i = 0;i<p.odata.length;i++) { 4303 if(p.odata[i].oper === so) { 4304 sot = p.operands[so] || ""; 4305 break; 4306 } 4307 } 4308 var st = soptions.searchtitle != null ? soptions.searchtitle : p.operandTitle; 4309 select = "<a title='"+st+"' style='padding-right: 0.5em;' soper='"+so+"' class='soptclass' colname='"+this.name+"'>"+sot+"</a>"; 4310 } 4311 $("td:eq(0)",stbl).attr("colindex",ci).append(select); 4312 if(soptions.clearSearch === undefined) { 4313 soptions.clearSearch = true; 4314 } 4315 if(soptions.clearSearch) { 4316 var csv = p.resetTitle || 'Clear Search Value'; 4317 $("td:eq(2)",stbl).append("<a title='"+csv+"' style='padding-right: 0.3em;padding-left: 0.3em;' class='clearsearchclass'>"+p.resetIcon+"</a>"); 4318 } else { 4319 $("td:eq(2)", stbl).hide(); 4320 } 4321 switch (this.stype) 4322 { 4323 case "select": 4324 surl = this.surl || soptions.dataUrl; 4325 if(surl) { 4326 // data returned should have already constructed html select 4327 // primitive jQuery load 4328 self = thd; 4329 $(self).append(stbl); 4330 $.ajax($.extend({ 4331 url: surl, 4332 dataType: "html", 4333 success: function(res) { 4334 if(soptions.buildSelect !== undefined) { 4335 var d = soptions.buildSelect(res); 4336 if (d) { 4337 $("td:eq(1)",stbl).append(d); 4338 } 4339 } else { 4340 $("td:eq(1)",stbl).append(res); 4341 } 4342 if(soptions.defaultValue !== undefined) { $("select",self).val(soptions.defaultValue); } 4343 $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name}); 4344 if(soptions.attr) {$("select",self).attr(soptions.attr);} 4345 $("select",self).css({width: "100%"}); 4346 // preserve autoserch 4347 $.jgrid.bindEv.call($t, $("select",self)[0], soptions); 4348 if(p.autosearch===true){ 4349 $("select",self).change(function(){ 4350 triggerToolbar(); 4351 return false;
4352 }); 4353 } 4354 res=null; 4355 } 4356 }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} )); 4357 } else { 4358 var oSv, sep, delim; 4359 if(cm.searchoptions) { 4360 oSv = cm.searchoptions.value === undefined ? "" : cm.searchoptions.value; 4361 sep = cm.searchoptions.separator === undefined ? ":" : cm.searchoptions.separator; 4362 delim = cm.searchoptions.delimiter === undefined ? ";" : cm.searchoptions.delimiter; 4363 } else if(cm.editoptions) { 4364 oSv = cm.editoptions.value === undefined ? "" : cm.editoptions.value; 4365 sep = cm.editoptions.separator === undefined ? ":" : cm.editoptions.separator; 4366 delim = cm.editoptions.delimiter === undefined ? ";" : cm.editoptions.delimiter; 4367 } 4368 if (oSv) { 4369 var elem = document.createElement("select"); 4370 elem.style.width = "100%"; 4371 $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name}); 4372 var sv, ov, key, k; 4373 if(typeof oSv === "string") { 4374 so = oSv.split(delim); 4375 for(k=0; k<so.length;k++){ 4376 sv = so[k].split(sep); 4377 ov = document.createElement("option"); 4378 ov.value = sv[0]; ov.innerHTML = sv[1]; 4379 elem.appendChild(ov); 4380 } 4381 } else if(typeof oSv === "object" ) { 4382 for (key in oSv) { 4383 if(oSv.hasOwnProperty(key)) { 4384 ov = document.createElement("option"); 4385 ov.value = key; ov.innerHTML = oSv[key]; 4386 elem.appendChild(ov); 4387 } 4388 } 4389 } 4390 if(soptions.defaultValue !== undefined) { $(elem).val(soptions.defaultValue); } 4391 if(soptions.attr) {$(elem).attr(soptions.attr);} 4392 $(thd).append(stbl); 4393 $.jgrid.bindEv.call($t, elem , soptions); 4394 $("td:eq(1)",stbl).append( elem ); 4395 if(p.autosearch===true){ 4396 $(elem).change(function(){ 4397 triggerToolbar(); 4398 return false; 4399 }); 4400 } 4401 } 4402 } 4403 break; 4404 case "text": 4405 var df = soptions.defaultValue !== undefined ? soptions.defaultValue: ""; 4406 4407 $("td:eq(1)",stbl).append("<input type='text' style='width:100%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>"); 4408 $(thd).append(stbl); 4409 4410 if(soptions.attr) {$("input",thd).attr(soptions.attr);} 4411 $.jgrid.bindEv.call($t, $("input",thd)[0], soptions); 4412 if(p.autosearch===true){ 4413 if(p.searchOnEnter) { 4414 $("input",thd).keypress(function(e){ 4415 var key = e.charCode || e.keyCode || 0; 4416 if(key === 13){ 4417 triggerToolbar(); 4418 return false; 4419 } 4420 return this; 4421 }); 4422 } else { 4423 $("input",thd).keydown(function(e){ 4424 var key = e.which; 4425 switch (key) { 4426 case 13: 4427 return false; 4428 case 9 : 4429 case 16: 4430 case 37: 4431 case 38: 4432 case 39: 4433 case 40: 4434 case 27: 4435 break; 4436 default : 4437 if(timeoutHnd) { clearTimeout(timeoutHnd); } 4438 timeoutHnd = setTimeout(function(){triggerToolbar();},500); 4439 } 4440 }); 4441 } 4442 } 4443 break; 4444 case "custom": 4445 $("td:eq(1)",stbl).append("<span style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"'/>"); 4446 $(thd).append(stbl); 4447 try { 4448 if($.isFunction(soptions.custom_element)) { 4449 var celm = soptions.custom_element.call($t,soptions.defaultValue !== undefined ? soptions.defaultValue: "",soptions); 4450 if(celm) { 4451 celm = $(celm).addClass("customelement"); 4452 $(thd).find(">span").append(celm); 4453 } else { 4454 throw "e2"; 4455 } 4456 } else { 4457 throw "e1"; 4458 } 4459 } catch (e) { 4460 if (e === "e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);} 4461 if (e === "e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);} 4462 else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); } 4463 } 4464 break; 4465 } 4466 } 4467 $(th).append(thd); 4468 $(tr).append(th); 4469 if(!p.searchOperators) { 4470 $("td:eq(0)",stbl).hide(); 4471 } 4472 }); 4473 $("table thead",$t.grid.hDiv).append(tr); 4474 if(p.searchOperators) { 4475 $(".soptclass",tr).click(function(e){ 4476 var offset = $(this).offset(), 4477 left = ( offset.left ), 4478 top = ( offset.top); 4479 buildRuleMenu(this, left, top ); 4480 e.stopPropagation(); 4481 }); 4482 $("body").on('click', function(e){ 4483 if(e.target.className !== "soptclass") { 4484 $("#sopt_menu").hide(); 4485 } 4486 }); 4487 } 4488 $(".clearsearchclass",tr).click(function(e){ 4489 var ptr = $(this).parents("tr:first"), 4490 coli = parseInt($("td.ui-search-oper", ptr).attr('colindex'),10), 4491 sval = $.extend({},$t.p.colModel[coli].searchoptions || {}), 4492 dval = sval.defaultValue ? sval.defaultValue : ""; 4493 if($t.p.colModel[coli].stype === "select") { 4494 if(dval) { 4495 $("td.ui-search-input select", ptr).val( dval ); 4496 } else { 4497 $("td.ui-search-input select", ptr)[0].selectedIndex = 0; 4498 } 4499 } else { 4500 $("td.ui-search-input input", ptr).val( dval ); 4501 } 4502 // ToDo custom search type 4503 if(p.autosearch===true){ 4504 triggerToolbar(); 4505 } 4506 4507 }); 4508 this.ftoolbar = true; 4509 this.triggerToolbar = triggerToolbar; 4510 this.clearToolbar = clearToolbar; 4511 this.toggleToolbar = toggleToolbar; 4512 }); 4513 }, 4514 destroyFilterToolbar: function () { 4515 return this.each(function () { 4516 if (!this.ftoolbar) { 4517 return; 4518 } 4519 this.triggerToolbar = null; 4520 this.clearToolbar = null; 4521 this.toggleToolbar = null; 4522 this.ftoolbar = false;
4523 $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove(); 4524 }); 4525 }, 4526 destroyGroupHeader : function(nullHeader) 4527 { 4528 if(nullHeader === undefined) { 4529 nullHeader = true; 4530 } 4531 return this.each(function() 4532 { 4533 var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid, 4534 thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc; 4535 if(!grid) { return; } 4536 4537 $(this).unbind('.setGroupHeaders'); 4538 $tr = $("<tr>", {role: "rowheader"}).addClass("ui-jqgrid-labels"); 4539 headers = grid.headers; 4540 for (i = 0, l = headers.length; i < l; i++) { 4541 hc = cm[i].hidden ? "none" : ""; 4542 $th = $(headers[i].el) 4543 .width(headers[i].width) 4544 .css('display',hc); 4545 try { 4546 $th.removeAttr("rowSpan"); 4547 } catch (rs) { 4548 //IE 6/7 4549 $th.attr("rowSpan",1); 4550 } 4551 $tr.append($th); 4552 $resizing = $th.children("span.ui-jqgrid-resize"); 4553 if ($resizing.length>0) {// resizable column 4554 $resizing[0].style.height = ""; 4555 } 4556 $th.children("div")[0].style.top = ""; 4557 } 4558 $(thead).children('tr.ui-jqgrid-labels').remove(); 4559 $(thead).prepend($tr); 4560 4561 if(nullHeader === true) { 4562 $($t).jqGrid('setGridParam',{ 'groupHeader': null}); 4563 } 4564 }); 4565 }, 4566 setGroupHeaders : function ( o ) { 4567 o = $.extend({ 4568 useColSpanStyle : false, 4569 groupHeaders: [] 4570 },o || {}); 4571 return this.each(function(){ 4572 this.p.groupHeader = o; 4573 var ts = this, 4574 i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle, 4575 iCol, 4576 cghi, 4577 //startColumnName, 4578 numberOfColumns, 4579 titleText, 4580 cVisibleColumns, 4581 colModel = ts.p.colModel, 4582 cml = colModel.length, 4583 ths = ts.grid.headers, 4584 $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv), 4585 $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"), 4586 $thead = $htable.children("thead"), 4587 $theadInTable, 4588 $firstHeaderRow = $htable.find(".jqg-first-row-header"); 4589 if($firstHeaderRow[0] === undefined) { 4590 $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto"); 4591 } else { 4592 $firstHeaderRow.empty(); 4593 } 4594 var $firstRow, 4595 inColumnHeader = function (text, columnHeaders) { 4596 var length = columnHeaders.length, i; 4597 for (i = 0; i < length; i++) { 4598 if (columnHeaders[i].startColumnName === text) { 4599 return i; 4600 } 4601 } 4602 return -1; 4603 }; 4604 4605 $(ts).prepend($thead); 4606 $tr = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header"); 4607 for (i = 0; i < cml; i++) { 4608 th = ths[i].el; 4609 $th = $(th); 4610 cmi = colModel[i]; 4611 // build the next cell for the first header row 4612 thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')}; 4613 $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow); 4614 4615 th.style.width = ""; // remove unneeded style 4616 iCol = inColumnHeader(cmi.name, o.groupHeaders); 4617 if (iCol >= 0) { 4618 cghi = o.groupHeaders[iCol]; 4619 numberOfColumns = cghi.numberOfColumns; 4620 titleText = cghi.titleText; 4621 4622 // caclulate the number of visible columns from the next numberOfColumns columns 4623 for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) { 4624 if (!colModel[i + iCol].hidden) { 4625 cVisibleColumns++; 4626 } 4627 } 4628 4629 // The next numberOfColumns headers will be moved in the next row 4630 // in the current row will be placed the new column header with the titleText. 4631 // The text will be over the cVisibleColumns columns 4632 $colHeader = $('<th>').attr({role: "columnheader"}) 4633 .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction) 4634 .css({'height':'22px', 'border-top': '0 none'}) 4635 .html(titleText); 4636 if(cVisibleColumns > 0) { 4637 $colHeader.attr("colspan", String(cVisibleColumns)); 4638 } 4639 if (ts.p.headertitles) { 4640 $colHeader.attr("title", $colHeader.text()); 4641 } 4642 // hide if not a visible cols 4643 if( cVisibleColumns === 0) { 4644 $colHeader.hide(); 4645 } 4646 4647 $th.before($colHeader); // insert new column header before the current 4648 $tr.append(th); // move the current header in the next row 4649 4650 // set the coumter of headers which will be moved in the next row 4651 skip = numberOfColumns - 1; 4652 } else { 4653 if (skip === 0) { 4654 if (o.useColSpanStyle) { 4655 // expand the header height to two rows 4656 $th.attr("rowspan", "2"); 4657 } else { 4658 $('<th>', {role: "columnheader"}) 4659 .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction) 4660 .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0 none'}) 4661 .insertBefore($th); 4662 $tr.append(th); 4663 } 4664 } else { 4665 // move the header to the next row 4666 //$th.css({"padding-top": "2px", height: "19px"}); 4667 $tr.append(th); 4668 skip--; 4669 } 4670 } 4671 } 4672 $theadInTable = $(ts).children("thead"); 4673 $theadInTable.prepend($firstHeaderRow); 4674 $tr.insertAfter($trLabels); 4675 $htable.append($theadInTable); 4676 4677 if (o.useColSpanStyle) { 4678 // Increase the height of resizing span of visible headers 4679 $htable.find("span.ui-jqgrid-resize").each(function () { 4680 var $parent = $(this).parent(); 4681 if ($parent.is(":visible")) { 4682 this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;'; 4683 } 4684 }); 4685 4686 // Set position of the sortable div (the main lable) 4687 // with the column header text to the middle of the cell. 4688 // One should not do this for hidden headers. 4689 $htable.find("div.ui-jqgrid-sortable").each(function () { 4690 var $ts = $(this), $parent = $ts.parent(); 4691 if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) { 4692 $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px'); 4693 } 4694 }); 4695 } 4696 4697 $firstRow = $theadInTable.find("tr.jqg-first-row-header"); 4698 $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) { 4699 $firstRow.find('th').eq(idx).width(nw); 4700 }); 4701 }); 4702 }, 4703 setFrozenColumns : function () { 4704 return this.each(function() { 4705 if ( !this.grid ) {return;} 4706 var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false; 4707 // TODO treeGrid and grouping Support 4708 if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll ) 4709 { 4710 return; 4711 } 4712 if($t.p.rownumbers) { i++; } 4713 if($t.p.multiselect) { i++; } 4714 4715 // get the max index of frozen col 4716 while(i<len) 4717 { 4718 // from left, no breaking frozen 4719 if(cm[i].frozen === true) 4720 { 4721 frozen = true; 4722 maxfrozen = i; 4723 } else { 4724 break; 4725 } 4726 i++; 4727 } 4728 if( maxfrozen>=0 && frozen) { 4729 var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0, 4730 hth = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height(); 4731 //headers 4732 if($t.p.toppager) { 4733 top = top + $($t.grid.topDiv).outerHeight(); 4734 } 4735 if($t.p.toolbar[0] === true) { 4736 if($t.p.toolbar[1] !== "bottom") { 4737 top = top + $($t.grid.uDiv).outerHeight(); 4738 } 4739 }
4740 $t.grid.fhDiv = $('<div style="position:absolute;left:0px;top:'+top+'px;height:'+hth+'px;" class="frozen-div ui-state-default ui-jqgrid-hdiv"></div>'); 4741 $t.grid.fbDiv = $('<div style="position:absolute;left:0px;top:'+(parseInt(top,10)+parseInt(hth,10) + 1)+'px;overflow-y:hidden" class="frozen-bdiv ui-jqgrid-bdiv"></div>'); 4742 $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv); 4743 var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true); 4744 // groupheader support - only if useColSpanstyle is false 4745 if($t.p.groupHeader) { 4746 $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){ 4747 $("th:gt("+maxfrozen+")",this).remove(); 4748 }); 4749 var swapfroz = -1, fdel = -1, cs, rs; 4750 $("tr.jqg-second-row-header th", htbl).each(function(){ 4751 cs= parseInt($(this).attr("colspan"),10); 4752 rs= parseInt($(this).attr("rowspan"),10); 4753 if(rs) { 4754 swapfroz++; 4755 fdel++; 4756 } 4757 if(cs) { 4758 swapfroz = swapfroz+cs; 4759 fdel++; 4760 } 4761 if(swapfroz === maxfrozen) { 4762 return false; 4763 } 4764 }); 4765 if(swapfroz !== maxfrozen) { 4766 fdel = maxfrozen; 4767 } 4768 $("tr.jqg-second-row-header", htbl).each(function(){ 4769 $("th:gt("+fdel+")",this).remove(); 4770 }); 4771 } else { 4772 $("tr",htbl).each(function(){ 4773 $("th:gt("+maxfrozen+")",this).remove(); 4774 }); 4775 } 4776 $(htbl).width(1); 4777 // resizing stuff 4778 $($t.grid.fhDiv).append(htbl) 4779 .mousemove(function (e) { 4780 if($t.grid.resizing){ $t.grid.dragMove(e);return false; } 4781 }); 4782 $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) { 4783 var rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv); 4784 $("th:eq("+index+")",rhth).width( w ); 4785 var btd = $(".ui-jqgrid-btable",$t.grid.fbDiv); 4786 $("tr:first td:eq("+index+")",btd).width( w ); 4787 }); 4788 // sorting stuff 4789 $($t).bind('jqGridSortCol.setFrozenColumns', function (e, index, idxcol) { 4790 4791 var previousSelectedTh = $("tr.ui-jqgrid-labels:last th:eq("+$t.p.lastsort+")",$t.grid.fhDiv), newSelectedTh = $("tr.ui-jqgrid-labels:last th:eq("+idxcol+")",$t.grid.fhDiv); 4792 4793 $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled'); 4794 $(previousSelectedTh).attr("aria-selected","false"); 4795 $("span.ui-icon-"+$t.p.sortorder,newSelectedTh).removeClass('ui-state-disabled'); 4796 $(newSelectedTh).attr("aria-selected","true"); 4797 if(!$t.p.viewsortcols[0]) { 4798 if($t.p.lastsort !== idxcol) { 4799 $("span.s-ico",previousSelectedTh).hide(); 4800 $("span.s-ico",newSelectedTh).show(); 4801 } 4802 } 4803 }); 4804 4805 // data stuff 4806 //TODO support for setRowData 4807 $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv); 4808 $($t.grid.bDiv).scroll(function () { 4809 $($t.grid.fbDiv).scrollTop($(this).scrollTop()); 4810 }); 4811 if($t.p.hoverrows === true) { 4812 $("#"+$.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout'); 4813 } 4814 $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () { 4815 $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove(); 4816 $($t.grid.fbDiv).height($($t.grid.bDiv).height()-16); 4817 var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true); 4818 $("tr[role=row]",btbl).each(function(){ 4819 $("td[role=gridcell]:gt("+maxfrozen+")",this).remove(); 4820 }); 4821 4822 $(btbl).width(1).attr("id",$t.p.id+"_frozen"); 4823 $($t.grid.fbDiv).append(btbl); 4824 if($t.p.hoverrows === true) { 4825 $("tr.jqgrow", btbl).hover( 4826 function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass("ui-state-hover"); }, 4827 function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass("ui-state-hover"); } 4828 ); 4829 $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover( 4830 function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass("ui-state-hover");}, 4831 function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass("ui-state-hover"); } 4832 ); 4833 } 4834 btbl=null; 4835 }); 4836 if(!$t.grid.hDiv.loading) { 4837 $($t).triggerHandler("jqGridAfterGridComplete"); 4838 } 4839 $t.p.frozenColumns = true; 4840 } 4841 }); 4842 }, 4843 destroyFrozenColumns : function() { 4844 return this.each(function() { 4845 if ( !this.grid ) {return;} 4846 if(this.p.frozenColumns === true) { 4847 var $t = this; 4848 $($t.grid.fhDiv).remove(); 4849 $($t.grid.fbDiv).remove(); 4850 $t.grid.fhDiv = null; $t.grid.fbDiv=null; 4851 $(this).unbind('.setFrozenColumns'); 4852 if($t.p.hoverrows === true) { 4853 var ptr; 4854 $("#"+$.jgrid.jqID($t.p.id)).bind('mouseover',function(e) { 4855 ptr = $(e.target).closest("tr.jqgrow"); 4856 if($(ptr).attr("class") !== "ui-subgrid") { 4857 $(ptr).addClass("ui-state-hover"); 4858 } 4859 }).bind('mouseout',function(e) { 4860 ptr = $(e.target).closest("tr.jqgrow"); 4861 $(ptr).removeClass("ui-state-hover"); 4862 }); 4863 } 4864 this.p.frozenColumns = false;
4865 } 4866 }); 4867 } 4868}); 4869})(jQuery); 4870/* 4871 * jqModal - Minimalist Modaling with jQuery 4872 * (http://dev.iceburg.net/jquery/jqmodal/) 4873 * 4874 * Copyright (c) 2007,2008 Brice Burgess <[email protected]> 4875 * Dual licensed under the MIT and GPL licenses: 4876 * http://www.opensource.org/licenses/mit-license.php 4877 * http://www.gnu.org/licenses/gpl.html 4878 * 4879 * $Version: 07/06/2008 +r13 4880 */ 4881(function($) { 4882$.fn.jqm=function(o){ 4883var p={ 4884overlay: 50, 4885closeoverlay : true, 4886overlayClass: 'jqmOverlay', 4887closeClass: 'jqmClose', 4888trigger: '.jqModal', 4889ajax: F, 4890ajaxText: '', 4891target: F, 4892modal: F, 4893toTop: F, 4894onShow: F, 4895onHide: F, 4896onLoad: F 4897}; 4898return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s; 4899H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s}; 4900if(p.trigger)$(this).jqmAddTrigger(p.trigger); 4901});}; 4902 4903$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');}; 4904$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');}; 4905$.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});}; 4906$.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});}; 4907 4908$.jqm = { 4909hash:{}, 4910open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index')));z=(z>0)?z:3000;var o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z); 4911 if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);} 4912 else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);} 4913 else o=F; 4914 4915 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F; 4916 4917 if(c.ajax) {var r=c.target||h.w,u=c.ajax;r=(typeof r == 'string')?$(r,h.w):$(r);u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u; 4918 r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});} 4919 else if(cc)h.w.jqmAddClose($(cc,h.w)); 4920 4921 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o); 4922 (c.onShow)?c.onShow(h):h.w.show();e(h);return F; 4923}, 4924close:function(s){var h=H[s];if(!h.a)return F;h.a=F; 4925 if(A[0]){A.pop();if(!A[0])L('unbind');} 4926 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove(); 4927 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F; 4928}, 4929params:{}}; 4930var s=0,H=$.jqm.hash,A=[],F=false, 4931e=function(h){f(h);}, 4932f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}}, 4933L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);}, 4934m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r){$('.jqmID'+h.s).each(function(){var $self=$(this),offset=$self.offset();if(offset.top<=e.pageY && e.pageY<=offset.top+$self.height() && offset.left<=e.pageX && e.pageX<=offset.left+$self.width()){r=false;return false;}});f(h);}return !r;}, 4935hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() { 4936 if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});}; 4937})(jQuery);/* 4938 * jqDnR - Minimalistic Drag'n'Resize for jQuery. 4939 * 4940 * Copyright (c) 2007 Brice Burgess <[email protected]>, http://www.iceburg.net 4941 * Licensed under the MIT License: 4942 * http://www.opensource.org/licenses/mit-license.php 4943 * 4944 * $Version: 2007.08.19 +r2 4945 */ 4946 4947(function($){ 4948$.fn.jqDrag=function(h){return i(this,h,'d');}; 4949$.fn.jqResize=function(h,ar){return i(this,h,'r',ar);}; 4950$.jqDnR={ 4951 dnr:{}, 4952 e:0, 4953 drag:function(v){ 4954 if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});} 4955 else { 4956 E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)}); 4957 if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});} 4958 } 4959 return false; 4960 }, 4961 stop:function(){ 4962 //E.css('opacity',M.o); 4963 $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop); 4964 } 4965}; 4966var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1, 4967i=function(e,h,k,aR){ 4968 return e.each(function(){ 4969 h=(h)?$(h,e):e; 4970 h.bind('mousedown',{e:e,k:k},function(v){ 4971 var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
4972 // attempt utilization of dimensions plugin to fix IE issues 4973 if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}} 4974 M={ 4975 X:p.left||f('left')||0, 4976 Y:p.top||f('top')||0, 4977 W:f('width')||E[0].scrollWidth||0, 4978 H:f('height')||E[0].scrollHeight||0, 4979 pX:v.pageX, 4980 pY:v.pageY, 4981 k:d.k 4982 //o:E.css('opacity') 4983 }; 4984 // also resize 4985 if(E1 && d.k != 'd'){ 4986 M1={ 4987 X:p.left||f1('left')||0, 4988 Y:p.top||f1('top')||0, 4989 W:E1[0].offsetWidth||f1('width')||0, 4990 H:E1[0].offsetHeight||f1('height')||0, 4991 pX:v.pageX, 4992 pY:v.pageY, 4993 k:d.k 4994 }; 4995 } else {M1 = false;} 4996 //E.css({opacity:0.8}); 4997 if($("input.hasDatepicker",E[0])[0]) { 4998 try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){} 4999 } 5000 $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop); 5001 return false; 5002 }); 5003 }); 5004}, 5005f=function(k){return parseInt(E.css(k),10)||false;}, 5006f1=function(k){return parseInt(E1.css(k),10)||false;}; 5007})(jQuery);/* 5008 The below work is licensed under Creative Commons GNU LGPL License. 5009 5010 Original work: 5011 5012 License: http://creativecommons.org/licenses/LGPL/2.1/ 5013 Author: Stefan Goessner/2006 5014 Web: http://goessner.net/ 5015 5016 Modifications made: 5017 5018 Version: 0.9-p5 5019 Description: Restructured code, JSLint validated (no strict whitespaces), 5020 added handling of empty arrays, empty strings, and int/floats values. 5021 Author: Michael Schøler/2008-01-29 5022 Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/ 5023 5024 Description: json2xml added support to convert functions as CDATA 5025 so it will be easy to write characters that cause some problems when convert 5026 Author: Tony Tomov 5027*/ 5028 5029/*global alert */ 5030var xmlJsonClass = { 5031 // Param "xml": Element or document DOM node. 5032 // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress. 5033 // Returns: JSON string 5034 xml2json: function(xml, tab) { 5035 if (xml.nodeType === 9) { 5036 // document node 5037 xml = xml.documentElement; 5038 } 5039 var nws = this.removeWhite(xml); 5040 var obj = this.toObj(nws); 5041 var json = this.toJson(obj, xml.nodeName, "\t"); 5042 return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}"; 5043 }, 5044 5045 // Param "o": JavaScript object 5046 // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress. 5047 // Returns: XML string 5048 json2xml: function(o, tab) { 5049 var toXml = function(v, name, ind) { 5050 var xml = ""; 5051 var i, n; 5052 if (v instanceof Array) { 5053 if (v.length === 0) { 5054 xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n"; 5055 } 5056 else { 5057 for (i = 0, n = v.length; i < n; i += 1) { 5058 var sXml = ind + toXml(v[i], name, ind+"\t") + "\n"; 5059 xml += sXml; 5060 } 5061 } 5062 } 5063 else if (typeof(v) === "object") { 5064 var hasChild = false; 5065 xml += ind + "<" + name; 5066 var m; 5067 for (m in v) if (v.hasOwnProperty(m)) { 5068 if (m.charAt(0) === "@") { 5069 xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\""; 5070 } 5071 else { 5072 hasChild = true; 5073 } 5074 } 5075 xml += hasChild ? ">" : "/>"; 5076 if (hasChild) { 5077 for (m in v) if (v.hasOwnProperty(m)) { 5078 if (m === "#text") { 5079 xml += v[m]; 5080 } 5081 else if (m === "#cdata") { 5082 xml += "<![CDATA[" + v[m] + "]]>"; 5083 } 5084 else if (m.charAt(0) !== "@") { 5085 xml += toXml(v[m], m, ind+"\t"); 5086 } 5087 } 5088 xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">"; 5089 } 5090 } 5091 else if (typeof(v) === "function") { 5092 xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">"; 5093 } 5094 else { 5095 if (v === undefined ) { v = ""; } 5096 if (v.toString() === "\"\"" || v.toString().length === 0) { 5097 xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">"; 5098 } 5099 else { 5100 xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">"; 5101 } 5102 } 5103 return xml; 5104 }; 5105 var xml = ""; 5106 var m; 5107 for (m in o) if (o.hasOwnProperty(m)) { 5108 xml += toXml(o[m], m, ""); 5109 } 5110 return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, ""); 5111 }, 5112 // Internal methods 5113 toObj: function(xml) { 5114 var o = {}; 5115 var FuncTest = /function/i; 5116 if (xml.nodeType === 1) { 5117 // element node .. 5118 if (xml.attributes.length) { 5119 // element with attributes .. 5120 var i; 5121 for (i = 0; i < xml.attributes.length; i += 1) { 5122 o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString(); 5123 } 5124 } 5125 if (xml.firstChild) { 5126 // element has child nodes .. 5127 var textChild = 0, cdataChild = 0, hasElementChild = false;
vendor: 4,427 bytes, lines 5128-5291
5128 var n; 5129 for (n = xml.firstChild; n; n = n.nextSibling) { 5130 if (n.nodeType === 1) { 5131 hasElementChild = true; 5132 } 5133 else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) { 5134 // non-whitespace text 5135 textChild += 1; 5136 } 5137 else if (n.nodeType === 4) { 5138 // cdata section node 5139 cdataChild += 1; 5140 } 5141 } 5142 if (hasElementChild) { 5143 if (textChild < 2 && cdataChild < 2) { 5144 // structured element with evtl. a single text or/and cdata node .. 5145 this.removeWhite(xml); 5146 for (n = xml.firstChild; n; n = n.nextSibling) { 5147 if (n.nodeType === 3) { 5148 // text node 5149 o["#text"] = this.escape(n.nodeValue); 5150 } 5151 else if (n.nodeType === 4) { 5152 // cdata node 5153 if (FuncTest.test(n.nodeValue)) { 5154 o[n.nodeName] = [o[n.nodeName], n.nodeValue]; 5155 } else { 5156 o["#cdata"] = this.escape(n.nodeValue); 5157 } 5158 } 5159 else if (o[n.nodeName]) { 5160 // multiple occurence of element .. 5161 if (o[n.nodeName] instanceof Array) { 5162 o[n.nodeName][o[n.nodeName].length] = this.toObj(n); 5163 } 5164 else { 5165 o[n.nodeName] = [o[n.nodeName], this.toObj(n)]; 5166 } 5167 } 5168 else { 5169 // first occurence of element .. 5170 o[n.nodeName] = this.toObj(n); 5171 } 5172 } 5173 } 5174 else { 5175 // mixed content 5176 if (!xml.attributes.length) { 5177 o = this.escape(this.innerXml(xml)); 5178 } 5179 else { 5180 o["#text"] = this.escape(this.innerXml(xml)); 5181 } 5182 } 5183 } 5184 else if (textChild) { 5185 // pure text 5186 if (!xml.attributes.length) { 5187 o = this.escape(this.innerXml(xml)); 5188 if (o === "__EMPTY_ARRAY_") { 5189 o = "[]"; 5190 } else if (o === "__EMPTY_STRING_") { 5191 o = ""; 5192 } 5193 } 5194 else { 5195 o["#text"] = this.escape(this.innerXml(xml)); 5196 } 5197 } 5198 else if (cdataChild) { 5199 // cdata 5200 if (cdataChild > 1) { 5201 o = this.escape(this.innerXml(xml)); 5202 } 5203 else { 5204 for (n = xml.firstChild; n; n = n.nextSibling) { 5205 if(FuncTest.test(xml.firstChild.nodeValue)) { 5206 o = xml.firstChild.nodeValue; 5207 break; 5208 } else { 5209 o["#cdata"] = this.escape(n.nodeValue); 5210 } 5211 } 5212 } 5213 } 5214 } 5215 if (!xml.attributes.length && !xml.firstChild) { 5216 o = null; 5217 } 5218 } 5219 else if (xml.nodeType === 9) { 5220 // document.node 5221 o = this.toObj(xml.documentElement); 5222 } 5223 else { 5224 alert("unhandled node type: " + xml.nodeType); 5225 } 5226 return o; 5227 }, 5228 toJson: function(o, name, ind, wellform) { 5229 if(wellform === undefined) wellform = true; 5230 var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n"; 5231 if(!wellform) { 5232 tab= ""; newline= ""; 5233 } 5234 5235 if (o === "[]") { 5236 json += (name ? ":[]" : "[]"); 5237 } 5238 else if (o instanceof Array) { 5239 var n, i, ar=[]; 5240 for (i = 0, n = o.length; i < n; i += 1) { 5241 ar[i] = this.toJson(o[i], "", ind + tab, wellform); 5242 } 5243 json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]"; 5244 } 5245 else if (o === null) { 5246 json += (name && ":") + "null"; 5247 } 5248 else if (typeof(o) === "object") { 5249 var arr = [], m; 5250 for (m in o) { 5251 if (o.hasOwnProperty(m)) { 5252 arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform); 5253 } 5254 } 5255 json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}"; 5256 } 5257 else if (typeof(o) === "string") { 5258 /* 5259 var objRegExp = /(^-?\d+\.?\d*$)/; 5260 var FuncTest = /function/i; 5261 var os = o.toString(); 5262 if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") { 5263 // int or float 5264 json += (name && ":") + "\"" +os + "\""; 5265 } 5266 else { 5267 */ 5268 json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\""; 5269 //} 5270 } 5271 else { 5272 json += (name && ":") + o.toString(); 5273 } 5274 return json; 5275 }, 5276 innerXml: function(node) { 5277 var s = ""; 5278 if ("innerHTML" in node) { 5279 s = node.innerHTML; 5280 } 5281 else { 5282 var asXml = function(n) { 5283 var s = "", i; 5284 if (n.nodeType === 1) { 5285 s += "<" + n.nodeName; 5286 for (i = 0; i < n.attributes.length; i += 1) { 5287 s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\""; 5288 } 5289 if (n.firstChild) { 5290 s += ">"; 5291 for (var c = n.firstChild; c;
5291 c = c.nextSibling) { 5292 s += asXml(c); 5293 } 5294 s += "</" + n.nodeName + ">"; 5295 } 5296 else { 5297 s += "/>"; 5298 } 5299 } 5300 else if (n.nodeType === 3) { 5301 s += n.nodeValue; 5302 } 5303 else if (n.nodeType === 4) { 5304 s += "<![CDATA[" + n.nodeValue + "]]>"; 5305 } 5306 return s; 5307 }; 5308 for (var c = node.firstChild; c; c = c.nextSibling) { 5309 s += asXml(c); 5310 } 5311 } 5312 return s; 5313 }, 5314 escape: function(txt) { 5315 return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r'); 5316 }, 5317 removeWhite: function(e) { 5318 e.normalize(); 5319 var n; 5320 for (n = e.firstChild; n; ) { 5321 if (n.nodeType === 3) { 5322 // text node 5323 if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) { 5324 // pure whitespace text node 5325 var nxt = n.nextSibling; 5326 e.removeChild(n); 5327 n = nxt; 5328 } 5329 else { 5330 n = n.nextSibling; 5331 } 5332 } 5333 else if (n.nodeType === 1) { 5334 // element node 5335 this.removeWhite(n); 5336 n = n.nextSibling; 5337 } 5338 else { 5339 // any other node 5340 n = n.nextSibling; 5341 } 5342 } 5343 return e; 5344 } 5345};/* 5346** 5347 * formatter for values but most of the values if for jqGrid 5348 * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion 5349 * we are trying to keep it as light as possible 5350 * Joshua Burnett [email protected] 5351 * http://www.greenbill.com 5352 * 5353 * Changes from Tony Tomov [email protected] 5354 * Dual licensed under the MIT and GPL licenses: 5355 * http://www.opensource.org/licenses/mit-license.php 5356 * http://www.gnu.org/licenses/gpl-2.0.html 5357 * 5358**/ 5359/*jshint eqeqeq:false */ 5360/*global jQuery */ 5361 5362(function($) { 5363"use strict"; 5364 $.fmatter = {}; 5365 //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column 5366 //example {id:1234,} 5367 $.extend($.fmatter,{ 5368 isBoolean : function(o) { 5369 return typeof o === 'boolean'; 5370 }, 5371 isObject : function(o) { 5372 return (o && (typeof o === 'object' || $.isFunction(o))) || false; 5373 }, 5374 isString : function(o) { 5375 return typeof o === 'string'; 5376 }, 5377 isNumber : function(o) { 5378 return typeof o === 'number' && isFinite(o); 5379 }, 5380 isValue : function (o) { 5381 return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o)); 5382 }, 5383 isEmpty : function(o) { 5384 if(!this.isString(o) && this.isValue(o)) { 5385 return false; 5386 } 5387 if (!this.isValue(o)){ 5388 return true; 5389 } 5390 o = $.trim(o).replace(/\ \;/ig,'').replace(/\ \;/ig,''); 5391 return o===""; 5392 } 5393 }); 5394 $.fn.fmatter = function(formatType, cellval, opts, rwd, act) { 5395 // build main options before element iteration 5396 var v=cellval; 5397 opts = $.extend({}, $.jgrid.formatter, opts); 5398 5399 try { 5400 v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act); 5401 } catch(fe){} 5402 return v; 5403 }; 5404 $.fmatter.util = { 5405 // Taken from YAHOO utils 5406 NumberFormat : function(nData,opts) { 5407 if(!$.fmatter.isNumber(nData)) { 5408 nData *= 1; 5409 } 5410 if($.fmatter.isNumber(nData)) { 5411 var bNegative = (nData < 0); 5412 var sOutput = String(nData); 5413 var sDecimalSeparator = opts.decimalSeparator || "."; 5414 var nDotIndex; 5415 if($.fmatter.isNumber(opts.decimalPlaces)) { 5416 // Round to the correct decimal place 5417 var nDecimalPlaces = opts.decimalPlaces; 5418 var nDecimal = Math.pow(10, nDecimalPlaces); 5419 sOutput = String(Math.round(nData*nDecimal)/nDecimal); 5420 nDotIndex = sOutput.lastIndexOf("."); 5421 if(nDecimalPlaces > 0) { 5422 // Add the decimal separator 5423 if(nDotIndex < 0) { 5424 sOutput += sDecimalSeparator; 5425 nDotIndex = sOutput.length-1; 5426 } 5427 // Replace the "." 5428 else if(sDecimalSeparator !== "."){ 5429 sOutput = sOutput.replace(".",sDecimalSeparator); 5430 } 5431 // Add missing zeros 5432 while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) { 5433 sOutput += "0"; 5434 } 5435 } 5436 } 5437 if(opts.thousandsSeparator) { 5438 var sThousandsSeparator = opts.thousandsSeparator; 5439 nDotIndex = sOutput.lastIndexOf(sDecimalSeparator); 5440 nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length; 5441 var sNewOutput = sOutput.substring(nDotIndex); 5442 var nCount = -1, i; 5443 for (i=nDotIndex; i>0; i--) { 5444 nCount++; 5445 if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) { 5446 sNewOutput = sThousandsSeparator + sNewOutput; 5447 } 5448 sNewOutput = sOutput.charAt(i-1) + sNewOutput; 5449 } 5450 sOutput = sNewOutput; 5451 } 5452 // Prepend prefix 5453 sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput; 5454 // Append suffix 5455 sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput; 5456 return sOutput; 5457 5458 } 5459 return nData; 5460 } 5461 }; 5462 $.fn.fmatter.defaultFormat = function(cellval, opts) { 5463 return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || " "; 5464 }; 5465 $.fn.fmatter.email = function(cellval, opts) { 5466 if(!$.fmatter.isEmpty(cellval)) { 5467 return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>"; 5468 } 5469 return $.fn.fmatter.defaultFormat(cellval,opts ); 5470 }; 5471 $.fn.fmatter.checkbox =function(cval, opts) { 5472 var op = $.extend({},opts.checkbox), ds; 5473 if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { 5474 op = $.extend({},op,opts.colModel.formatoptions); 5475 } 5476 if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";} 5477 if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);} 5478 cval=String(cval); 5479 cval=(cval+"").toLowerCase(); 5480 var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : ""; 5481 return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>"; 5482 }; 5483 $.fn.fmatter.link = function(cellval, opts) { 5484 var op = {target:opts.target}; 5485 var target = ""; 5486 if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { 5487 op = $.extend({},op,opts.colModel.formatoptions); 5488 } 5489 if(op.target) {target = 'target=' + op.target;} 5490 if(!$.fmatter.isEmpty(cellval)) { 5491 return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>"; 5492 } 5493 return $.fn.fmatter.defaultFormat(cellval,opts); 5494 }; 5495 $.fn.fmatter.showlink = function(cellval, opts) { 5496 var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName}, 5497 target = "", idUrl; 5498 if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { 5499 op = $.extend({},op,opts.colModel.formatoptions); 5500 } 5501 if(op.target) {target = 'target=' + op.target;} 5502 idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam; 5503 if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string 5504 return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>"; 5505 } 5506 return $.fn.fmatter.defaultFormat(cellval,opts); 5507 }; 5508 $.fn.fmatter.integer = function(cellval, opts) { 5509 var op = $.extend({},opts.integer); 5510 if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { 5511 op = $.extend({},op,opts.colModel.formatoptions); 5512 } 5513 if($.fmatter.isEmpty(cellval)) { 5514 return op.defaultValue; 5515 } 5516 return $.fmatter.util.NumberFormat(cellval,op); 5517 }; 5518 $.fn.fmatter.number = function (cellval, opts) { 5519 var op = $.extend({},opts.number); 5520 if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { 5521 op = $.extend({},op,opts.colModel.formatoptions); 5522 } 5523 if($.fmatter.isEmpty(cellval)) { 5524 return op.defaultValue; 5525 } 5526 return $.fmatter.util.NumberFormat(cellval,op); 5527 }; 5528 $.fn.fmatter.currency = function (cellval, opts) { 5529 var op = $.extend({},opts.currency); 5530 if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { 5531 op = $.extend({},op,opts.colModel.formatoptions); 5532 } 5533 if($.fmatter.isEmpty(cellval)) { 5534 return op.defaultValue; 5535 } 5536 return $.fmatter.util.NumberFormat(cellval,op); 5537 }; 5538 $.fn.fmatter.date = function (cellval, opts, rwd, act) { 5539 var op = $.extend({},opts.date); 5540 if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { 5541 op = $.extend({},op,opts.colModel.formatoptions); 5542 } 5543 if(!op.reformatAfterEdit && act === 'edit'){ 5544 return $.fn.fmatter.defaultFormat(cellval, opts); 5545 } 5546 if(!$.fmatter.isEmpty(cellval)) { 5547 return $.jgrid.parseDate(op.srcformat,cellval,op.newformat,op); 5548 } 5549 return $.fn.fmatter.defaultFormat(cellval, opts); 5550 }; 5551 $.fn.fmatter.select = function (cellval,opts) { 5552 // jqGrid specific 5553 cellval = String(cellval); 5554 var oSelect = false, ret=[], sep, delim; 5555 if(opts.colModel.formatoptions !== undefined){
5556 oSelect= opts.colModel.formatoptions.value; 5557 sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator; 5558 delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter; 5559 } else if(opts.colModel.editoptions !== undefined){ 5560 oSelect= opts.colModel.editoptions.value; 5561 sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator; 5562 delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter; 5563 } 5564 if (oSelect) { 5565 var msl = (opts.colModel.editoptions != null && opts.colModel.editoptions.multiple === true) === true ? true : false, 5566 scell = [], sv; 5567 if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});} 5568 if ($.fmatter.isString(oSelect)) { 5569 // mybe here we can use some caching with care ???? 5570 var so = oSelect.split(delim), j=0, i; 5571 for(i=0; i<so.length;i++){ 5572 sv = so[i].split(sep); 5573 if(sv.length > 2 ) { 5574 sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep); 5575 } 5576 if(msl) { 5577 if($.inArray(sv[0],scell)>-1) { 5578 ret[j] = sv[1]; 5579 j++; 5580 } 5581 } else if($.trim(sv[0]) === $.trim(cellval)) { 5582 ret[0] = sv[1]; 5583 break; 5584 } 5585 } 5586 } else if($.fmatter.isObject(oSelect)) { 5587 // this is quicker 5588 if(msl) { 5589 ret = $.map(scell, function(n){ 5590 return oSelect[n]; 5591 }); 5592 } else { 5593 ret[0] = oSelect[cellval] || ""; 5594 } 5595 } 5596 } 5597 cellval = ret.join(", "); 5598 return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval; 5599 }; 5600 $.fn.fmatter.rowactions = function(act) { 5601 var $tr = $(this).closest("tr.jqgrow"), 5602 rid = $tr.attr("id"), 5603 $id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'), 5604 $grid = $("#"+$id), 5605 $t = $grid[0], 5606 p = $t.p, 5607 cm = p.colModel[$.jgrid.getCellIndex(this)], 5608 $actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(), 5609 op = { 5610 extraparam: {} 5611 }, 5612 saverow = function(rowid, res) { 5613 if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); } 5614 $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); 5615 $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); 5616 }, 5617 restorerow = function(rowid) { 5618 if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); } 5619 $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); 5620 $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); 5621 }; 5622 5623 if (cm.formatoptions !== undefined) { 5624 op = $.extend(op,cm.formatoptions); 5625 } 5626 if (p.editOptions !== undefined) { 5627 op.editOptions = p.editOptions; 5628 } 5629 if (p.delOptions !== undefined) { 5630 op.delOptions = p.delOptions; 5631 } 5632 if ($tr.hasClass("jqgrid-new-row")){ 5633 op.extraparam[p.prmNames.oper] = p.prmNames.addoper; 5634 } 5635 var actop = { 5636 keys: op.keys, 5637 oneditfunc: op.onEdit, 5638 successfunc: op.onSuccess, 5639 url: op.url, 5640 extraparam: op.extraparam, 5641 aftersavefunc: saverow, 5642 errorfunc: op.onError, 5643 afterrestorefunc: restorerow, 5644 restoreAfterError: op.restoreAfterError, 5645 mtype: op.mtype 5646 }; 5647 switch(act) 5648 { 5649 case 'edit': 5650 $grid.jqGrid('editRow', rid, actop); 5651 $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide(); 5652 $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show(); 5653 $grid.triggerHandler("jqGridAfterGridComplete"); 5654 break; 5655 case 'save': 5656 if ($grid.jqGrid('saveRow', rid, actop)) { 5657 $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); 5658 $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); 5659 $grid.triggerHandler("jqGridAfterGridComplete"); 5660 } 5661 break; 5662 case 'cancel' : 5663 $grid.jqGrid('restoreRow', rid, restorerow); 5664 $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); 5665 $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); 5666 $grid.triggerHandler("jqGridAfterGridComplete"); 5667 break; 5668 case 'del':
5669 $grid.jqGrid('delGridRow', rid, op.delOptions); 5670 break; 5671 case 'formedit': 5672 $grid.jqGrid('setSelection', rid); 5673 $grid.jqGrid('editGridRow', rid, op.editOptions); 5674 break; 5675 } 5676 }; 5677 $.fn.fmatter.actions = function(cellval,opts) { 5678 var op={keys:false, editbutton:true, delbutton:true, editformbutton: false}, 5679 rowid=opts.rowId, str="",ocl; 5680 if(opts.colModel.formatoptions !== undefined) { 5681 op = $.extend(op,opts.colModel.formatoptions); 5682 } 5683 if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";} 5684 if(op.editformbutton){ 5685 ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'formedit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; 5686 str += "<div title='"+$.jgrid.nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='ui-icon ui-icon-pencil'></span></div>"; 5687 } else if(op.editbutton){ 5688 ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'edit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover') "; 5689 str += "<div title='"+$.jgrid.nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='ui-icon ui-icon-pencil'></span></div>"; 5690 } 5691 if(op.delbutton) { 5692 ocl = "id='jDeleteButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'del'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; 5693 str += "<div title='"+$.jgrid.nav.deltitle+"' style='float:left;margin-left:5px;' class='ui-pg-div ui-inline-del' "+ocl+"><span class='ui-icon ui-icon-trash'></span></div>"; 5694 } 5695 ocl = "id='jSaveButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'save'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; 5696 str += "<div title='"+$.jgrid.edit.bSubmit+"' style='float:left;display:none' class='ui-pg-div ui-inline-save' "+ocl+"><span class='ui-icon ui-icon-disk'></span></div>"; 5697 ocl = "id='jCancelButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'cancel'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; 5698 str += "<div title='"+$.jgrid.edit.bCancel+"' style='float:left;display:none;margin-left:5px;' class='ui-pg-div ui-inline-cancel' "+ocl+"><span class='ui-icon ui-icon-cancel'></span></div>"; 5699 return "<div style='margin-left:8px;'>" + str + "</div>"; 5700 }; 5701 $.unformat = function (cellval,options,pos,cnt) { 5702 // specific for jqGrid only 5703 var ret, formatType = options.colModel.formatter, 5704 op =options.colModel.formatoptions || {}, sep, 5705 re = /([\.\*\_\'\(\)\{\}\+\?\\])/g, 5706 unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat); 5707 if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) { 5708 ret = unformatFunc.call(this, $(cellval).text(), options, cellval); 5709 } else if(formatType !== undefined && $.fmatter.isString(formatType) ) { 5710 var opts = $.jgrid.formatter || {}, stripTag; 5711 switch(formatType) { 5712 case 'integer' : 5713 op = $.extend({},opts.integer,op); 5714 sep = op.thousandsSeparator.replace(re,"\\$1"); 5715 stripTag = new RegExp(sep, "g"); 5716 ret = $(cellval).text().replace(stripTag,''); 5717 break; 5718 case 'number' : 5719 op = $.extend({},opts.number,op); 5720 sep = op.thousandsSeparator.replace(re,"\\$1"); 5721 stripTag = new RegExp(sep, "g"); 5722 ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.'); 5723 break; 5724 case 'currency': 5725 op = $.extend({},opts.currency,op); 5726 sep = op.thousandsSeparator.replace(re,"\\$1"); 5727 stripTag = new RegExp(sep, "g"); 5728 ret = $(cellval).text(); 5729 if (op.prefix && op.prefix.length) { 5730 ret = ret.substr(op.prefix.length); 5731 } 5732 if (op.suffix && op.suffix.length) { 5733 ret = ret.substr(0, ret.length - op.suffix.length); 5734 } 5735 ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.'); 5736 break; 5737 case 'checkbox': 5738 var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"]; 5739 ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1]; 5740 break; 5741 case 'select' : 5742 ret = $.unformat.select(cellval,options,pos,cnt); 5743 break; 5744 case 'actions': 5745 return ""; 5746 default: 5747 ret= $(cellval).text(); 5748 } 5749 } 5750 return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html()); 5751 }; 5752 $.unformat.select = function (cellval,options,pos,cnt) { 5753 // Spacial case when we have local data and perform a sort 5754 // cnt is set to true only in sortDataArray 5755 var ret = []; 5756 var cell = $(cellval).text(); 5757 if(cnt===true) {return cell;} 5758 var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions), 5759 sep = op.separator === undefined ? ":" : op.separator, 5760 delim = op.delimiter === undefined ? ";" : op.delimiter; 5761 5762 if(op.value){ 5763 var oSelect = op.value, 5764 msl = op.multiple === true ? true : false, 5765 scell = [], sv; 5766 if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});} 5767 if ($.fmatter.isString(oSelect)) { 5768 var so = oSelect.split(delim), j=0, i; 5769 for(i=0; i<so.length;i++){ 5770 sv = so[i].split(sep); 5771 if(sv.length > 2 ) {
5772 sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep); 5773 } 5774 if(msl) { 5775 if($.inArray(sv[1],scell)>-1) { 5776 ret[j] = sv[0]; 5777 j++; 5778 } 5779 } else if($.trim(sv[1]) === $.trim(cell)) { 5780 ret[0] = sv[0]; 5781 break; 5782 } 5783 } 5784 } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){ 5785 if(!msl) {scell[0] = cell;} 5786 ret = $.map(scell, function(n){ 5787 var rv; 5788 $.each(oSelect, function(i,val){ 5789 if (val === n) { 5790 rv = i; 5791 return false; 5792 } 5793 }); 5794 if( rv !== undefined ) {return rv;} 5795 }); 5796 } 5797 return ret.join(", "); 5798 } 5799 return cell || ""; 5800 }; 5801 $.unformat.date = function (cellval, opts) { 5802 var op = $.jgrid.formatter.date || {}; 5803 if(opts.formatoptions !== undefined) { 5804 op = $.extend({},op,opts.formatoptions); 5805 } 5806 if(!$.fmatter.isEmpty(cellval)) { 5807 return $.jgrid.parseDate(op.newformat,cellval,op.srcformat,op); 5808 } 5809 return $.fn.fmatter.defaultFormat(cellval, opts); 5810 }; 5811})(jQuery); 5812/*jshint eqeqeq:false */ 5813/*global jQuery */ 5814(function($){ 5815/* 5816 * jqGrid common function 5817 * Tony Tomov [email protected] 5818 * http://trirand.com/blog/ 5819 * Dual licensed under the MIT and GPL licenses: 5820 * http://www.opensource.org/licenses/mit-license.php 5821 * http://www.gnu.org/licenses/gpl-2.0.html 5822*/ 5823"use strict"; 5824$.extend($.jgrid,{ 5825// Modal functions 5826 showModal : function(h) { 5827 h.w.show(); 5828 }, 5829 closeModal : function(h) { 5830 h.w.hide().attr("aria-hidden","true"); 5831 if(h.o) {h.o.remove();} 5832 }, 5833 hideModal : function (selector,o) { 5834 o = $.extend({jqm : true, gb :''}, o || {}); 5835 if(o.onClose) { 5836 var oncret = o.gb && typeof o.gb === "string" && o.gb.substr(0,6) === "#gbox_" ? o.onClose.call($("#" + o.gb.substr(6))[0], selector) : o.onClose(selector); 5837 if (typeof oncret === 'boolean' && !oncret ) { return; } 5838 } 5839 if ($.fn.jqm && o.jqm === true) { 5840 $(selector).attr("aria-hidden","true").jqmHide(); 5841 } else { 5842 if(o.gb !== '') { 5843 try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){} 5844 } 5845 $(selector).hide().attr("aria-hidden","true"); 5846 } 5847 }, 5848//Helper functions 5849 findPos : function(obj) { 5850 var curleft = 0, curtop = 0; 5851 if (obj.offsetParent) { 5852 do { 5853 curleft += obj.offsetLeft; 5854 curtop += obj.offsetTop; 5855 } while (obj = obj.offsetParent); 5856 //do not change obj == obj.offsetParent 5857 } 5858 return [curleft,curtop]; 5859 }, 5860 createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) { 5861 p = $.extend(true, {}, $.jgrid.jqModal || {}, p); 5862 var mw = document.createElement('div'), rtlsup, self = this; 5863 css = $.extend({}, css || {}); 5864 rtlsup = $(p.gbox).attr("dir") === "rtl" ? true : false; 5865 mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog"; 5866 mw.id = aIDs.themodal; 5867 var mh = document.createElement('div'); 5868 mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"; 5869 mh.id = aIDs.modalhead; 5870 $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>"); 5871 var ahr= $("<a class='ui-jqdialog-titlebar-close ui-corner-all'></a>") 5872 .hover(function(){ahr.addClass('ui-state-hover');}, 5873 function(){ahr.removeClass('ui-state-hover');}) 5874 .append("<span class='ui-icon ui-icon-closethick'></span>"); 5875 $(mh).append(ahr); 5876 if(rtlsup) { 5877 mw.dir = "rtl";
5878 $(".ui-jqdialog-title",mh).css("float","right"); 5879 $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em"); 5880 } else { 5881 mw.dir = "ltr"; 5882 $(".ui-jqdialog-title",mh).css("float","left"); 5883 $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em"); 5884 } 5885 var mc = document.createElement('div'); 5886 $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent); 5887 $(mc).append(content); 5888 mw.appendChild(mc); 5889 $(mw).prepend(mh); 5890 if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog 5891 else if (typeof appendsel === "string") { 5892 $(appendsel).append(mw); 5893 } else {$(mw).insertBefore(insertSelector);} 5894 $(mw).css(css); 5895 if(p.jqModal === undefined) {p.jqModal = true;} // internal use 5896 var coord = {}; 5897 if ( $.fn.jqm && p.jqModal === true) { 5898 if(p.left ===0 && p.top===0 && p.overlay) { 5899 var pos = []; 5900 pos = $.jgrid.findPos(posSelector); 5901 p.left = pos[0] + 4; 5902 p.top = pos[1] + 4; 5903 } 5904 coord.top = p.top+"px"; 5905 coord.left = p.left; 5906 } else if(p.left !==0 || p.top!==0) { 5907 coord.left = p.left;
5908 coord.top = p.top+"px"; 5909 } 5910 $("a.ui-jqdialog-titlebar-close",mh).click(function(){ 5911 var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose; 5912 var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox; 5913 self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm}); 5914 return false; 5915 }); 5916 if (p.width === 0 || !p.width) {p.width = 300;} 5917 if(p.height === 0 || !p.height) {p.height =200;} 5918 if(!p.zIndex) { 5919 var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index"); 5920 if(parentZ) { 5921 p.zIndex = parseInt(parentZ,10)+2; 5922 } else { 5923 p.zIndex = 950; 5924 } 5925 } 5926 var rtlt = 0; 5927 if( rtlsup && coord.left && !appendsel) { 5928 rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do 5929 // just in case 5930 coord.left = parseInt(coord.left,10) + parseInt(rtlt,10); 5931 } 5932 if(coord.left) { coord.left += "px"; } 5933 $(mw).css($.extend({ 5934 width: isNaN(p.width) ? "auto": p.width+"px", 5935 height:isNaN(p.height) ? "auto" : p.height + "px", 5936 zIndex:p.zIndex, 5937 overflow: 'hidden' 5938 },coord)) 5939 .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"}); 5940 if(p.drag === undefined) { p.drag=true;} 5941 if(p.resize === undefined) {p.resize=true;} 5942 if (p.drag) { 5943 $(mh).css('cursor','move'); 5944 if($.fn.jqDrag) { 5945 $(mw).jqDrag(mh); 5946 } else { 5947 try { 5948 $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))}); 5949 } catch (e) {} 5950 } 5951 } 5952 if(p.resize) { 5953 if($.fn.jqResize) { 5954 $(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se'></div>"); 5955 $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false); 5956 } else { 5957 try { 5958 $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false}); 5959 } catch (r) {} 5960 } 5961 } 5962 if(p.closeOnEscape === true){ 5963 $(mw).keydown( function( e ) { 5964 if( e.which == 27 ) { 5965 var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose; 5966 self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:p.gbox,jqm:p.jqModal,onClose: cone}); 5967 } 5968 }); 5969 } 5970 }, 5971 viewModal : function (selector,o){ 5972 o = $.extend({ 5973 toTop: true, 5974 overlay: 10, 5975 modal: false, 5976 overlayClass : 'ui-widget-overlay', 5977 onShow: $.jgrid.showModal, 5978 onHide: $.jgrid.closeModal, 5979 gbox: '', 5980 jqm : true, 5981 jqM : true 5982 }, o || {}); 5983 if ($.fn.jqm && o.jqm === true) { 5984 if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); } 5985 else {$(selector).attr("aria-hidden","false").jqmShow();} 5986 } else { 5987 if(o.gbox !== '') { 5988 $(".jqgrid-overlay:first",o.gbox).show(); 5989 $(selector).data("gbox",o.gbox); 5990 } 5991 $(selector).show().attr("aria-hidden","false"); 5992 try{$(':input:visible',selector)[0].focus();}catch(_){} 5993 } 5994 }, 5995 info_dialog : function(caption, content,c_b, modalopt) { 5996 var mopt = { 5997 width:290, 5998 height:'auto', 5999 dataheight: 'auto', 6000 drag: true, 6001 resize: false, 6002 left:250, 6003 top:170, 6004 zIndex : 1000, 6005 jqModal : true, 6006 modal : false, 6007 closeOnEscape : true, 6008 align: 'center', 6009 buttonalign : 'center', 6010 buttons : [] 6011 // {text:'textbutt', id:"buttid", onClick : function(){...}} 6012 // if the id is not provided we set it like info_button_+ the index in the array - i.e info_button_0,info_button_1... 6013 }; 6014 $.extend(true, mopt, $.jgrid.jqModal || {}, {caption:"<b>"+caption+"</b>"}, modalopt || {}); 6015 var jm = mopt.jqModal, self = this; 6016 if($.fn.jqm && !jm) { jm = false; } 6017 // in case there is no jqModal 6018 var buttstr ="", i; 6019 if(mopt.buttons.length > 0) { 6020 for(i=0;i<mopt.buttons.length;i++) { 6021 if(mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_"+i; } 6022 buttstr += "<a id='"+mopt.buttons[i].id+"' class='fm-button ui-state-default ui-corner-all'>"+mopt.buttons[i].text+"</a>"; 6023 } 6024 } 6025 var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px", 6026 cn = "text-align:"+mopt.align+";"; 6027 var cnt = "<div id='info_id'>"; 6028 cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>"; 6029 cnt += c_b ? "<div class='ui-widget-content ui-helper-clearfix' style='text-align:"+mopt.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'><a id='closedialog' class='fm-button ui-state-default ui-corner-all'>"+c_b+"</a>"+buttstr+"</div>" : 6030 buttstr !== "" ? "<div class='ui-widget-content ui-helper-clearfix' style='text-align:"+mopt.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'>"+buttstr+"</div>" : ""; 6031 cnt += "</div>"; 6032 6033 try {
6034 if($("#info_dialog").attr("aria-hidden") === "false") { 6035 $.jgrid.hideModal("#info_dialog",{jqm:jm}); 6036 } 6037 $("#info_dialog").remove(); 6038 } catch (e){} 6039 $.jgrid.createModal({ 6040 themodal:'info_dialog', 6041 modalhead:'info_head', 6042 modalcontent:'info_content', 6043 scrollelm: 'infocnt'}, 6044 cnt, 6045 mopt, 6046 '','',true 6047 ); 6048 // attach onclick after inserting into the dom 6049 if(buttstr) { 6050 $.each(mopt.buttons,function(i){ 6051 $("#"+$.jgrid.jqID(this.id),"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;}); 6052 }); 6053 } 6054 $("#closedialog", "#info_id").click(function(){ 6055 self.hideModal("#info_dialog",{ 6056 jqm:jm, 6057 onClose: $("#info_dialog").data("onClose") || mopt.onClose, 6058 gb: $("#info_dialog").data("gbox") || mopt.gbox 6059 }); 6060 return false; 6061 }); 6062 $(".fm-button","#info_dialog").hover( 6063 function(){$(this).addClass('ui-state-hover');}, 6064 function(){$(this).removeClass('ui-state-hover');} 6065 ); 6066 if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); } 6067 $.jgrid.viewModal("#info_dialog",{ 6068 onHide: function(h) { 6069 h.w.hide().remove(); 6070 if(h.o) { h.o.remove(); } 6071 }, 6072 modal :mopt.modal, 6073 jqm:jm 6074 }); 6075 if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); } 6076 try{ $("#info_dialog").focus();} catch (m){} 6077 }, 6078 bindEv: function (el, opt) { 6079 var $t = this; 6080 if($.isFunction(opt.dataInit)) { 6081 opt.dataInit.call($t,el,opt); 6082 } 6083 if(opt.dataEvents) { 6084 $.each(opt.dataEvents, function() { 6085 if (this.data !== undefined) { 6086 $(el).bind(this.type, this.data, this.fn); 6087 } else { 6088 $(el).bind(this.type, this.fn); 6089 } 6090 }); 6091 } 6092 }, 6093// Form Functions 6094 createEl : function(eltype,options,vl,autowidth, ajaxso) { 6095 var elem = "", $t = this; 6096 function setAttributes(elm, atr, exl ) { 6097 var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value']; 6098 if(exl !== undefined && $.isArray(exl)) { 6099 $.merge(exclude, exl); 6100 } 6101 $.each(atr, function(key, value){ 6102 if($.inArray(key, exclude) === -1) { 6103 $(elm).attr(key,value); 6104 } 6105 }); 6106 if(!atr.hasOwnProperty('id')) { 6107 $(elm).attr('id', $.jgrid.randId()); 6108 } 6109 } 6110 switch (eltype) 6111 { 6112 case "textarea" : 6113 elem = document.createElement("textarea"); 6114 if(autowidth) { 6115 if(!options.cols) { $(elem).css({width:"98%"});} 6116 } else if (!options.cols) { options.cols = 20; } 6117 if(!options.rows) { options.rows = 2; } 6118 if(vl===' ' || vl===' ' || (vl.length===1 && vl.charCodeAt(0)===160)) {vl="";} 6119 elem.value = vl; 6120 setAttributes(elem, options); 6121 $(elem).attr({"role":"textbox","multiline":"true"}); 6122 break; 6123 case "checkbox" : //what code for simple checkbox 6124 elem = document.createElement("input"); 6125 elem.type = "checkbox"; 6126 if( !options.value ) { 6127 var vl1 = (vl+"").toLowerCase(); 6128 if(vl1.search(/(false|f|0|no|n|off|undefined)/i)<0 && vl1!=="") { 6129 elem.checked=true; 6130 elem.defaultChecked=true; 6131 elem.value = vl; 6132 } else { 6133 elem.value = "on"; 6134 } 6135 $(elem).attr("offval","off"); 6136 } else { 6137 var cbval = options.value.split(":"); 6138 if(vl === cbval[0]) { 6139 elem.checked=true; 6140 elem.defaultChecked=true; 6141 } 6142 elem.value = cbval[0]; 6143 $(elem).attr("offval",cbval[1]); 6144 } 6145 setAttributes(elem, options, ['value']); 6146 $(elem).attr("role","checkbox"); 6147 break; 6148 case "select" : 6149 elem = document.createElement("select"); 6150 elem.setAttribute("role","select"); 6151 var msl, ovm = []; 6152 if(options.multiple===true) { 6153 msl = true; 6154 elem.multiple="multiple"; 6155 $(elem).attr("aria-multiselectable","true"); 6156 } else { msl = false; } 6157 if(options.dataUrl !== undefined) { 6158 var rowid = null, postData = options.postData || ajaxso.postData; 6159 try { 6160 rowid = options.rowId; 6161 } catch(e) {} 6162 6163 if ($t.p && $t.p.idPrefix) { 6164 rowid = $.jgrid.stripPref($t.p.idPrefix, rowid); 6165 } 6166 $.ajax($.extend({ 6167 url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : options.dataUrl, 6168 type : "GET", 6169 dataType: "html", 6170 data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData, 6171 context: {elem:elem, options:options, vl:vl}, 6172 success: function(data){ 6173 var ovm = [], elem = this.elem, vl = this.vl, 6174 options = $.extend({},this.options), 6175 msl = options.multiple===true, 6176 a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t,data) : data; 6177 if(typeof a === 'string') { 6178 a = $( $.trim( a ) ).html(); 6179 } 6180 if(a) { 6181 $(elem).append(a); 6182 setAttributes(elem, options, postData ? ['postData'] : undefined ); 6183 if(options.size === undefined) { options.size = msl ? 3 : 1;} 6184 if(msl) { 6185 ovm = vl.split(","); 6186 ovm = $.map(ovm,function(n){return $.trim(n);}); 6187 } else { 6188 ovm[0] = $.trim(vl); 6189 } 6190 //$(elem).attr(options); 6191 setTimeout(function(){ 6192 $("option",elem).each(function(i){ 6193 //if(i===0) { this.selected = ""; } 6194 // fix IE8/IE7 problem with selecting of the first item on multiple=true 6195 if (i === 0 && elem.multiple) { this.selected = false; } 6196 $(this).attr("role","option"); 6197 if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) { 6198 this.selected= "selected"; 6199 } 6200 }); 6201 },0); 6202 } 6203 } 6204 },ajaxso || {})); 6205 } else if(options.value) { 6206 var i; 6207 if(options.size === undefined) { 6208 options.size = msl ? 3 : 1; 6209 } 6210 if(msl) { 6211 ovm = vl.split(","); 6212 ovm = $.map(ovm,function(n){return $.trim(n);}); 6213 } 6214 if(typeof options.value === 'function') { options.value = options.value(); } 6215 var so,sv, ov, 6216 sep = options.separator === undefined ? ":" : options.separator, 6217 delim = options.delimiter === undefined ? ";" : options.delimiter; 6218 if(typeof options.value === 'string') { 6219 so = options.value.split(delim); 6220 for(i=0; i<so.length;i++){ 6221 sv = so[i].split(sep); 6222 if(sv.length > 2 ) { 6223 sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep); 6224 } 6225 ov = document.createElement("option"); 6226 ov.setAttribute("role","option"); 6227 ov.value = sv[0]; ov.innerHTML = sv[1]; 6228 elem.appendChild(ov); 6229 if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) { ov.selected ="selected"; } 6230 if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";} 6231 } 6232 } else if (typeof options.value === 'object') { 6233 var oSv = options.value, key; 6234 for (key in oSv) { 6235 if (oSv.hasOwnProperty(key ) ){ 6236 ov = document.createElement("option"); 6237 ov.setAttribute("role","option"); 6238 ov.value = key; ov.innerHTML = oSv[key]; 6239 elem.appendChild(ov); 6240 if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl)) ) { ov.selected ="selected"; } 6241 if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; } 6242 } 6243 } 6244 } 6245 setAttributes(elem, options, ['value']); 6246 } 6247 break; 6248 case "text" : 6249 case "password" : 6250 case "button" : 6251 var role; 6252 if(eltype==="button") { role = "button"; } 6253 else { role = "textbox"; } 6254 elem = document.createElement("input"); 6255 elem.type = eltype; 6256 elem.value = vl; 6257 setAttributes(elem, options); 6258 if(eltype !== "button"){ 6259 if(autowidth) { 6260 if(!options.size) { $(elem).css({width:"98%"}); } 6261 } else if (!options.size) { options.size = 20; } 6262 } 6263 $(elem).attr("role",role); 6264 break; 6265 case "image" : 6266 case "file" : 6267 elem = document.createElement("input"); 6268 elem.type = eltype; 6269 setAttributes(elem, options); 6270 break; 6271 case "custom" : 6272 elem = document.createElement("span");
vendor: 8,760 bytes, lines 6273-6518
6273 try { 6274 if($.isFunction(options.custom_element)) { 6275 var celm = options.custom_element.call($t,vl,options); 6276 if(celm) { 6277 celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name}); 6278 $(elem).empty().append(celm); 6279 } else { 6280 throw "e2"; 6281 } 6282 } else { 6283 throw "e1"; 6284 } 6285 } catch (e) { 6286 if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);} 6287 if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);} 6288 else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); } 6289 } 6290 break; 6291 } 6292 return elem; 6293 }, 6294// Date Validation Javascript 6295 checkDate : function (format, date) { 6296 var daysInFebruary = function(year){ 6297 // February has 29 days in any year evenly divisible by four, 6298 // EXCEPT for centurial years which are not also divisible by 400. 6299 return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 ); 6300 }, 6301 tsp = {}, sep; 6302 format = format.toLowerCase(); 6303 //we search for /,-,. for the date separator 6304 if(format.indexOf("/") !== -1) { 6305 sep = "/"; 6306 } else if(format.indexOf("-") !== -1) { 6307 sep = "-"; 6308 } else if(format.indexOf(".") !== -1) { 6309 sep = "."; 6310 } else { 6311 sep = "/"; 6312 } 6313 format = format.split(sep); 6314 date = date.split(sep); 6315 if (date.length !== 3) { return false; } 6316 var j=-1,yln, dln=-1, mln=-1, i; 6317 for(i=0;i<format.length;i++){ 6318 var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10); 6319 tsp[format[i]] = dv; 6320 yln = format[i]; 6321 if(yln.indexOf("y") !== -1) { j=i; } 6322 if(yln.indexOf("m") !== -1) { mln=i; } 6323 if(yln.indexOf("d") !== -1) { dln=i; } 6324 } 6325 if (format[j] === "y" || format[j] === "yyyy") { 6326 yln=4; 6327 } else if(format[j] ==="yy"){ 6328 yln = 2; 6329 } else { 6330 yln = -1; 6331 } 6332 var daysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31], 6333 strDate; 6334 if (j === -1) { 6335 return false; 6336 } 6337 strDate = tsp[format[j]].toString(); 6338 if(yln === 2 && strDate.length === 1) {yln = 1;} 6339 if (strDate.length !== yln || (tsp[format[j]]===0 && date[j]!=="00")){ 6340 return false; 6341 } 6342 if(mln === -1) { 6343 return false; 6344 } 6345 strDate = tsp[format[mln]].toString(); 6346 if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){ 6347 return false; 6348 } 6349 if(dln === -1) { 6350 return false; 6351 } 6352 strDate = tsp[format[dln]].toString(); 6353 if (strDate.length<1 || tsp[format[dln]]<1 || tsp[format[dln]]>31 || (tsp[format[mln]]===2 && tsp[format[dln]]>daysInFebruary(tsp[format[j]])) || tsp[format[dln]] > daysInMonth[tsp[format[mln]]]){ 6354 return false; 6355 } 6356 return true; 6357 }, 6358 isEmpty : function(val) 6359 { 6360 if (val.match(/^\s+$/) || val === "") { 6361 return true; 6362 } 6363 return false; 6364 }, 6365 checkTime : function(time){ 6366 // checks only hh:ss (and optional am/pm) 6367 var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/,regs; 6368 if(!$.jgrid.isEmpty(time)) 6369 { 6370 regs = time.match(re); 6371 if(regs) { 6372 if(regs[3]) { 6373 if(regs[1] < 1 || regs[1] > 12) { return false; } 6374 } else { 6375 if(regs[1] > 23) { return false; } 6376 } 6377 if(regs[2] > 59) { 6378 return false; 6379 } 6380 } else { 6381 return false; 6382 } 6383 } 6384 return true; 6385 }, 6386 checkValues : function(val, valref, customobject, nam) { 6387 var edtrul,i, nm, dft, len, g = this, cm = g.p.colModel; 6388 if(customobject === undefined) { 6389 if(typeof valref==='string'){ 6390 for( i =0, len=cm.length;i<len; i++){ 6391 if(cm[i].name===valref) { 6392 edtrul = cm[i].editrules; 6393 valref = i; 6394 if(cm[i].formoptions != null) { nm = cm[i].formoptions.label; } 6395 break; 6396 } 6397 } 6398 } else if(valref >=0) { 6399 edtrul = cm[valref].editrules; 6400 } 6401 } else { 6402 edtrul = customobject; 6403 nm = nam===undefined ? "_" : nam; 6404 } 6405 if(edtrul) { 6406 if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label; } 6407 if(edtrul.required === true) { 6408 if( $.jgrid.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; } 6409 } 6410 // force required 6411 var rqfield = edtrul.required === false ? false : true; 6412 if(edtrul.number === true) { 6413 if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { 6414 if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; } 6415 } 6416 } 6417 if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) { 6418 if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];} 6419 } 6420 if(edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) { 6421 if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];} 6422 } 6423 var filter; 6424 if(edtrul.email === true) { 6425 if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { 6426 // taken from $ Validate plugin 6427 filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i; 6428 if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];} 6429 } 6430 } 6431 if(edtrul.integer === true) { 6432 if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { 6433 if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; } 6434 if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];} 6435 } 6436 } 6437 if(edtrul.date === true) { 6438 if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { 6439 if(cm[valref].formatoptions && cm[valref].formatoptions.newformat) { 6440 dft = cm[valref].formatoptions.newformat; 6441 if( $.jgrid.formatter.date.masks.hasOwnProperty(dft) ) { 6442 dft = $.jgrid.formatter.date.masks[dft]; 6443 } 6444 } else { 6445 dft = cm[valref].datefmt || "Y-m-d"; 6446 } 6447 if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; } 6448 } 6449 } 6450 if(edtrul.time === true) { 6451 if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { 6452 if(!$.jgrid.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; } 6453 } 6454 } 6455 if(edtrul.url === true) { 6456 if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { 6457 filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; 6458 if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];} 6459 } 6460 } 6461 if(edtrul.custom === true) { 6462 if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { 6463 if($.isFunction(edtrul.custom_func)) { 6464 var ret = edtrul.custom_func.call(g,val,nm,valref); 6465 return $.isArray(ret) ? ret : [false,$.jgrid.edit.msg.customarray,""]; 6466 } 6467 return [false,$.jgrid.edit.msg.customfcheck,""]; 6468 } 6469 } 6470 } 6471 return [true,"",""]; 6472 } 6473}); 6474})(jQuery); 6475/* 6476 * jqFilter jQuery jqGrid filter addon. 6477 * Copyright (c) 2011, Tony Tomov, [email protected] 6478 * Dual licensed under the MIT and GPL licenses 6479 * http://www.opensource.org/licenses/mit-license.php 6480 * http://www.gnu.org/licenses/gpl-2.0.html 6481 * 6482 * The work is inspired from this Stefan Pirvu 6483 * http://www.codeproject.com/KB/scripting/json-filtering.aspx 6484 * 6485 * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter: 6486 6487{ "groupOp": "AND", 6488 "groups" : [ 6489 { "groupOp": "OR", 6490 "rules": [ 6491 { "field": "name", "op": "eq", "data": "England" }, 6492 { "field": "id", "op": "le", "data": "5"} 6493 ] 6494 } 6495 ], 6496 "rules": [ 6497 { "field": "name", "op": "eq", "data": "Romania" }, 6498 { "field": "id", "op": "le", "data": "1"} 6499 ] 6500} 6501*/ 6502/*jshint eqeqeq:false, eqnull:true, devel:true */ 6503/*global jQuery */ 6504 6505(function ($) { 6506"use strict"; 6507 6508$.fn.jqFilter = function( arg ) { 6509 if (typeof arg === 'string') { 6510 6511 var fn = $.fn.jqFilter[arg]; 6512 if (!fn) { 6513 throw ("jqFilter - No such method: " + arg); 6514 } 6515 var args = $.makeArray(arguments).slice(1); 6516 return fn.apply(this,args); 6517 } 6518
6519 var p = $.extend(true,{ 6520 filter: null, 6521 columns: [], 6522 onChange : null, 6523 afterRedraw : null, 6524 checkValues : null, 6525 error: false, 6526 errmsg : "", 6527 errorcheck : true, 6528 showQuery : true, 6529 sopt : null, 6530 ops : [], 6531 operands : null, 6532 numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'], 6533 stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'], 6534 strarr : ['text', 'string', 'blob'], 6535 groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }], 6536 groupButton : true, 6537 ruleButtons : true, 6538 direction : "ltr" 6539 }, $.jgrid.filter, arg || {}); 6540 return this.each( function() { 6541 if (this.filter) {return;} 6542 this.p = p; 6543 // setup filter in case if they is not defined 6544 if (this.p.filter === null || this.p.filter === undefined) { 6545 this.p.filter = { 6546 groupOp: this.p.groupOps[0].op, 6547 rules: [], 6548 groups: [] 6549 }; 6550 } 6551 var i, len = this.p.columns.length, cl, 6552 isIE = /msie/i.test(navigator.userAgent) && !window.opera; 6553 6554 // translating the options 6555 this.p.initFilter = $.extend(true,{},this.p.filter); 6556 6557 // set default values for the columns if they are not set 6558 if( !len ) {return;} 6559 for(i=0; i < len; i++) { 6560 cl = this.p.columns[i]; 6561 if( cl.stype ) { 6562 // grid compatibility 6563 cl.inputtype = cl.stype; 6564 } else if(!cl.inputtype) { 6565 cl.inputtype = 'text'; 6566 } 6567 if( cl.sorttype ) { 6568 // grid compatibility 6569 cl.searchtype = cl.sorttype; 6570 } else if (!cl.searchtype) { 6571 cl.searchtype = 'string'; 6572 } 6573 if(cl.hidden === undefined) { 6574 // jqGrid compatibility 6575 cl.hidden = false; 6576 } 6577 if(!cl.label) { 6578 cl.label = cl.name; 6579 } 6580 if(cl.index) { 6581 cl.name = cl.index; 6582 } 6583 if(!cl.hasOwnProperty('searchoptions')) { 6584 cl.searchoptions = {}; 6585 } 6586 if(!cl.hasOwnProperty('searchrules')) { 6587 cl.searchrules = {}; 6588 } 6589 6590 } 6591 if(this.p.showQuery) { 6592 $(this).append("<table class='queryresult ui-widget ui-widget-content' style='display:block;max-width:440px;border:0px none;' dir='"+this.p.direction+"'><tbody><tr><td class='query'></td></tr></tbody></table>"); 6593 } 6594 var getGrid = function () { 6595 return $("#" + $.jgrid.jqID(p.id))[0] || null; 6596 }; 6597 /* 6598 *Perform checking. 6599 * 6600 */ 6601 var checkData = function(val, colModelItem) { 6602 var ret = [true,""], $t = getGrid(); 6603 if($.isFunction(colModelItem.searchrules)) { 6604 ret = colModelItem.searchrules.call($t, val, colModelItem); 6605 } else if($.jgrid && $.jgrid.checkValues) { 6606 try { 6607 ret = $.jgrid.checkValues.call($t, val, -1, colModelItem.searchrules, colModelItem.label); 6608 } catch (e) {} 6609 } 6610 if(ret && ret.length && ret[0] === false) { 6611 p.error = !ret[0]; 6612 p.errmsg = ret[1]; 6613 } 6614 }; 6615 /* moving to common 6616 randId = function() { 6617 return Math.floor(Math.random()*10000).toString(); 6618 }; 6619 */ 6620 6621 this.onchange = function ( ){ 6622 // clear any error 6623 this.p.error = false; 6624 this.p.errmsg=""; 6625 return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false; 6626 }; 6627 /* 6628 * Redraw the filter every time when new field is added/deleted 6629 * and field is changed 6630 */ 6631 this.reDraw = function() { 6632 $("table.group:first",this).remove(); 6633 var t = this.createTableForGroup(p.filter, null); 6634 $(this).append(t); 6635 if($.isFunction(this.p.afterRedraw) ) { 6636 this.p.afterRedraw.call(this, this.p); 6637 } 6638 }; 6639 /* 6640 * Creates a grouping data for the filter 6641 * @param group - object 6642 * @param parentgroup - object 6643 */ 6644 this.createTableForGroup = function(group, parentgroup) { 6645 var that = this, i; 6646 // this table will hold all the group (tables) and rules (rows) 6647 var table = $("<table class='group ui-widget ui-widget-content' style='border:0px none;'><tbody></tbody></table>"), 6648 // create error message row 6649 align = "left"; 6650 if(this.p.direction === "rtl") { 6651 align = "right"; 6652 table.attr("dir","rtl"); 6653 } 6654 if(parentgroup === null) { 6655 table.append("<tr class='error' style='display:none;'><th colspan='5' class='ui-state-error' align='"+align+"'></th></tr>"); 6656 } 6657 6658 var tr = $("<tr></tr>"); 6659 table.append(tr); 6660 // this header will hold the group operator type and group action buttons for 6661 // creating subgroup "+ {}", creating rule "+" or deleting the group "-" 6662 var th = $("<th colspan='5' align='"+align+"'></th>"); 6663 tr.append(th); 6664 6665 if(this.p.ruleButtons === true) { 6666 // dropdown for: choosing group operator type 6667 var groupOpSelect = $("<select class='opsel'></select>"); 6668 th.append(groupOpSelect); 6669 // populate dropdown with all posible group operators: or, and 6670 var str= "", selected; 6671 for (i = 0; i < p.groupOps.length; i++) { 6672 selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :""; 6673 str += "<option value='"+that.p.groupOps[i].op+"'" + selected+">"+that.p.groupOps[i].text+"</option>"; 6674 } 6675 6676 groupOpSelect 6677 .append(str) 6678 .bind('change',function() { 6679 group.groupOp = $(groupOpSelect).val(); 6680 that.onchange(); // signals that the filter has changed 6681 }); 6682 } 6683 // button for adding a new subgroup 6684 var inputAddSubgroup ="<span></span>"; 6685 if(this.p.groupButton) { 6686 inputAddSubgroup = $("<input type='button' value='+ {}' title='Add subgroup' class='add-group'/>"); 6687 inputAddSubgroup.bind('click',function() { 6688 if (group.groups === undefined ) { 6689 group.groups = []; 6690 } 6691 6692 group.groups.push({ 6693 groupOp: p.groupOps[0].op, 6694 rules: [], 6695 groups: [] 6696 }); // adding a new group 6697 6698 that.reDraw(); // the html has changed, force reDraw 6699 6700 that.onchange(); // signals that the filter has changed 6701 return false;
vendor: 7,508 bytes, lines 6702-6915
6702 }); 6703 } 6704 th.append(inputAddSubgroup); 6705 if(this.p.ruleButtons === true) { 6706 // button for adding a new rule 6707 var inputAddRule = $("<input type='button' value='+' title='Add rule' class='add-rule ui-add'/>"), cm; 6708 inputAddRule.bind('click',function() { 6709 //if(!group) { group = {};} 6710 if (group.rules === undefined) { 6711 group.rules = []; 6712 } 6713 for (i = 0; i < that.p.columns.length; i++) { 6714 // but show only serchable and serchhidden = true fields 6715 var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search, 6716 hidden = (that.p.columns[i].hidden === true), 6717 ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true); 6718 if ((ignoreHiding && searchable) || (searchable && !hidden)) { 6719 cm = that.p.columns[i]; 6720 break; 6721 } 6722 } 6723 6724 var opr; 6725 if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;} 6726 else if(that.p.sopt) { opr= that.p.sopt; } 6727 else if ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {opr = that.p.stropts;} 6728 else {opr = that.p.numopts;} 6729 6730 group.rules.push({ 6731 field: cm.name, 6732 op: opr[0], 6733 data: "" 6734 }); // adding a new rule 6735 6736 that.reDraw(); // the html has changed, force reDraw 6737 // for the moment no change have been made to the rule, so 6738 // this will not trigger onchange event 6739 return false; 6740 }); 6741 th.append(inputAddRule); 6742 } 6743 6744 // button for delete the group 6745 if (parentgroup !== null) { // ignore the first group 6746 var inputDeleteGroup = $("<input type='button' value='-' title='Delete group' class='delete-group'/>"); 6747 th.append(inputDeleteGroup); 6748 inputDeleteGroup.bind('click',function() { 6749 // remove group from parent 6750 for (i = 0; i < parentgroup.groups.length; i++) { 6751 if (parentgroup.groups[i] === group) { 6752 parentgroup.groups.splice(i, 1); 6753 break; 6754 } 6755 } 6756 6757 that.reDraw(); // the html has changed, force reDraw 6758 6759 that.onchange(); // signals that the filter has changed 6760 return false; 6761 }); 6762 } 6763 6764 // append subgroup rows 6765 if (group.groups !== undefined) { 6766 for (i = 0; i < group.groups.length; i++) { 6767 var trHolderForSubgroup = $("<tr></tr>"); 6768 table.append(trHolderForSubgroup); 6769 6770 var tdFirstHolderForSubgroup = $("<td class='first'></td>"); 6771 trHolderForSubgroup.append(tdFirstHolderForSubgroup); 6772 6773 var tdMainHolderForSubgroup = $("<td colspan='4'></td>"); 6774 tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group)); 6775 trHolderForSubgroup.append(tdMainHolderForSubgroup); 6776 } 6777 } 6778 if(group.groupOp === undefined) { 6779 group.groupOp = that.p.groupOps[0].op; 6780 } 6781 6782 // append rules rows 6783 if (group.rules !== undefined) { 6784 for (i = 0; i < group.rules.length; i++) { 6785 table.append( 6786 this.createTableRowForRule(group.rules[i], group) 6787 ); 6788 } 6789 } 6790 6791 return table; 6792 }; 6793 /* 6794 * Create the rule data for the filter 6795 */ 6796 this.createTableRowForRule = function(rule, group ) { 6797 // save current entity in a variable so that it could 6798 // be referenced in anonimous method calls 6799 6800 var that=this, $t = getGrid(), tr = $("<tr></tr>"), 6801 //document.createElement("tr"), 6802 6803 // first column used for padding 6804 //tdFirstHolderForRule = document.createElement("td"), 6805 i, op, trpar, cm, str="", selected; 6806 //tdFirstHolderForRule.setAttribute("class", "first"); 6807 tr.append("<td class='first'></td>"); 6808 6809 6810 // create field container 6811 var ruleFieldTd = $("<td class='columns'></td>"); 6812 tr.append(ruleFieldTd); 6813 6814 6815 // dropdown for: choosing field 6816 var ruleFieldSelect = $("<select></select>"), ina, aoprs = []; 6817 ruleFieldTd.append(ruleFieldSelect); 6818 ruleFieldSelect.bind('change',function() { 6819 rule.field = $(ruleFieldSelect).val(); 6820 6821 trpar = $(this).parents("tr:first"); 6822 for (i=0;i<that.p.columns.length;i++) { 6823 if(that.p.columns[i].name === rule.field) { 6824 cm = that.p.columns[i]; 6825 break; 6826 } 6827 } 6828 if(!cm) {return;} 6829 cm.searchoptions.id = $.jgrid.randId(); 6830 if(isIE && cm.inputtype === "text") { 6831 if(!cm.searchoptions.size) { 6832 cm.searchoptions.size = 10; 6833 } 6834 } 6835 var elm = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions || {}, true); 6836 $(elm).addClass("input-elm"); 6837 //that.createElement(rule, ""); 6838 6839 if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;} 6840 else if(that.p.sopt) { op= that.p.sopt; } 6841 else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;} 6842 else {op = that.p.numopts;} 6843 // operators 6844 var s ="", so = 0; 6845 aoprs = []; 6846 $.each(that.p.ops, function() { aoprs.push(this.oper); }); 6847 for ( i = 0 ; i < op.length; i++) { 6848 ina = $.inArray(op[i],aoprs); 6849 if(ina !== -1) { 6850 if(so===0) { 6851 rule.op = that.p.ops[ina].oper; 6852 } 6853 s += "<option value='"+that.p.ops[ina].oper+"'>"+that.p.ops[ina].text+"</option>"; 6854 so++; 6855 } 6856 } 6857 $(".selectopts",trpar).empty().append( s ); 6858 $(".selectopts",trpar)[0].selectedIndex = 0; 6859 if( $.jgrid.msie && $.jgrid.msiever() < 9) { 6860 var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1; 6861 $(".selectopts",trpar).width( sw ); 6862 $(".selectopts",trpar).css("width","auto"); 6863 } 6864 // data 6865 $(".data",trpar).empty().append( elm ); 6866 $.jgrid.bindEv.call($t, elm, cm.searchoptions); 6867 $(".input-elm",trpar).bind('change',function( e ) { 6868 var elem = e.target; 6869 rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ? 6870 cm.searchoptions.custom_value.call($t, $(elem).children(".customelement:first"), 'get') : elem.value; 6871 that.onchange(); // signals that the filter has changed 6872 }); 6873 setTimeout(function(){ //IE, Opera, Chrome 6874 rule.data = $(elm).val(); 6875 that.onchange(); // signals that the filter has changed 6876 }, 0); 6877 }); 6878 6879 // populate drop down with user provided column definitions 6880 var j=0; 6881 for (i = 0; i < that.p.columns.length; i++) { 6882 // but show only serchable and serchhidden = true fields 6883 var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search, 6884 hidden = (that.p.columns[i].hidden === true), 6885 ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true); 6886 if ((ignoreHiding && searchable) || (searchable && !hidden)) { 6887 selected = ""; 6888 if(rule.field === that.p.columns[i].name) { 6889 selected = " selected='selected'"; 6890 j=i; 6891 } 6892 str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>"; 6893 } 6894 } 6895 ruleFieldSelect.append( str ); 6896 6897 6898 // create operator container 6899 var ruleOperatorTd = $("<td class='operators'></td>"); 6900 tr.append(ruleOperatorTd); 6901 cm = p.columns[j]; 6902 // create it here so it can be referentiated in the onchange event 6903 //var RD = that.createElement(rule, rule.data); 6904 cm.searchoptions.id = $.jgrid.randId(); 6905 if(isIE && cm.inputtype === "text") { 6906 if(!cm.searchoptions.size) { 6907 cm.searchoptions.size = 10; 6908 } 6909 } 6910 var ruleDataInput = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions || {}, true); 6911 if(rule.op === 'nu' || rule.op === 'nn') { 6912 $(ruleDataInput).attr('readonly','true'); 6913 $(ruleDataInput).attr('disabled','true'); 6914 } //retain the state of disabled text fields in case of null ops 6915 // dropdown for: choosing operator
6916 var ruleOperatorSelect = $("<select class='selectopts'></select>"); 6917 ruleOperatorTd.append(ruleOperatorSelect); 6918 ruleOperatorSelect.bind('change',function() { 6919 rule.op = $(ruleOperatorSelect).val(); 6920 trpar = $(this).parents("tr:first"); 6921 var rd = $(".input-elm",trpar)[0]; 6922 if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null" 6923 rule.data = ""; 6924 if(rd.tagName.toUpperCase() !== 'SELECT') rd.value = ""; 6925 rd.setAttribute("readonly", "true"); 6926 rd.setAttribute("disabled", "true"); 6927 } else { 6928 if(rd.tagName.toUpperCase() === 'SELECT') rule.data = rd.value; 6929 rd.removeAttribute("readonly"); 6930 rd.removeAttribute("disabled"); 6931 } 6932 6933 that.onchange(); // signals that the filter has changed 6934 }); 6935 6936 // populate drop down with all available operators 6937 if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;} 6938 else if(that.p.sopt) { op= that.p.sopt; } 6939 else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;} 6940 else {op = that.p.numopts;} 6941 str=""; 6942 $.each(that.p.ops, function() { aoprs.push(this.oper); }); 6943 for ( i = 0; i < op.length; i++) { 6944 ina = $.inArray(op[i],aoprs); 6945 if(ina !== -1) { 6946 selected = rule.op === that.p.ops[ina].oper ? " selected='selected'" : ""; 6947 str += "<option value='"+that.p.ops[ina].oper+"'"+selected+">"+that.p.ops[ina].text+"</option>"; 6948 } 6949 } 6950 ruleOperatorSelect.append( str ); 6951 // create data container 6952 var ruleDataTd = $("<td class='data'></td>"); 6953 tr.append(ruleDataTd); 6954 6955 // textbox for: data 6956 // is created previously 6957 //ruleDataInput.setAttribute("type", "text"); 6958 ruleDataTd.append(ruleDataInput); 6959 $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions); 6960 $(ruleDataInput) 6961 .addClass("input-elm") 6962 .bind('change', function() { 6963 rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(this).children(".customelement:first"),'get') : $(this).val(); 6964 that.onchange(); // signals that the filter has changed 6965 }); 6966 6967 // create action container 6968 var ruleDeleteTd = $("<td></td>"); 6969 tr.append(ruleDeleteTd); 6970 6971 // create button for: delete rule 6972 if(this.p.ruleButtons === true) { 6973 var ruleDeleteInput = $("<input type='button' value='-' title='Delete rule' class='delete-rule ui-del'/>"); 6974 ruleDeleteTd.append(ruleDeleteInput); 6975 //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}}); 6976 ruleDeleteInput.bind('click',function() { 6977 // remove rule from group 6978 for (i = 0; i < group.rules.length; i++) { 6979 if (group.rules[i] === rule) { 6980 group.rules.splice(i, 1); 6981 break; 6982 } 6983 } 6984 6985 that.reDraw(); // the html has changed, force reDraw 6986 6987 that.onchange(); // signals that the filter has changed 6988 return false; 6989 }); 6990 } 6991 return tr; 6992 }; 6993 6994 this.getStringForGroup = function(group) { 6995 var s = "(", index; 6996 if (group.groups !== undefined) { 6997 for (index = 0; index < group.groups.length; index++) { 6998 if (s.length > 1) { 6999 s += " " + group.groupOp + " "; 7000 } 7001 try { 7002 s += this.getStringForGroup(group.groups[index]); 7003 } catch (eg) {alert(eg);} 7004 } 7005 } 7006 7007 if (group.rules !== undefined) { 7008 try{ 7009 for (index = 0; index < group.rules.length; index++) { 7010 if (s.length > 1) { 7011 s += " " + group.groupOp + " "; 7012 } 7013 s += this.getStringForRule(group.rules[index]); 7014 } 7015 } catch (e) {alert(e);} 7016 } 7017 7018 s += ")"; 7019 7020 if (s === "()") { 7021 return ""; // ignore groups that don't have rules 7022 } 7023 return s; 7024 }; 7025 this.getStringForRule = function(rule) { 7026 var opUF = "",opC="", i, cm, ret, val, 7027 numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid 7028 for (i = 0; i < this.p.ops.length; i++) { 7029 if (this.p.ops[i].oper === rule.op) { 7030 opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : ""; 7031 opC = this.p.ops[i].oper; 7032 break; 7033 } 7034 } 7035 for (i=0; i<this.p.columns.length; i++) { 7036 if(this.p.columns[i].name === rule.field) { 7037 cm = this.p.columns[i]; 7038 break; 7039 } 7040 } 7041 if (cm == undefined) { return ""; } 7042 val = rule.data; 7043 if(opC === 'bw' || opC === 'bn') { val = val+"%"; } 7044 if(opC === 'ew' || opC === 'en') { val = "%"+val; } 7045 if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; } 7046 if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; } 7047 if(p.errorcheck) { checkData(rule.data, cm); } 7048 if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; } 7049 else { ret = rule.field + " " + opUF + " \"" + val + "\""; } 7050 return ret; 7051 }; 7052 this.resetFilter = function () { 7053 this.p.filter = $.extend(true,{},this.p.initFilter); 7054 this.reDraw(); 7055 this.onchange(); 7056 }; 7057 this.hideError = function() { 7058 $("th.ui-state-error", this).html(""); 7059 $("tr.error", this).hide(); 7060 }; 7061 this.showError = function() { 7062 $("th.ui-state-error", this).html(this.p.errmsg); 7063 $("tr.error", this).show(); 7064 }; 7065 this.toUserFriendlyString = function() {
7066 return this.getStringForGroup(p.filter); 7067 }; 7068 this.toString = function() { 7069 // this will obtain a string that can be used to match an item. 7070 var that = this; 7071 function getStringRule(rule) { 7072 if(that.p.errorcheck) { 7073 var i, cm; 7074 for (i=0; i<that.p.columns.length; i++) { 7075 if(that.p.columns[i].name === rule.field) { 7076 cm = that.p.columns[i]; 7077 break; 7078 } 7079 } 7080 if(cm) {checkData(rule.data, cm);} 7081 } 7082 return rule.op + "(item." + rule.field + ",'" + rule.data + "')"; 7083 } 7084 7085 function getStringForGroup(group) { 7086 var s = "(", index; 7087 7088 if (group.groups !== undefined) { 7089 for (index = 0; index < group.groups.length; index++) { 7090 if (s.length > 1) { 7091 if (group.groupOp === "OR") { 7092 s += " || "; 7093 } 7094 else { 7095 s += " && "; 7096 } 7097 } 7098 s += getStringForGroup(group.groups[index]); 7099 } 7100 } 7101 7102 if (group.rules !== undefined) { 7103 for (index = 0; index < group.rules.length; index++) { 7104 if (s.length > 1) { 7105 if (group.groupOp === "OR") { 7106 s += " || "; 7107 } 7108 else { 7109 s += " && "; 7110 } 7111 } 7112 s += getStringRule(group.rules[index]); 7113 } 7114 } 7115 7116 s += ")"; 7117 7118 if (s === "()") { 7119 return ""; // ignore groups that don't have rules 7120 } 7121 return s; 7122 } 7123 7124 return getStringForGroup(this.p.filter); 7125 }; 7126 7127 // Here we init the filter 7128 this.reDraw(); 7129 7130 if(this.p.showQuery) { 7131 this.onchange(); 7132 } 7133 // mark is as created so that it will not be created twice on this element 7134 this.filter = true; 7135 }); 7136}; 7137$.extend($.fn.jqFilter,{ 7138 /* 7139 * Return SQL like string. Can be used directly 7140 */ 7141 toSQLString : function() 7142 { 7143 var s =""; 7144 this.each(function(){ 7145 s = this.toUserFriendlyString(); 7146 }); 7147 return s; 7148 }, 7149 /* 7150 * Return filter data as object. 7151 */ 7152 filterData : function() 7153 { 7154 var s; 7155 this.each(function(){ 7156 s = this.p.filter; 7157 }); 7158 return s; 7159 7160 }, 7161 getParameter : function (param) { 7162 if(param !== undefined) { 7163 if (this.p.hasOwnProperty(param) ) { 7164 return this.p[param]; 7165 } 7166 } 7167 return this.p; 7168 }, 7169 resetFilter: function() { 7170 return this.each(function(){ 7171 this.resetFilter(); 7172 }); 7173 }, 7174 addFilter: function (pfilter) { 7175 if (typeof pfilter === "string") { 7176 pfilter = $.jgrid.parse( pfilter ); 7177 } 7178 this.each(function(){ 7179 this.p.filter = pfilter; 7180 this.reDraw(); 7181 this.onchange(); 7182 }); 7183 } 7184 7185}); 7186})(jQuery); 7187/*jshint eqeqeq:false, eqnull:true, devel:true */ 7188/*global xmlJsonClass, jQuery */ 7189(function($){ 7190/** 7191 * jqGrid extension for form editing Grid Data 7192 * Tony Tomov [email protected] 7193 * http://trirand.com/blog/ 7194 * Dual licensed under the MIT and GPL licenses: 7195 * http://www.opensource.org/licenses/mit-license.php 7196 * http://www.gnu.org/licenses/gpl-2.0.html 7197**/ 7198"use strict"; 7199var rp_ge = {}; 7200$.jgrid.extend({ 7201 searchGrid : function (p) { 7202 p = $.extend(true, { 7203 recreateFilter: false, 7204 drag: true, 7205 sField:'searchField', 7206 sValue:'searchString', 7207 sOper: 'searchOper', 7208 sFilter: 'filters', 7209 loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only. 7210 beforeShowSearch: null, 7211 afterShowSearch : null, 7212 onInitializeSearch: null, 7213 afterRedraw : null, 7214 afterChange: null, 7215 closeAfterSearch : false, 7216 closeAfterReset: false, 7217 closeOnEscape : false, 7218 searchOnEnter : false, 7219 multipleSearch : false, 7220 multipleGroup : false, 7221 //cloneSearchRowOnAdd: true, 7222 top : 0, 7223 left: 0, 7224 jqModal : true, 7225 modal: false, 7226 resize : true, 7227 width: 450, 7228 height: 'auto', 7229 dataheight: 'auto', 7230 showQuery: false, 7231 errorcheck : true, 7232 sopt: null, 7233 stringResult: undefined, 7234 onClose : null, 7235 onSearch : null, 7236 onReset : null, 7237 toTop : true, 7238 overlay : 30, 7239 columns : [], 7240 tmplNames : null, 7241 tmplFilters : null, 7242 tmplLabel : ' Template: ', 7243 showOnLoad: false, 7244 layer: null, 7245 operands : { "eq" :"=", "ne":"<>","lt":"<","le":"<=","gt":">","ge":">=","bw":"LIKE","bn":"NOT LIKE","in":"IN","ni":"NOT IN","ew":"LIKE","en":"NOT LIKE","cn":"LIKE","nc":"NOT LIKE","nu":"IS NULL","nn":"ISNOT NULL"} 7246 }, $.jgrid.search, p || {}); 7247 return this.each(function() { 7248 var $t = this; 7249 if(!$t.grid) {return;} 7250 var fid = "fbox_"+$t.p.id, 7251 showFrm = true, 7252 mustReload = true, 7253 IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid}, 7254 defaultFilters = $t.p.postData[p.sFilter], 7255 fl; 7256 if(typeof defaultFilters === "string") { 7257 defaultFilters = $.jgrid.parse( defaultFilters ); 7258 } 7259 if(p.recreateFilter === true) { 7260 $("#"+$.jgrid.jqID(IDs.themodal)).remove(); 7261 } 7262 function showFilter(_filter) { 7263 showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]); 7264 if(showFrm === undefined) { 7265 showFrm = true; 7266 } 7267 if(showFrm && $.isFunction(p.beforeShowSearch)) { 7268 showFrm = p.beforeShowSearch.call($t,_filter); 7269 } 7270 if(showFrm) { 7271 $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop}); 7272 $($t).triggerHandler("jqGridFilterAfterShow", [_filter]); 7273 if($.isFunction(p.afterShowSearch)) { 7274 p.afterShowSearch.call($t, _filter); 7275 } 7276 } 7277 } 7278 if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) { 7279 showFilter($("#fbox_"+$.jgrid.jqID(+$t.p.id))); 7280 } else { 7281 var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)), 7282 align = "left", butleft =""; 7283 if($t.p.direction === "rtl") {
7284 align = "right"; 7285 butleft = " style='text-align:left'"; 7286 fil.attr("dir","rtl"); 7287 } 7288 var columns = $.extend([],$t.p.colModel), 7289 bS ="<a id='"+fid+"_search' class='fm-button ui-state-default ui-corner-all fm-button-icon-right ui-reset'><span class='ui-icon ui-icon-search'></span>"+p.Find+"</a>", 7290 bC ="<a id='"+fid+"_reset' class='fm-button ui-state-default ui-corner-all fm-button-icon-left ui-search'><span class='ui-icon ui-icon-arrowreturnthick-1-w'></span>"+p.Reset+"</a>", 7291 bQ = "", tmpl="", colnm, found = false, bt, cmi=-1; 7292 if(p.showQuery) { 7293 bQ ="<a id='"+fid+"_query' class='fm-button ui-state-default ui-corner-all fm-button-icon-left'><span class='ui-icon ui-icon-comment'></span>Query</a>"; 7294 } 7295 if(!p.columns.length) { 7296 $.each(columns, function(i,n){ 7297 if(!n.label) { 7298 n.label = $t.p.colNames[i]; 7299 } 7300 // find first searchable column and set it if no default filter 7301 if(!found) { 7302 var searchable = (n.search === undefined) ? true: n.search , 7303 hidden = (n.hidden === true), 7304 ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true); 7305 if ((ignoreHiding && searchable) || (searchable && !hidden)) { 7306 found = true; 7307 colnm = n.index || n.name; 7308 cmi =i; 7309 } 7310 } 7311 }); 7312 } else { 7313 columns = p.columns; 7314 cmi = 0; 7315 colnm = columns[0].index || columns[0].name; 7316 } 7317 // old behaviour 7318 if( (!defaultFilters && colnm) || p.multipleSearch === false ) { 7319 var cmop = "eq"; 7320 if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) { 7321 cmop = columns[cmi].searchoptions.sopt[0]; 7322 } else if(p.sopt && p.sopt.length) { 7323 cmop = p.sopt[0]; 7324 } 7325 defaultFilters = {groupOp: "AND", rules: [{field: colnm, op: cmop, data: ""}]}; 7326 } 7327 found = false; 7328 if(p.tmplNames && p.tmplNames.length) { 7329 found = true; 7330 tmpl = p.tmplLabel; 7331 tmpl += "<select class='ui-template'>"; 7332 tmpl += "<option value='default'>Default</option>"; 7333 $.each(p.tmplNames, function(i,n){ 7334 tmpl += "<option value='"+i+"'>"+n+"</option>"; 7335 }); 7336 tmpl += "</select>"; 7337 } 7338 7339 bt = "<table class='EditTable' style='border:0px none;margin-top:5px' id='"+fid+"_2'><tbody><tr><td colspan='2'><hr class='ui-widget-content' style='margin:1px'/></td></tr><tr><td class='EditButton' style='text-align:"+align+"'>"+bC+tmpl+"</td><td class='EditButton' "+butleft+">"+bQ+bS+"</td></tr></tbody></table>"; 7340 fid = $.jgrid.jqID( fid); 7341 $("#"+fid).jqFilter({ 7342 columns : columns, 7343 filter: p.loadDefaults ? defaultFilters : null, 7344 showQuery: p.showQuery, 7345 errorcheck : p.errorcheck, 7346 sopt: p.sopt, 7347 groupButton : p.multipleGroup, 7348 ruleButtons : p.multipleSearch, 7349 afterRedraw : p.afterRedraw, 7350 ops : p.odata, 7351 operands : p.operands, 7352 ajaxSelectOptions: $t.p.ajaxSelectOptions, 7353 groupOps: p.groupOps, 7354 onChange : function() { 7355 if(this.p.showQuery) { 7356 $('.query',this).html(this.toUserFriendlyString()); 7357 } 7358 if ($.isFunction(p.afterChange)) { 7359 p.afterChange.call($t, $("#"+fid), p); 7360 } 7361 }, 7362 direction : $t.p.direction, 7363 id: $t.p.id 7364 }); 7365 fil.append( bt ); 7366 if(found && p.tmplFilters && p.tmplFilters.length) { 7367 $(".ui-template", fil).bind('change', function(){ 7368 var curtempl = $(this).val(); 7369 if(curtempl==="default") { 7370 $("#"+fid).jqFilter('addFilter', defaultFilters); 7371 } else { 7372 $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]); 7373 } 7374 return false; 7375 }); 7376 } 7377 if(p.multipleGroup === true) {p.multipleSearch = true;} 7378 $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]); 7379 if($.isFunction(p.onInitializeSearch) ) { 7380 p.onInitializeSearch.call($t, $("#"+fid)); 7381 } 7382 p.gbox = "#gbox_"+fid; 7383 if (p.layer) { 7384 $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"}); 7385 } else { 7386 $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]); 7387 } 7388 if (p.searchOnEnter || p.closeOnEscape) { 7389 $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) { 7390 var $target = $(e.target); 7391 if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER 7392 !$target.hasClass('add-group') && !$target.hasClass('add-rule') && 7393 !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') && 7394 (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) { 7395 $("#"+fid+"_search").click(); 7396 return false;
7397 } 7398 if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE 7399 $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").click(); 7400 return false; 7401 } 7402 }); 7403 } 7404 if(bQ) { 7405 $("#"+fid+"_query").bind('click', function(){ 7406 $(".queryresult", fil).toggle(); 7407 return false; 7408 }); 7409 } 7410 if (p.stringResult===undefined) { 7411 // to provide backward compatibility, inferring stringResult value from multipleSearch 7412 p.stringResult = p.multipleSearch; 7413 } 7414 $("#"+fid+"_search").bind('click', function(){ 7415 var sdata={}, res, filters; 7416 fl = $("#"+fid); 7417 fl.find(".input-elm:focus").change(); 7418 filters = fl.jqFilter('filterData'); 7419 if(p.errorcheck) { 7420 fl[0].hideError(); 7421 if(!p.showQuery) {fl.jqFilter('toSQLString');} 7422 if(fl[0].p.error) { 7423 fl[0].showError(); 7424 return false; 7425 } 7426 } 7427 7428 if(p.stringResult) { 7429 try { 7430 // xmlJsonClass or JSON.stringify 7431 res = xmlJsonClass.toJson(filters, '', '', false); 7432 } catch (e) { 7433 try { 7434 res = JSON.stringify(filters); 7435 } catch (e2) { } 7436 } 7437 if(typeof res==="string") { 7438 sdata[p.sFilter] = res; 7439 $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";}); 7440 } 7441 } else { 7442 if(p.multipleSearch) { 7443 sdata[p.sFilter] = filters; 7444 $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";}); 7445 } else { 7446 sdata[p.sField] = filters.rules[0].field; 7447 sdata[p.sValue] = filters.rules[0].data; 7448 sdata[p.sOper] = filters.rules[0].op; 7449 sdata[p.sFilter] = ""; 7450 } 7451 } 7452 $t.p.search = true; 7453 $.extend($t.p.postData,sdata); 7454 mustReload = $($t).triggerHandler("jqGridFilterSearch"); 7455 if( mustReload === undefined) { 7456 mustReload = true; 7457 } 7458 if(mustReload && $.isFunction(p.onSearch) ) { 7459 mustReload = p.onSearch.call($t, $t.p.filters); 7460 } 7461 if (mustReload !== false) { 7462 $($t).trigger("reloadGrid",[{page:1}]); 7463 } 7464 if(p.closeAfterSearch) { 7465 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose}); 7466 } 7467 return false; 7468 }); 7469 $("#"+fid+"_reset").bind('click', function(){ 7470 var sdata={}, 7471 fl = $("#"+fid); 7472 $t.p.search = false; 7473 $t.p.resetsearch = true; 7474 if(p.multipleSearch===false) { 7475 sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = ""; 7476 } else { 7477 sdata[p.sFilter] = ""; 7478 } 7479 fl[0].resetFilter(); 7480 if(found) { 7481 $(".ui-template", fil).val("default"); 7482 } 7483 $.extend($t.p.postData,sdata); 7484 mustReload = $($t).triggerHandler("jqGridFilterReset"); 7485 if(mustReload === undefined) { 7486 mustReload = true; 7487 } 7488 if(mustReload && $.isFunction(p.onReset) ) { 7489 mustReload = p.onReset.call($t); 7490 } 7491 if(mustReload !== false) { 7492 $($t).trigger("reloadGrid",[{page:1}]); 7493 } 7494 if (p.closeAfterReset) { 7495 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose}); 7496 } 7497 return false; 7498 }); 7499 showFilter($("#"+fid)); 7500 $(".fm-button:not(.ui-state-disabled)",fil).hover( 7501 function(){$(this).addClass('ui-state-hover');}, 7502 function(){$(this).removeClass('ui-state-hover');} 7503 ); 7504 } 7505 }); 7506 }, 7507 editGridRow : function(rowid, p){ 7508 p = $.extend(true, { 7509 top : 0, 7510 left: 0, 7511 width: 300, 7512 datawidth: 'auto', 7513 height: 'auto', 7514 dataheight: 'auto', 7515 modal: false, 7516 overlay : 30, 7517 drag: true, 7518 resize: true, 7519 url: null, 7520 mtype : "POST", 7521 clearAfterAdd :true, 7522 closeAfterEdit : false, 7523 reloadAfterSubmit : true, 7524 onInitializeForm: null, 7525 beforeInitData: null, 7526 beforeShowForm: null, 7527 afterShowForm: null, 7528 beforeSubmit: null, 7529 afterSubmit: null, 7530 onclickSubmit: null, 7531 afterComplete: null, 7532 onclickPgButtons : null, 7533 afterclickPgButtons: null, 7534 editData : {}, 7535 recreateForm : false, 7536 jqModal : true, 7537 closeOnEscape : false, 7538 addedrow : "first", 7539 topinfo : '', 7540 bottominfo: '', 7541 saveicon : [], 7542 closeicon : [], 7543 savekey: [false,13], 7544 navkeys: [false,38,40], 7545 checkOnSubmit : false, 7546 checkOnUpdate : false, 7547 _savedData : {}, 7548 processing : false, 7549 onClose : null, 7550 ajaxEditOptions : {}, 7551 serializeEditData : null, 7552 viewPagerButtons : true, 7553 overlayClass : 'ui-widget-overlay' 7554 }, $.jgrid.edit, p || {}); 7555 rp_ge[$(this)[0].p.id] = p; 7556 return this.each(function(){ 7557 var $t = this; 7558 if (!$t.grid || !rowid) {return;} 7559 var gID = $t.p.id, 7560 frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg), 7561 IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr}, 7562 onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false, 7563 onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false, 7564 onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false, 7565 onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false, 7566 showFrm = true, 7567 maxCols = 1, maxRows=0, postdata, diff, frmoper; 7568 frmgr = $.jgrid.jqID(frmgr);
7569 if (rowid === "new") { 7570 rowid = "_empty"; 7571 frmoper = "add"; 7572 p.caption=rp_ge[$t.p.id].addCaption; 7573 } else { 7574 p.caption=rp_ge[$t.p.id].editCaption; 7575 frmoper = "edit"; 7576 } 7577 if(!p.recreateForm) { 7578 if( $($t).data("formProp") ) { 7579 $.extend(rp_ge[$(this)[0].p.id], $($t).data("formProp")); 7580 } 7581 } 7582 var closeovrl = true; 7583 if(p.checkOnUpdate && p.jqModal && !p.modal) { 7584 closeovrl = false; 7585 } 7586 function getFormData(){ 7587 $(frmtb+" > tbody > tr > td > .FormElement").each(function() { 7588 var celm = $(".customelement", this); 7589 if (celm.length) { 7590 var elem = celm[0], nm = $(elem).attr('name'); 7591 $.each($t.p.colModel, function(){ 7592 if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) { 7593 try { 7594 postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get'); 7595 if (postdata[nm] === undefined) {throw "e1";} 7596 } catch (e) { 7597 if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);} 7598 else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);} 7599 } 7600 return true; 7601 } 7602 }); 7603 } else { 7604 switch ($(this).get(0).type) { 7605 case "checkbox": 7606 if($(this).is(":checked")) { 7607 postdata[this.name]= $(this).val(); 7608 }else { 7609 var ofv = $(this).attr("offval"); 7610 postdata[this.name]= ofv; 7611 } 7612 break; 7613 case "select-one": 7614 postdata[this.name]= $("option:selected",this).val(); 7615 break; 7616 case "select-multiple": 7617 postdata[this.name]= $(this).val(); 7618 if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");} 7619 else {postdata[this.name] ="";} 7620 var selectedText = []; 7621 $("option:selected",this).each( 7622 function(i,selected){ 7623 selectedText[i] = $(selected).text(); 7624 } 7625 ); 7626 break; 7627 case "password": 7628 case "text": 7629 case "textarea": 7630 case "button": 7631 postdata[this.name] = $(this).val(); 7632 7633 break; 7634 } 7635 if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);} 7636 } 7637 }); 7638 return true; 7639 } 7640 function createData(rowid,obj,tb,maxcols){ 7641 var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false, 7642 tdtmpl = "<td class='CaptionTD'> </td><td class='DataTD'> </td>", tmpl="", i; //*2 7643 for (i =1; i<=maxcols;i++) { 7644 tmpl += tdtmpl; 7645 } 7646 if(rowid !== '_empty') { 7647 ind = $(obj).jqGrid("getInd",rowid); 7648 } 7649 $(obj.p.colModel).each( function(i) { 7650 nm = this.name; 7651 // hidden fields are included in the form 7652 if(this.editrules && this.editrules.edithidden === true) { 7653 hc = false; 7654 } else { 7655 hc = this.hidden === true ? true : false; 7656 } 7657 dc = hc ? "style='display:none'" : ""; 7658 if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') { 7659 if(ind === false) { 7660 tmp = ""; 7661 } else { 7662 if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) { 7663 tmp = $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text(); 7664 } else { 7665 try { 7666 tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i); 7667 } catch (_) { 7668 tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html(); 7669 } 7670 if(!tmp || tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';} 7671 } 7672 } 7673 var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm, rowId: rowid}), 7674 frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}), 7675 rp = parseInt(frmopt.rowpos,10) || cnt+1, 7676 cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10); 7677 if(rowid === "_empty" && opt.defaultValue ) { 7678 tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue; 7679 } 7680 if(!this.edittype) {this.edittype = "text";} 7681 if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);} 7682 elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {})); 7683 //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");} 7684 //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();} 7685 if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;} 7686 $(elc).addClass("FormElement"); 7687 if( $.inArray(this.edittype, ['text','textarea','password','select']) > -1) { 7688 $(elc).addClass("ui-widget-content ui-corner-all"); 7689 } 7690 trdata = $(tb).find("tr[rowpos="+rp+"]"); 7691 if(frmopt.rowabove) { 7692 var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>"); 7693 $(tb).append(newdata); 7694 newdata[0].rp = rp; 7695 } 7696 if ( trdata.length===0 ) { 7697 trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm); 7698 $(trdata).append(tmpl); 7699 $(tb).append(trdata); 7700 trdata[0].rp = rp; 7701 } 7702 $("td:eq("+(cp-2)+")",trdata[0]).html(frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label); 7703 $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix); 7704 if(this.edittype==='custom' && $.isFunction(opt.custom_value) ) { 7705 opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp); 7706 } 7707 $.jgrid.bindEv.call($t, elc, opt); 7708 retpos[cnt] = i; 7709 cnt++; 7710 } 7711 }); 7712 if( cnt > 0) { 7713 var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='"+obj.p.id+"_id' value='"+rowid+"'/></td></tr>"); 7714 idrow[0].rp = cnt+999; 7715 $(tb).append(idrow); 7716 if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;} 7717 } 7718 return retpos; 7719 } 7720 function fillData(rowid,obj,fmid){ 7721 var nm,cnt=0,tmp, fld,opt,vl,vlc; 7722 if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData = {};rp_ge[$t.p.id]._savedData[obj.p.id+"_id"]=rowid;} 7723 var cm = obj.p.colModel; 7724 if(rowid === '_empty') { 7725 $(cm).each(function(){ 7726 nm = this.name; 7727 opt = $.extend({}, this.editoptions || {} ); 7728 fld = $("#"+$.jgrid.jqID(nm),"#"+fmid); 7729 if(fld && fld.length && fld[0] !== null) { 7730 vl = ""; 7731 if(this.edittype === 'custom' && $.isFunction(opt.custom_value)) { 7732 opt.custom_value.call($t, $("#"+nm,"#"+fmid),'set',vl); 7733 } else if(opt.defaultValue ) { 7734 vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue; 7735 if(fld[0].type==='checkbox') { 7736 vlc = vl.toLowerCase(); 7737 if(vlc.search(/(false|f|0|no|n|off|undefined)/i)<0 && vlc!=="") { 7738 fld[0].checked = true; 7739 fld[0].defaultChecked = true; 7740 fld[0].value = vl; 7741 } else { 7742 fld[0].checked = false;
7743 fld[0].defaultChecked = false; 7744 } 7745 } else {fld.val(vl);} 7746 } else { 7747 if( fld[0].type==='checkbox' ) { 7748 fld[0].checked = false; 7749 fld[0].defaultChecked = false; 7750 vl = $(fld).attr("offval"); 7751 } else if (fld[0].type && fld[0].type.substr(0,6)==='select') { 7752 fld[0].selectedIndex = 0; 7753 } else { 7754 fld.val(vl); 7755 } 7756 } 7757 if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;} 7758 } 7759 }); 7760 $("#id_g","#"+fmid).val(rowid); 7761 return; 7762 } 7763 var tre = $(obj).jqGrid("getInd",rowid,true); 7764 if(!tre) {return;} 7765 $('td[role="gridcell"]',tre).each( function(i) { 7766 nm = cm[i].name; 7767 // hidden fields are included in the form 7768 if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) { 7769 if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) { 7770 tmp = $(this).text(); 7771 } else { 7772 try { 7773 tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i); 7774 } catch (_) { 7775 tmp = cm[i].edittype==="textarea" ? $(this).text() : $(this).html(); 7776 } 7777 } 7778 if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);} 7779 if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;} 7780 nm = $.jgrid.jqID(nm); 7781 switch (cm[i].edittype) { 7782 case "password": 7783 case "text": 7784 case "button" : 7785 case "image": 7786 case "textarea": 7787 if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';} 7788 $("#"+nm,"#"+fmid).val(tmp); 7789 break; 7790 case "select": 7791 var opv = tmp.split(","); 7792 opv = $.map(opv,function(n){return $.trim(n);}); 7793 $("#"+nm+" option","#"+fmid).each(function(){ 7794 if (!cm[i].editoptions.multiple && ($.trim(tmp) === $.trim($(this).text()) || opv[0] === $.trim($(this).text()) || opv[0] === $.trim($(this).val())) ){ 7795 this.selected= true; 7796 } else if (cm[i].editoptions.multiple){ 7797 if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){ 7798 this.selected = true; 7799 }else{ 7800 this.selected = false; 7801 } 7802 } else { 7803 this.selected = false; 7804 } 7805 }); 7806 break; 7807 case "checkbox": 7808 tmp = String(tmp); 7809 if(cm[i].editoptions && cm[i].editoptions.value) { 7810 var cb = cm[i].editoptions.value.split(":"); 7811 if(cb[0] === tmp) { 7812 $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":true, "defaultChecked" : true}); 7813 } else { 7814 $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":false, "defaultChecked" : false}); 7815 } 7816 } else { 7817 tmp = tmp.toLowerCase(); 7818 if(tmp.search(/(false|f|0|no|n|off|undefined)/i)<0 && tmp!=="") { 7819 $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true); 7820 $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie 7821 } else { 7822 $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false); 7823 $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie 7824 } 7825 } 7826 break; 7827 case 'custom' : 7828 try { 7829 if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) { 7830 cm[i].editoptions.custom_value.call($t, $("#"+nm,"#"+fmid),'set',tmp); 7831 } else {throw "e1";} 7832 } catch (e) { 7833 if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);} 7834 else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);} 7835 } 7836 break; 7837 } 7838 cnt++; 7839 } 7840 }); 7841 if(cnt>0) {$("#id_g",frmtb).val(rowid);} 7842 } 7843 function setNulls() { 7844 $.each($t.p.colModel, function(i,n){ 7845 if(n.editoptions && n.editoptions.NullIfEmpty === true) { 7846 if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") { 7847 postdata[n.name] = 'null';
7848 } 7849 } 7850 }); 7851 } 7852 function postIt() { 7853 var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i; 7854 7855 var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [$("#"+frmgr), frmoper]); 7856 if(retvals && typeof retvals === 'object') {postdata = retvals;} 7857 7858 if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) { 7859 retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata,$("#"+frmgr),frmoper); 7860 if(retvals && typeof retvals === 'object') {postdata = retvals;} 7861 } 7862 for( key in postdata ){ 7863 if(postdata.hasOwnProperty(key)) { 7864 ret = $.jgrid.checkValues.call($t,postdata[key],key); 7865 if(ret[0] === false) {break;} 7866 } 7867 } 7868 setNulls(); 7869 if(ret[0]) { 7870 onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]); 7871 if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) { 7872 onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata, frmoper) || {}; 7873 } 7874 ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $("#"+frmgr), frmoper]); 7875 if(ret === undefined) { 7876 ret = [true,"",""]; 7877 } 7878 if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) { 7879 ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$("#"+frmgr), frmoper); 7880 } 7881 } 7882 7883 if(ret[0] && !rp_ge[$t.p.id].processing) { 7884 rp_ge[$t.p.id].processing = true; 7885 $("#sData", frmtb+"_2").addClass('ui-state-active'); 7886 oper = opers.oper; 7887 idname = opers.id; 7888 // we add to pos data array the action - the name is oper 7889 postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) === "_empty") ? opers.addoper : opers.editoper; 7890 if(postdata[oper] !== opers.addoper) { 7891 postdata[idname] = postdata[$t.p.id+"_id"]; 7892 } else { 7893 // check to see if we have allredy this field in the form and if yes lieve it 7894 if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];} 7895 } 7896 delete postdata[$t.p.id+"_id"]; 7897 postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS); 7898 if($t.p.treeGrid === true) { 7899 if(postdata[oper] === opers.addoper) { 7900 selr = $($t).jqGrid("getGridParam", 'selrow'); 7901 var tr_par_id = $t.p.treeGridModel === 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id'; 7902 postdata[tr_par_id] = selr; 7903 } 7904 for(i in $t.p.treeReader){ 7905 if($t.p.treeReader.hasOwnProperty(i)) { 7906 var itm = $t.p.treeReader[i]; 7907 if(postdata.hasOwnProperty(itm)) { 7908 if(postdata[oper] === opers.addoper && i === 'parent_id_field') {continue;} 7909 delete postdata[itm]; 7910 } 7911 } 7912 } 7913 } 7914 7915 postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]); 7916 var ajaxOptions = $.extend({ 7917 url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'), 7918 type: rp_ge[$t.p.id].mtype, 7919 data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata, 7920 complete:function(data,status){ 7921 var key; 7922 postdata[idname] = $t.p.idPrefix + postdata[idname]; 7923 if(data.status >= 300 && data.status !== 304) { 7924 ret[0] = false; 7925 ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]); 7926 if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) { 7927 ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data, frmoper); 7928 } else { 7929 ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status; 7930 } 7931 } else { 7932 // data is posted successful 7933 // execute aftersubmit with the returned data from server 7934 ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]); 7935 if(ret === undefined) { 7936 ret = [true,"",""]; 7937 } 7938 if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) { 7939 ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata, frmoper); 7940 } 7941 } 7942 if(ret[0] === false) { 7943 $("#FormError>td",frmtb).html(ret[1]); 7944 $("#FormError",frmtb).show(); 7945 } else { 7946 if($t.p.autoencode) { 7947 $.each(postdata,function(n,v){ 7948 postdata[n] = $.jgrid.htmlDecode(v); 7949 }); 7950 } 7951 //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local"; 7952 // the action is add 7953 if(postdata[oper] === opers.addoper ) { 7954 //id processing 7955 // user not set the id ret[2] 7956 if(!ret[2]) {ret[2] = $.jgrid.randId();} 7957 postdata[idname] = ret[2]; 7958 if(rp_ge[$t.p.id].reloadAfterSubmit) { 7959 $($t).trigger("reloadGrid"); 7960 } else { 7961 if($t.p.treeGrid === true){ 7962 $($t).jqGrid("addChildNode",ret[2],selr,postdata ); 7963 } else { 7964 $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); 7965 } 7966 } 7967 if(rp_ge[$t.p.id].closeAfterAdd) { 7968 if($t.p.treeGrid !== true){ 7969 $($t).jqGrid("setSelection",ret[2]); 7970 } 7971 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); 7972 } else if (rp_ge[$t.p.id].clearAfterAdd) { 7973 fillData("_empty",$t,frmgr); 7974 } 7975 } else { 7976 // the action is update 7977 if(rp_ge[$t.p.id].reloadAfterSubmit) { 7978 $($t).trigger("reloadGrid"); 7979 if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);} 7980 } else { 7981 if($t.p.treeGrid === true) { 7982 $($t).jqGrid("setTreeRow", postdata[idname],postdata); 7983 } else { 7984 $($t).jqGrid("setRowData", postdata[idname],postdata); 7985 } 7986 } 7987 if(rp_ge[$t.p.id].closeAfterEdit) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});} 7988 } 7989 if($.isFunction(rp_ge[$t.p.id].afterComplete)) { 7990 copydata = data; 7991 setTimeout(function(){ 7992 $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $("#"+frmgr), frmoper]); 7993 rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $("#"+frmgr), frmoper); 7994 copydata=null; 7995 },500); 7996 } 7997 if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
7998 $("#"+frmgr).data("disabled",false); 7999 if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !== "_empty"){ 8000 for(key in rp_ge[$t.p.id]._savedData) { 8001 if(rp_ge[$t.p.id]._savedData.hasOwnProperty(key) && postdata[key]) { 8002 rp_ge[$t.p.id]._savedData[key] = postdata[key]; 8003 } 8004 } 8005 } 8006 } 8007 } 8008 rp_ge[$t.p.id].processing=false; 8009 $("#sData", frmtb+"_2").removeClass('ui-state-active'); 8010 try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){} 8011 } 8012 }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions ); 8013 8014 if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) { 8015 if ($.isFunction($t.p.dataProxy)) { 8016 rp_ge[$t.p.id].useDataProxy = true; 8017 } else { 8018 ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl; 8019 } 8020 } 8021 if (ret[0]) { 8022 if (rp_ge[$t.p.id].useDataProxy) { 8023 var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id); 8024 if(dpret === undefined) { 8025 dpret = [true, ""]; 8026 } 8027 if(dpret[0] === false ) { 8028 ret[0] = false; 8029 ret[1] = dpret[1] || "Error deleting the selected row!" ; 8030 } else { 8031 if(ajaxOptions.data.oper === opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) { 8032 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); 8033 } 8034 if(ajaxOptions.data.oper === opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) { 8035 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); 8036 } 8037 } 8038 } else { 8039 if(ajaxOptions.url === "clientArray") { 8040 postdata = ajaxOptions.data; 8041 ajaxOptions.complete({status:200, statusText:''},''); 8042 } else { 8043 $.ajax(ajaxOptions); 8044 } 8045 } 8046 } 8047 } 8048 if(ret[0] === false) { 8049 $("#FormError>td",frmtb).html(ret[1]); 8050 $("#FormError",frmtb).show(); 8051 // return; 8052 } 8053 } 8054 function compareData(nObj, oObj ) { 8055 var ret = false,key; 8056 for (key in nObj) { 8057 if(nObj.hasOwnProperty(key) && nObj[key] != oObj[key]) { 8058 ret = true; 8059 break; 8060 } 8061 } 8062 return ret; 8063 } 8064 function checkUpdates () { 8065 var stat = true; 8066 $("#FormError",frmtb).hide(); 8067 if(rp_ge[$t.p.id].checkOnUpdate) { 8068 postdata = {}; 8069 getFormData(); 8070 diff = compareData(postdata,rp_ge[$t.p.id]._savedData); 8071 if(diff) { 8072 $("#"+frmgr).data("disabled",true); 8073 $(".confirm","#"+IDs.themodal).show(); 8074 stat = false; 8075 } 8076 } 8077 return stat; 8078 } 8079 function restoreInline() 8080 { 8081 var i; 8082 if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) { 8083 for (i=0;i<$t.p.savedRow.length;i++) { 8084 if ($t.p.savedRow[i].id == rowid) { 8085 $($t).jqGrid('restoreRow',rowid); 8086 break; 8087 } 8088 } 8089 } 8090 } 8091 function updateNav(cr, posarr){ 8092 var totr = posarr[1].length-1; 8093 if (cr===0) { 8094 $("#pData",frmtb+"_2").addClass('ui-state-disabled'); 8095 } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) { 8096 $("#pData",frmtb+"_2").addClass('ui-state-disabled'); 8097 } else { 8098 $("#pData",frmtb+"_2").removeClass('ui-state-disabled'); 8099 } 8100 8101 if (cr===totr) { 8102 $("#nData",frmtb+"_2").addClass('ui-state-disabled'); 8103 } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) { 8104 $("#nData",frmtb+"_2").addClass('ui-state-disabled'); 8105 } else { 8106 $("#nData",frmtb+"_2").removeClass('ui-state-disabled'); 8107 } 8108 } 8109 function getCurrPos() { 8110 var rowsInGrid = $($t).jqGrid("getDataIDs"), 8111 selrow = $("#id_g",frmtb).val(), 8112 pos = $.inArray(selrow,rowsInGrid); 8113 return [pos,rowsInGrid]; 8114 } 8115 8116 var dh = isNaN(rp_ge[$(this)[0].p.id].dataheight) ? rp_ge[$(this)[0].p.id].dataheight : rp_ge[$(this)[0].p.id].dataheight+"px", 8117 dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px", 8118 frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>
8118").data("disabled",false), 8119 tbl = $("<table id='"+frmtborg+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"); 8120 $($t.p.colModel).each( function() { 8121 var fmto = this.formoptions; 8122 maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 ); 8123 maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 ); 8124 }); 8125 $(frm).append(tbl); 8126 var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>"); 8127 flr[0].rp = 0; 8128 $(tbl).append(flr); 8129 //topinfo 8130 flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge[$t.p.id].topinfo+"</td></tr>"); 8131 flr[0].rp = 0; 8132 $(tbl).append(flr); 8133 showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [frm, frmoper]); 8134 if(showFrm === undefined) { 8135 showFrm = true; 8136 } 8137 if(showFrm && onBeforeInit) { 8138 showFrm = onBeforeInit.call($t,frm, frmoper); 8139 } 8140 if(showFrm === false) {return;} 8141 restoreInline(); 8142 // set the id. 8143 // use carefull only to change here colproperties. 8144 // create data 8145 var rtlb = $t.p.direction === "rtl" ? true :false, 8146 bp = rtlb ? "nData" : "pData", 8147 bn = rtlb ? "pData" : "nData"; 8148 createData(rowid,$t,tbl,maxCols); 8149 // buttons at footer 8150 var bP = "<a id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>", 8151 bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>", 8152 bS ="<a id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
8153 bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>"; 8154 var bt = "<table border='0' cellspacing='0' cellpadding='0' class='EditTable' id='"+frmtborg+"_2'><tbody><tr><td colspan='2'><hr class='ui-widget-content' style='margin:1px'/></td></tr><tr id='Act_Buttons'><td class='navButton'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton'>"+bS+bC+"</td></tr>"; 8155 bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>"; 8156 bt += "</tbody></table>"; 8157 if(maxRows > 0) { 8158 var sd=[]; 8159 $.each($(tbl)[0].rows,function(i,r){ 8160 sd[i] = r; 8161 }); 8162 sd.sort(function(a,b){ 8163 if(a.rp > b.rp) {return 1;} 8164 if(a.rp < b.rp) {return -1;} 8165 return 0; 8166 }); 8167 $.each(sd, function(index, row) { 8168 $('tbody',tbl).append(row); 8169 }); 8170 } 8171 p.gbox = "#gbox_"+$.jgrid.jqID(gID); 8172 var cle = false; 8173 if(p.closeOnEscape===true){ 8174 p.closeOnEscape = false; 8175 cle = true; 8176 } 8177 var tms = $("<div></div>").append(frm).append(bt); 8178 $.jgrid.createModal(IDs,tms, rp_ge[$(this)[0].p.id] ,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]); 8179 if(rtlb) { 8180 $("#pData, #nData",frmtb+"_2").css("float","right"); 8181 $(".EditButton",frmtb+"_2").css("text-align","left"); 8182 } 8183 if(rp_ge[$t.p.id].topinfo) {$(".tinfo",frmtb).show();} 8184 if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmtb+"_2").show();} 8185 tms = null;bt=null; 8186 $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) { 8187 var wkey = e.target; 8188 if ($("#"+frmgr).data("disabled")===true ) {return false;}//?? 8189 if(rp_ge[$t.p.id].savekey[0] === true && e.which === rp_ge[$t.p.id].savekey[1]) { // save 8190 if(wkey.tagName !== "TEXTAREA") { 8191 $("#sData", frmtb+"_2").trigger("click"); 8192 return false; 8193 } 8194 } 8195 if(e.which === 27) { 8196 if(!checkUpdates()) {return false;} 8197 if(cle) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});} 8198 return false; 8199 } 8200 if(rp_ge[$t.p.id].navkeys[0]===true) { 8201 if($("#id_g",frmtb).val() === "_empty") {return true;} 8202 if(e.which === rp_ge[$t.p.id].navkeys[1]){ //up 8203 $("#pData", frmtb+"_2").trigger("click"); 8204 return false; 8205 } 8206 if(e.which === rp_ge[$t.p.id].navkeys[2]){ //down 8207 $("#nData", frmtb+"_2").trigger("click"); 8208 return false; 8209 } 8210 } 8211 }); 8212 if(p.checkOnUpdate) { 8213 $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose"); 8214 $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).unbind("click") 8215 .click(function(){ 8216 if(!checkUpdates()) {return false;} 8217 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); 8218 return false; 8219 }); 8220 } 8221 p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon); 8222 p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon); 8223 // beforeinitdata after creation of the form 8224 if(p.saveicon[0]===true) { 8225 $("#sData",frmtb+"_2").addClass(p.saveicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') 8226 .append("<span class='ui-icon "+p.saveicon[2]+"'></span>"); 8227 } 8228 if(p.closeicon[0]===true) { 8229 $("#cData",frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') 8230 .append("<span class='ui-icon "+p.closeicon[2]+"'></span>"); 8231 } 8232 if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) { 8233 bS ="<a id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>"; 8234 bN ="<a id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>"; 8235 bC ="<a id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>"; 8236 var zI = p.zIndex || 999;zI ++; 8237 $("<div class='"+ p.overlayClass+" jqgrid-overlay confirm' style='z-index:"+zI+";display:none;'> "+"</div><div class='confirm ui-widget-content ui-jqconfirm' style='z-index:"+(zI+1)+"'>"+p.saveData+"<br/><br/>"+bS+bN+bC+"</div>").insertAfter("#"+frmgr); 8238 $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){ 8239 postIt();
8240 $("#"+frmgr).data("disabled",false); 8241 $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide(); 8242 return false; 8243 }); 8244 $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){ 8245 $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide(); 8246 $("#"+frmgr).data("disabled",false); 8247 setTimeout(function(){$(":input:visible","#"+frmgr)[0].focus();},0); 8248 return false; 8249 }); 8250 $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){ 8251 $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide(); 8252 $("#"+frmgr).data("disabled",false); 8253 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); 8254 return false; 8255 }); 8256 } 8257 // here initform - only once 8258 $($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]); 8259 if(onInitializeForm) {onInitializeForm.call($t,$("#"+frmgr), frmoper);} 8260 if(rowid==="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();} 8261 $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]); 8262 if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr), frmoper);} 8263 $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose); 8264 $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{ 8265 gbox:"#gbox_"+$.jgrid.jqID(gID), 8266 jqm:p.jqModal, 8267 overlay: p.overlay, 8268 modal:p.modal, 8269 overlayClass: p.overlayClass, 8270 onHide : function(h) { 8271 var fh = $('#editmod'+gID)[0].style.height; 8272 if(fh.indexOf("px") > -1 ) { 8273 fh = parseFloat(fh); 8274 } 8275 $($t).data("formProp", { 8276 top:parseFloat($(h.w).css("top")), 8277 left : parseFloat($(h.w).css("left")), 8278 width : $(h.w).width(), 8279 height : fh, 8280 dataheight : $("#"+frmgr).height(), 8281 datawidth: $("#"+frmgr).width() 8282 }); 8283 h.w.remove(); 8284 if(h.o) {h.o.remove();} 8285 } 8286 }); 8287 if(!closeovrl) { 8288 $("." + $.jgrid.jqID(p.overlayClass)).click(function(){ 8289 if(!checkUpdates()) {return false;} 8290 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); 8291 return false; 8292 }); 8293 } 8294 $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover( 8295 function(){$(this).addClass('ui-state-hover');}, 8296 function(){$(this).removeClass('ui-state-hover');} 8297 ); 8298 $("#sData", frmtb+"_2").click(function(){ 8299 postdata = {}; 8300 $("#FormError",frmtb).hide(); 8301 // all depend on ret array 8302 //ret[0] - succes 8303 //ret[1] - msg if not succes 8304 //ret[2] - the id that will be set if reload after submit false 8305 getFormData(); 8306 if(postdata[$t.p.id+"_id"] === "_empty") {postIt();} 8307 else if(p.checkOnSubmit===true ) { 8308 diff = compareData(postdata,rp_ge[$t.p.id]._savedData); 8309 if(diff) { 8310 $("#"+frmgr).data("disabled",true); 8311 $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show(); 8312 } else { 8313 postIt(); 8314 } 8315 } else { 8316 postIt(); 8317 } 8318 return false; 8319 }); 8320 $("#cData", frmtb+"_2").click(function(){ 8321 if(!checkUpdates()) {return false;} 8322 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); 8323 return false; 8324 }); 8325 $("#nData", frmtb+"_2").click(function(){ 8326 if(!checkUpdates()) {return false;} 8327 $("#FormError",frmtb).hide(); 8328 var npos = getCurrPos(); 8329 npos[0] = parseInt(npos[0],10); 8330 if(npos[0] !== -1 && npos[1][npos[0]+1]) { 8331 $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]); 8332 var nposret; 8333 if($.isFunction(p.onclickPgButtons)) { 8334 nposret = p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]); 8335 if( nposret !== undefined && nposret === false ) {return false;} 8336 } 8337 if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass('ui-state-disabled')) {return false;} 8338 fillData(npos[1][npos[0]+1],$t,frmgr); 8339 $($t).jqGrid("setSelection",npos[1][npos[0]+1]); 8340 $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]); 8341 if($.isFunction(p.afterclickPgButtons)) { 8342 p.afterclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]+1]); 8343 } 8344 updateNav(npos[0]+1,npos); 8345 } 8346 return false;
8347 }); 8348 $("#pData", frmtb+"_2").click(function(){ 8349 if(!checkUpdates()) {return false;} 8350 $("#FormError",frmtb).hide(); 8351 var ppos = getCurrPos(); 8352 if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) { 8353 $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]); 8354 var pposret; 8355 if($.isFunction(p.onclickPgButtons)) { 8356 pposret = p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]); 8357 if( pposret !== undefined && pposret === false ) {return false;} 8358 } 8359 if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass('ui-state-disabled')) {return false;} 8360 fillData(ppos[1][ppos[0]-1],$t,frmgr); 8361 $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]); 8362 $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]); 8363 if($.isFunction(p.afterclickPgButtons)) { 8364 p.afterclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]-1]); 8365 } 8366 updateNav(ppos[0]-1,ppos); 8367 } 8368 return false; 8369 }); 8370 $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]); 8371 if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr), frmoper); } 8372 var posInit =getCurrPos(); 8373 updateNav(posInit[0],posInit); 8374 }); 8375 }, 8376 viewGridRow : function(rowid, p){ 8377 p = $.extend(true, { 8378 top : 0, 8379 left: 0, 8380 width: 0, 8381 datawidth: 'auto', 8382 height: 'auto', 8383 dataheight: 'auto', 8384 modal: false, 8385 overlay: 30, 8386 drag: true, 8387 resize: true, 8388 jqModal: true, 8389 closeOnEscape : false, 8390 labelswidth: '30%', 8391 closeicon: [], 8392 navkeys: [false,38,40], 8393 onClose: null, 8394 beforeShowForm : null, 8395 beforeInitData : null, 8396 viewPagerButtons : true, 8397 recreateForm : false 8398 }, $.jgrid.view, p || {}); 8399 rp_ge[$(this)[0].p.id] = p; 8400 return this.each(function(){ 8401 var $t = this; 8402 if (!$t.grid || !rowid) {return;} 8403 var gID = $t.p.id, 8404 frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ), 8405 frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID, 8406 IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr}, 8407 onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false, 8408 showFrm = true, 8409 maxCols = 1, maxRows=0; 8410 if(!p.recreateForm) { 8411 if( $($t).data("viewProp") ) { 8412 $.extend(rp_ge[$(this)[0].p.id], $($t).data("viewProp")); 8413 } 8414 } 8415 function focusaref(){ //Sfari 3 issues 8416 if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].navkeys[0]===true) { 8417 setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex", "-1").focus();},0); 8418 } 8419 } 8420 function createData(rowid,obj,tb,maxcols){ 8421 var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, i, 8422 tdtmpl = "<td class='CaptionTD form-view-label ui-widget-content' width='"+p.labelswidth+"'> </td><td class='DataTD form-view-data ui-helper-reset ui-widget-content'> </td>", tmpl="", 8423 tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'> </td><td class='DataTD form-view-data ui-widget-content'> </td>", 8424 fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld; 8425 for (i=1;i<=maxcols;i++) { 8426 tmpl += i === 1 ? tdtmpl : tdtmpl2; 8427 } 8428 // find max number align rigth with property formatter 8429 $(obj.p.colModel).each( function() { 8430 if(this.editrules && this.editrules.edithidden === true) { 8431 hc = false; 8432 } else { 8433 hc = this.hidden === true ? true : false; 8434 } 8435 if(!hc && this.align==='right') { 8436 if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) { 8437 max1 = Math.max(max1,parseInt(this.width,10)); 8438 } else { 8439 max2 = Math.max(max2,parseInt(this.width,10)); 8440 } 8441 } 8442 }); 8443 maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0; 8444 ind = $(obj).jqGrid("getInd",rowid); 8445 $(obj.p.colModel).each( function(i) { 8446 nm = this.name; 8447 setme = false; 8448 // hidden fields are included in the form 8449 if(this.editrules && this.editrules.edithidden === true) { 8450 hc = false; 8451 } else { 8452 hc = this.hidden === true ? true : false;
8453 } 8454 dc = hc ? "style='display:none'" : ""; 8455 viewfld = (typeof this.viewable !== 'boolean') ? true : this.viewable; 8456 if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) { 8457 if(ind === false) { 8458 tmp = ""; 8459 } else { 8460 if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) { 8461 tmp = $("td:eq("+i+")",obj.rows[ind]).text(); 8462 } else { 8463 tmp = $("td:eq("+i+")",obj.rows[ind]).html(); 8464 } 8465 } 8466 setme = this.align === 'right' && maxw !==0 ? true : false; 8467 var frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}), 8468 rp = parseInt(frmopt.rowpos,10) || cnt+1, 8469 cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10); 8470 if(frmopt.rowabove) { 8471 var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>"); 8472 $(tb).append(newdata); 8473 newdata[0].rp = rp; 8474 } 8475 trdata = $(tb).find("tr[rowpos="+rp+"]"); 8476 if ( trdata.length===0 ) { 8477 trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm); 8478 $(trdata).append(tmpl); 8479 $(tb).append(trdata); 8480 trdata[0].rp = rp; 8481 } 8482 $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label)+'</b>'); 8483 $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm); 8484 if(setme){ 8485 $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"}); 8486 } 8487 retpos[cnt] = i; 8488 cnt++; 8489 } 8490 }); 8491 if( cnt > 0) { 8492 var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='id' value='"+rowid+"'/></td></tr>"); 8493 idrow[0].rp = cnt+99; 8494 $(tb).append(idrow); 8495 } 8496 return retpos; 8497 } 8498 function fillData(rowid,obj){
8499 var nm, hc,cnt=0,tmp,trv; 8500 trv = $(obj).jqGrid("getInd",rowid,true); 8501 if(!trv) {return;} 8502 $('td',trv).each( function(i) { 8503 nm = obj.p.colModel[i].name; 8504 // hidden fields are included in the form 8505 if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) { 8506 hc = false; 8507 } else { 8508 hc = obj.p.colModel[i].hidden === true ? true : false; 8509 } 8510 if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') { 8511 if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) { 8512 tmp = $(this).text(); 8513 } else { 8514 tmp = $(this).html(); 8515 } 8516 nm = $.jgrid.jqID("v_"+nm); 8517 $("#"+nm+" span","#"+frmtb).html(tmp); 8518 if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();} 8519 cnt++; 8520 } 8521 }); 8522 if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);} 8523 } 8524 function updateNav(cr,posarr){ 8525 var totr = posarr[1].length-1; 8526 if (cr===0) { 8527 $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled'); 8528 } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) { 8529 $("#pData",frmtb+"_2").addClass('ui-state-disabled'); 8530 } else { 8531 $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled'); 8532 } 8533 if (cr===totr) { 8534 $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled'); 8535 } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) { 8536 $("#nData",frmtb+"_2").addClass('ui-state-disabled'); 8537 } else { 8538 $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled'); 8539 } 8540 } 8541 function getCurrPos() { 8542 var rowsInGrid = $($t).jqGrid("getDataIDs"), 8543 selrow = $("#id_g","#"+frmtb).val(), 8544 pos = $.inArray(selrow,rowsInGrid); 8545 return [pos,rowsInGrid]; 8546 } 8547 8548 var dh = isNaN(rp_ge[$(this)[0].p.id].dataheight) ? rp_ge[$(this)[0].p.id].dataheight : rp_ge[$(this)[0].p.id].dataheight+"px", 8549 dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px", 8550 frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>"), 8551 tbl =$("<table id='"+frmtb_id+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>"); 8552 $($t.p.colModel).each( function() { 8553 var fmto = this.formoptions; 8554 maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 ); 8555 maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 ); 8556 }); 8557 // set the id. 8558 $(frm).append(tbl); 8559 if(onBeforeInit) { 8560 showFrm = onBeforeInit.call($t, frm ); 8561 if(showFrm === undefined) { 8562 showFrm = true; 8563 } 8564 } 8565 if(showFrm === false) {return;} 8566 createData(rowid, $t, tbl, maxCols); 8567 var rtlb = $t.p.direction === "rtl" ? true :false, 8568 bp = rtlb ? "nData" : "pData", 8569 bn = rtlb ? "pData" : "nData", 8570 // buttons at footer 8571 bP = "<a id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>", 8572 bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
8573 bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>"; 8574 if(maxRows > 0) { 8575 var sd=[]; 8576 $.each($(tbl)[0].rows,function(i,r){ 8577 sd[i] = r; 8578 }); 8579 sd.sort(function(a,b){ 8580 if(a.rp > b.rp) {return 1;} 8581 if(a.rp < b.rp) {return -1;} 8582 return 0; 8583 }); 8584 $.each(sd, function(index, row) { 8585 $('tbody',tbl).append(row); 8586 }); 8587 } 8588 p.gbox = "#gbox_"+$.jgrid.jqID(gID); 8589 var bt = $("<div></div>").append(frm).append("<table border='0' class='EditTable' id='"+frmtb+"_2'><tbody><tr id='Act_Buttons'><td class='navButton' width='"+p.labelswidth+"'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton'>"+bC+"</td></tr></tbody></table>"); 8590 $.jgrid.createModal(IDs,bt,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]); 8591 if(rtlb) { 8592 $("#pData, #nData","#"+frmtb+"_2").css("float","right"); 8593 $(".EditButton","#"+frmtb+"_2").css("text-align","left"); 8594 } 8595 if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();} 8596 bt = null; 8597 $("#"+IDs.themodal).keydown( function( e ) { 8598 if(e.which === 27) { 8599 if(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose});} 8600 return false; 8601 } 8602 if(p.navkeys[0]===true) { 8603 if(e.which === p.navkeys[1]){ //up 8604 $("#pData", "#"+frmtb+"_2").trigger("click"); 8605 return false; 8606 } 8607 if(e.which === p.navkeys[2]){ //down 8608 $("#nData", "#"+frmtb+"_2").trigger("click"); 8609 return false; 8610 } 8611 } 8612 }); 8613 p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon); 8614 if(p.closeicon[0]===true) { 8615 $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') 8616 .append("<span class='ui-icon "+p.closeicon[2]+"'></span>"); 8617 } 8618 if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));} 8619 $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{ 8620 gbox:"#gbox_"+$.jgrid.jqID(gID), 8621 jqm:p.jqModal, 8622 overlay: p.overlay, 8623 modal:p.modal, 8624 onHide : function(h) { 8625 $($t).data("viewProp", { 8626 top:parseFloat($(h.w).css("top")), 8627 left : parseFloat($(h.w).css("left")), 8628 width : $(h.w).width(), 8629 height : $(h.w).height(), 8630 dataheight : $("#"+frmgr).height(), 8631 datawidth: $("#"+frmgr).width() 8632 }); 8633 h.w.remove(); 8634 if(h.o) {h.o.remove();} 8635 } 8636 }); 8637 $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover( 8638 function(){$(this).addClass('ui-state-hover');}, 8639 function(){$(this).removeClass('ui-state-hover');} 8640 ); 8641 focusaref(); 8642 $("#cData", "#"+frmtb+"_2").click(function(){ 8643 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose}); 8644 return false; 8645 }); 8646 $("#nData", "#"+frmtb+"_2").click(function(){ 8647 $("#FormError","#"+frmtb).hide(); 8648 var npos = getCurrPos(); 8649 npos[0] = parseInt(npos[0],10); 8650 if(npos[0] !== -1 && npos[1][npos[0]+1]) { 8651 if($.isFunction(p.onclickPgButtons)) { 8652 p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]); 8653 } 8654 fillData(npos[1][npos[0]+1],$t); 8655 $($t).jqGrid("setSelection",npos[1][npos[0]+1]); 8656 if($.isFunction(p.afterclickPgButtons)) { 8657 p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]); 8658 } 8659 updateNav(npos[0]+1,npos); 8660 } 8661 focusaref(); 8662 return false; 8663 }); 8664 $("#pData", "#"+frmtb+"_2").click(function(){ 8665 $("#FormError","#"+frmtb).hide(); 8666 var ppos = getCurrPos(); 8667 if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) { 8668 if($.isFunction(p.onclickPgButtons)) { 8669 p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]); 8670 } 8671 fillData(ppos[1][ppos[0]-1],$t); 8672 $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]); 8673 if($.isFunction(p.afterclickPgButtons)) { 8674 p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]); 8675 } 8676 updateNav(ppos[0]-1,ppos); 8677 } 8678 focusaref(); 8679 return false; 8680 }); 8681 var posInit =getCurrPos(); 8682 updateNav(posInit[0],posInit); 8683 }); 8684 }, 8685 delGridRow : function(rowids,p) { 8686 p = $.extend(true, { 8687 top : 0, 8688 left: 0, 8689 width: 240, 8690 height: 'auto', 8691 dataheight : 'auto', 8692 modal: false, 8693 overlay: 30, 8694 drag: true, 8695 resize: true, 8696 url : '', 8697 mtype : "POST", 8698 reloadAfterSubmit: true, 8699 beforeShowForm: null, 8700 beforeInitData : null, 8701 afterShowForm: null, 8702 beforeSubmit: null, 8703 onclickSubmit: null, 8704 afterSubmit: null, 8705 jqModal : true, 8706 closeOnEscape : false, 8707 delData: {}, 8708 delicon : [], 8709 cancelicon : [], 8710 onClose : null, 8711 ajaxDelOptions : {}, 8712 processing : false, 8713 serializeDelData : null, 8714 useDataProxy : false 8715 }, $.jgrid.del, p ||{}); 8716 rp_ge[$(this)[0].p.id] = p; 8717 return this.each(function(){ 8718 var $t = this; 8719 if (!$t.grid ) {return;} 8720 if(!rowids) {return;} 8721 var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ), 8722 onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ), 8723 onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false, 8724 gID = $t.p.id, onCS = {}, 8725 showFrm = true, 8726 dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper, 8727 dtbl_id = "DelTbl_" + gID, 8728 IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl}; 8729 if ($.isArray(rowids)) {rowids = rowids.join();} 8730 if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) { 8731 if(onBeforeInit) { 8732 showFrm = onBeforeInit.call($t,$("#"+dtbl)); 8733 if(showFrm === undefined) { 8734 showFrm = true; 8735 } 8736 } 8737 if(showFrm === false) {return;} 8738 $("#DelData>td","#"+dtbl).text(rowids); 8739 $("#DelError","#"+dtbl).hide(); 8740 if( rp_ge[$t.p.id].processing === true) { 8741 rp_ge[$t.p.id].processing=false; 8742 $("#dData", "#"+dtbl).removeClass('ui-state-active'); 8743 } 8744 if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));} 8745 $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal,jqM: false, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal}); 8746 if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));} 8747 } else { 8748 var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px", 8749 dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px", 8750 tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'>"; 8751 tbl += "<table class='DelTable'><tbody>"; 8752 // error data 8753 tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>"; 8754 tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>"; 8755 tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td > </td></tr>"; 8756 // buttons at footer 8757 tbl += "</tbody></table></div>"; 8758 var bS = "<a id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>", 8759 bC = "<a id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>"; 8760 tbl += "<table cellspacing='0' cellpadding='0' border='0' class='EditTable' id='"+dtbl+"_2'><tbody><tr><td><hr class='ui-widget-content' style='margin:1px'/></td></tr><tr><td class='DelButton EditButton'>"+bS+" "+bC+"</td></tr></tbody></table>"; 8761 p.gbox = "#gbox_"+$.jgrid.jqID(gID); 8762 $.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]); 8763 8764 if(onBeforeInit) { 8765 showFrm = onBeforeInit.call($t,$(tbl)); 8766 if(showFrm === undefined) { 8767 showFrm = true; 8768 } 8769 } 8770 if(showFrm === false) {return;} 8771 8772 $(".fm-button","#"+dtbl+"_2").hover( 8773 function(){$(this).addClass('ui-state-hover');}, 8774 function(){$(this).removeClass('ui-state-hover');} 8775 ); 8776 p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon); 8777 p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon); 8778 if(p.delicon[0]===true) { 8779 $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') 8780 .append("<span class='ui-icon "+p.delicon[2]+"'></span>"); 8781 } 8782 if(p.cancelicon[0]===true) { 8783 $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') 8784 .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>"); 8785 } 8786 $("#dData","#"+dtbl+"_2").click(function(){ 8787 var ret=[true,""], pk, 8788 postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,... 8789 onCS = {}; 8790 if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};} 8791 if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata);} 8792 if(ret[0] && !rp_ge[$t.p.id].processing) { 8793 rp_ge[$t.p.id].processing = true; 8794 opers = $t.p.prmNames; 8795 postd = $.extend({},rp_ge[$t.p.id].delData, onCS); 8796 oper = opers.oper; 8797 postd[oper] = opers.deloper; 8798 idname = opers.id; 8799 postdata = String(postdata).split(","); 8800 if(!postdata.length) { return false; } 8801 for(pk in postdata) { 8802 if(postdata.hasOwnProperty(pk)) {
8803 postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]); 8804 } 8805 } 8806 postd[idname] = postdata.join(); 8807 $(this).addClass('ui-state-active'); 8808 var ajaxOptions = $.extend({ 8809 url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'), 8810 type: rp_ge[$t.p.id].mtype, 8811 data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd, 8812 complete:function(data,status){ 8813 var i; 8814 if(data.status >= 300 && data.status !== 304) { 8815 ret[0] = false; 8816 if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) { 8817 ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t,data); 8818 } else { 8819 ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status; 8820 } 8821 } else { 8822 // data is posted successful 8823 // execute aftersubmit with the returned data from server 8824 if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) { 8825 ret = rp_ge[$t.p.id].afterSubmit.call($t,data,postd); 8826 } 8827 } 8828 if(ret[0] === false) { 8829 $("#DelError>td","#"+dtbl).html(ret[1]); 8830 $("#DelError","#"+dtbl).show(); 8831 } else { 8832 if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype !== "local") { 8833 $($t).trigger("reloadGrid"); 8834 } else { 8835 if($t.p.treeGrid===true){ 8836 try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){} 8837 } else { 8838 for(i=0;i<postdata.length;i++) { 8839 $($t).jqGrid("delRowData",$t.p.idPrefix+ postdata[i]); 8840 } 8841 } 8842 $t.p.selrow = null; 8843 $t.p.selarrrow = []; 8844 } 8845 if($.isFunction(rp_ge[$t.p.id].afterComplete)) { 8846 setTimeout(function(){rp_ge[$t.p.id].afterComplete.call($t,data,postdata);},500); 8847 } 8848 } 8849 rp_ge[$t.p.id].processing=false; 8850 $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active'); 8851 if(ret[0]) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});} 8852 } 8853 }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions); 8854 8855 8856 if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) { 8857 if ($.isFunction($t.p.dataProxy)) { 8858 rp_ge[$t.p.id].useDataProxy = true; 8859 } else { 8860 ret[0]=false;
8860ret[1] += " "+$.jgrid.errors.nourl; 8861 } 8862 } 8863 if (ret[0]) { 8864 if (rp_ge[$t.p.id].useDataProxy) { 8865 var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id); 8866 if(dpret === undefined) { 8867 dpret = [true, ""]; 8868 } 8869 if(dpret[0] === false ) { 8870 ret[0] = false; 8871 ret[1] = dpret[1] || "Error deleting the selected row!" ; 8872 } else { 8873 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); 8874 } 8875 } 8876 else { 8877 if(ajaxOptions.url === "clientArray") { 8878 postd = ajaxOptions.data; 8879 ajaxOptions.complete({status:200, statusText:''},''); 8880 } else { 8881 $.ajax(ajaxOptions); 8882 } 8883 } 8884 } 8885 } 8886 8887 if(ret[0] === false) { 8888 $("#DelError>td","#"+dtbl).html(ret[1]); 8889 $("#DelError","#"+dtbl).show(); 8890 } 8891 return false; 8892 }); 8893 $("#eData", "#"+dtbl+"_2").click(function(){ 8894 $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, onClose: rp_ge[$t.p.id].onClose}); 8895 return false; 8896 }); 8897 if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));} 8898 $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal}); 8899 if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));} 8900 } 8901 if(rp_ge[$t.p.id].closeOnEscape===true) { 8902 setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex","-1").focus();},0); 8903 } 8904 }); 8905 }, 8906 navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) { 8907 o = $.extend({ 8908 edit: true, 8909 editicon: "ui-icon-pencil", 8910 add: true, 8911 addicon:"ui-icon-plus", 8912 del: true, 8913 delicon:"ui-icon-trash", 8914 search: true, 8915 searchicon:"ui-icon-search", 8916 refresh: true, 8917 refreshicon:"ui-icon-refresh", 8918 refreshstate: 'firstpage', 8919 view: false, 8920 viewicon : "ui-icon-document", 8921 position : "left", 8922 closeOnEscape : true, 8923 beforeRefresh : null, 8924 afterRefresh : null, 8925 cloneToTop : false, 8926 alertwidth : 200, 8927 alertheight : 'auto', 8928 alerttop: null, 8929 alertleft: null, 8930 alertzIndex : null 8931 }, $.jgrid.nav, o ||{}); 8932 return this.each(function() { 8933 if(this.nav) {return;} 8934 var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id}, 8935 $t = this, twd, tdw; 8936 if(!$t.grid || typeof elem !== 'string') {return;} 8937 if ($("#"+alertIDs.themodal)[0] === undefined) { 8938 if(!o.alerttop && !o.alertleft) { 8939 if (window.innerWidth !== undefined) { 8940 o.alertleft = window.innerWidth; 8941 o.alerttop = window.innerHeight; 8942 } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) { 8943 o.alertleft = document.documentElement.clientWidth; 8944 o.alerttop = document.documentElement.clientHeight; 8945 } else { 8946 o.alertleft=1024; 8947 o.alerttop=768; 8948 } 8949 o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2; 8950 o.alerttop = o.alerttop/2-25; 8951 } 8952 $.jgrid.createModal(alertIDs, 8953 "<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>", 8954 { 8955 gbox:"#gbox_"+$.jgrid.jqID($t.p.id), 8956 jqModal:true, 8957 drag:true, 8958 resize:true, 8959 caption:o.alertcap, 8960 top:o.alerttop, 8961 left:o.alertleft, 8962 width:o.alertwidth, 8963 height: o.alertheight, 8964 closeOnEscape:o.closeOnEscape, 8965 zIndex: o.alertzIndex 8966 }, 8967 "#gview_"+$.jgrid.jqID($t.p.id), 8968 $("#gbox_"+$.jgrid.jqID($t.p.id))[0], 8969 true 8970 ); 8971 } 8972 var clone = 1, i, 8973 onHoverIn = function () { 8974 if (!$(this).hasClass('ui-state-disabled')) { 8975 $(this).addClass("ui-state-hover"); 8976 } 8977 }, 8978 onHoverOut = function () { 8979 $(this).removeClass("ui-state-hover"); 8980 }; 8981 if(o.cloneToTop && $t.p.toppager) {clone = 2;} 8982 for(i = 0; i<clone; i++) { 8983 var tbd, 8984 navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"), 8985 sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>", 8986 pgid, elemids; 8987 if(i===0) { 8988 pgid = elem; 8989 elemids = $t.p.id; 8990 if(pgid === $t.p.toppager) { 8991 elemids += "_top"; 8992 clone = 1; 8993 } 8994 } else { 8995 pgid = $t.p.toppager; 8996 elemids = $t.p.id+"_top"; 8997 } 8998 if($t.p.direction === "rtl") {$(navtbl).attr("dir","rtl").css("float","right");} 8999 if (o.add) { 9000 pAdd = pAdd || {};
9001 tbd = $("<td class='ui-pg-button ui-corner-all'></td>"); 9002 $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>"); 9003 $("tr",navtbl).append(tbd); 9004 $(tbd,navtbl) 9005 .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids}) 9006 .click(function(){ 9007 if (!$(this).hasClass('ui-state-disabled')) { 9008 if ($.isFunction( o.addfunc )) { 9009 o.addfunc.call($t); 9010 } else { 9011 $($t).jqGrid("editGridRow","new",pAdd); 9012 } 9013 } 9014 return false; 9015 }).hover(onHoverIn, onHoverOut); 9016 tbd = null; 9017 } 9018 if (o.edit) { 9019 tbd = $("<td class='ui-pg-button ui-corner-all'></td>"); 9020 pEdit = pEdit || {}; 9021 $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>"); 9022 $("tr",navtbl).append(tbd); 9023 $(tbd,navtbl) 9024 .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids}) 9025 .click(function(){ 9026 if (!$(this).hasClass('ui-state-disabled')) { 9027 var sr = $t.p.selrow; 9028 if (sr) { 9029 if($.isFunction( o.editfunc ) ) { 9030 o.editfunc.call($t, sr); 9031 } else { 9032 $($t).jqGrid("editGridRow",sr,pEdit); 9033 } 9034 } else { 9035 $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true}); 9036 $("#jqg_alrt").focus(); 9037 } 9038 } 9039 return false; 9040 }).hover(onHoverIn, onHoverOut); 9041 tbd = null; 9042 } 9043 if (o.view) { 9044 tbd = $("<td class='ui-pg-button ui-corner-all'></td>"); 9045 pView = pView || {}; 9046 $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>"); 9047 $("tr",navtbl).append(tbd); 9048 $(tbd,navtbl) 9049 .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids}) 9050 .click(function(){ 9051 if (!$(this).hasClass('ui-state-disabled')) { 9052 var sr = $t.p.selrow; 9053 if (sr) { 9054 if($.isFunction( o.viewfunc ) ) { 9055 o.viewfunc.call($t, sr); 9056 } else { 9057 $($t).jqGrid("viewGridRow",sr,pView); 9058 } 9059 } else { 9060 $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true}); 9061 $("#jqg_alrt").focus(); 9062 } 9063 } 9064 return false; 9065 }).hover(onHoverIn, onHoverOut); 9066 tbd = null; 9067 } 9068 if (o.del) { 9069 tbd = $("<td class='ui-pg-button ui-corner-all'></td>"); 9070 pDel = pDel || {}; 9071 $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>"); 9072 $("tr",navtbl).append(tbd); 9073 $(tbd,navtbl) 9074 .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids}) 9075 .click(function(){ 9076 if (!$(this).hasClass('ui-state-disabled')) { 9077 var dr; 9078 if($t.p.multiselect) { 9079 dr = $t.p.selarrrow; 9080 if(dr.length===0) {dr = null;} 9081 } else { 9082 dr = $t.p.selrow; 9083 } 9084 if(dr){ 9085 if($.isFunction( o.delfunc )){ 9086 o.delfunc.call($t, dr); 9087 }else{ 9088 $($t).jqGrid("delGridRow",dr,pDel); 9089 } 9090 } else { 9091 $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus(); 9092 } 9093 } 9094 return false; 9095 }).hover(onHoverIn, onHoverOut); 9096 tbd = null; 9097 } 9098 if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);} 9099 if (o.search) { 9100 tbd = $("<td class='ui-pg-button ui-corner-all'></td>"); 9101 pSearch = pSearch || {}; 9102 $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>"); 9103 $("tr",navtbl).append(tbd); 9104 $(tbd,navtbl) 9105 .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids}) 9106 .click(function(){ 9107 if (!$(this).hasClass('ui-state-disabled')) { 9108 if($.isFunction( o.searchfunc )) { 9109 o.searchfunc.call($t, pSearch); 9110 } else { 9111 $($t).jqGrid("searchGrid",pSearch); 9112 } 9113 } 9114 return false; 9115 }).hover(onHoverIn, onHoverOut); 9116 if (pSearch.showOnLoad && pSearch.showOnLoad === true) { 9117 $(tbd,navtbl).click(); 9118 }
9119 tbd = null; 9120 } 9121 if (o.refresh) { 9122 tbd = $("<td class='ui-pg-button ui-corner-all'></td>"); 9123 $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>"); 9124 $("tr",navtbl).append(tbd); 9125 $(tbd,navtbl) 9126 .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids}) 9127 .click(function(){ 9128 if (!$(this).hasClass('ui-state-disabled')) { 9129 if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);} 9130 $t.p.search = false; 9131 $t.p.resetsearch = true; 9132 try { 9133 if( o.refreshstate !== 'currentfilter') { 9134 var gID = $t.p.id; 9135 $t.p.postData.filters =""; 9136 try { 9137 $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter'); 9138 } catch(ef) {} 9139 if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);} 9140 } 9141 } catch (e) {} 9142 switch (o.refreshstate) { 9143 case 'firstpage': 9144 $($t).trigger("reloadGrid", [{page:1}]); 9145 break; 9146 case 'current': 9147 case 'currentfilter': 9148 $($t).trigger("reloadGrid", [{current:true}]); 9149 break; 9150 } 9151 if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);} 9152 } 9153 return false; 9154 }).hover(onHoverIn, onHoverOut); 9155 tbd = null; 9156 } 9157 tdw = $(".ui-jqgrid").css("font-size") || "11px"; 9158 $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>"); 9159 twd = $(navtbl).clone().appendTo("#testpg2").width(); 9160 $("#testpg2").remove(); 9161 $(pgid+"_"+o.position,pgid).append(navtbl); 9162 if($t.p._nvtd) { 9163 if(twd > $t.p._nvtd[0] ) { 9164 $(pgid+"_"+o.position,pgid).width(twd); 9165 $t.p._nvtd[0] = twd; 9166 } 9167 $t.p._nvtd[1] = twd; 9168 } 9169 tdw =null;twd=null;navtbl =null; 9170 this.nav = true; 9171 } 9172 }); 9173 }, 9174 navButtonAdd : function (elem, p) { 9175 p = $.extend({ 9176 caption : "newButton", 9177 title: '', 9178 buttonicon : 'ui-icon-newwin', 9179 onClickButton: null, 9180 position : "last", 9181 cursor : 'pointer' 9182 }, p ||{}); 9183 return this.each(function() { 9184 if( !this.grid) {return;} 9185 if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);} 9186 var findnav = $(".navtable",elem)[0], $t = this; 9187 if (findnav) { 9188 if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined ) {return;} 9189 var tbd = $("<td></td>"); 9190 if(p.buttonicon.toString().toUpperCase() === "NONE") { 9191 $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>"); 9192 } else { 9193 $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>"); 9194 } 9195 if(p.id) {$(tbd).attr("id",p.id);} 9196 if(p.position==='first'){ 9197 if(findnav.rows[0].cells.length ===0 ) { 9198 $("tr",findnav).append(tbd); 9199 } else { 9200 $("tr td:eq(0)",findnav).before(tbd); 9201 } 9202 } else { 9203 $("tr",findnav).append(tbd); 9204 } 9205 $(tbd,findnav) 9206 .attr("title",p.title || "") 9207 .click(function(e){ 9208 if (!$(this).hasClass('ui-state-disabled')) { 9209 if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);} 9210 } 9211 return false; 9212 }) 9213 .hover( 9214 function () { 9215 if (!$(this).hasClass('ui-state-disabled')) { 9216 $(this).addClass('ui-state-hover'); 9217 } 9218 }, 9219 function () {$(this).removeClass("ui-state-hover");} 9220 ); 9221 } 9222 }); 9223 }, 9224 navSeparatorAdd:function (elem,p) { 9225 p = $.extend({ 9226 sepclass : "ui-separator", 9227 sepcontent: '', 9228 position : "last" 9229 }, p ||{}); 9230 return this.each(function() { 9231 if( !this.grid) {return;} 9232 if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);} 9233 var findnav = $(".navtable",elem)[0]; 9234 if(findnav) { 9235 var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>"; 9236 if (p.position === 'first') { 9237 if (findnav.rows[0].cells.length === 0) { 9238 $("tr", findnav).append(sep); 9239 } else { 9240 $("tr td:eq(0)", findnav).before(sep); 9241 } 9242 } else { 9243 $("tr", findnav).append(sep); 9244 } 9245 } 9246 }); 9247 }, 9248 GridToForm : function( rowid, formid ) { 9249 return this.each(function(){ 9250 var $t = this, i; 9251 if (!$t.grid) {return;} 9252 var rowdata = $($t).jqGrid("getRowData",rowid); 9253 if (rowdata) { 9254 for(i in rowdata) { 9255 if(rowdata.hasOwnProperty(i)) {
9256 if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) { 9257 $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() { 9258 if( $(this).val() == rowdata[i] ) { 9259 $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true); 9260 } else { 9261 $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false); 9262 } 9263 }); 9264 } else { 9265 // this is very slow on big table and form. 9266 $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]); 9267 } 9268 } 9269 } 9270 } 9271 }); 9272 }, 9273 FormToGrid : function(rowid, formid, mode, position){ 9274 return this.each(function() { 9275 var $t = this; 9276 if(!$t.grid) {return;} 9277 if(!mode) {mode = 'set';} 9278 if(!position) {position = 'first';} 9279 var fields = $(formid).serializeArray(); 9280 var griddata = {}; 9281 $.each(fields, function(i, field){ 9282 griddata[field.name] = field.value; 9283 }); 9284 if(mode==='add') {$($t).jqGrid("addRowData",rowid,griddata, position);} 9285 else if(mode==='set') {$($t).jqGrid("setRowData",rowid,griddata);} 9286 }); 9287 } 9288}); 9289})(jQuery); 9290/*jshint eqeqeq:false, eqnull:true, devel:true */ 9291/*global jQuery */ 9292(function($){ 9293/** 9294 * jqGrid extension for manipulating Grid Data 9295 * Tony Tomov [email protected] 9296 * http://trirand.com/blog/ 9297 * Dual licensed under the MIT and GPL licenses: 9298 * http://www.opensource.org/licenses/mit-license.php 9299 * http://www.gnu.org/licenses/gpl-2.0.html 9300**/ 9301"use strict"; 9302$.jgrid.inlineEdit = $.jgrid.inlineEdit || {}; 9303$.jgrid.extend({ 9304//Editing 9305 editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) { 9306 // Compatible mode old versions 9307 var o={}, args = $.makeArray(arguments).slice(1); 9308 9309 if( $.type(args[0]) === "object" ) { 9310 o = args[0]; 9311 } else { 9312 if (keys !== undefined) { o.keys = keys; } 9313 if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; } 9314 if ($.isFunction(successfunc)) { o.successfunc = successfunc; } 9315 if (url !== undefined) { o.url = url; } 9316 if (extraparam !== undefined) { o.extraparam = extraparam; } 9317 if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; } 9318 if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; } 9319 if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; } 9320 // last two not as param, but as object (sorry) 9321 //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; } 9322 //if (mtype !== undefined) { o.mtype = mtype || "POST"; } 9323 } 9324 o = $.extend(true, { 9325 keys : false, 9326 oneditfunc: null, 9327 successfunc: null, 9328 url: null, 9329 extraparam: {}, 9330 aftersavefunc: null, 9331 errorfunc: null, 9332 afterrestorefunc: null, 9333 restoreAfterError: true, 9334 mtype: "POST", 9335 focusField : true 9336 }, $.jgrid.inlineEdit, o ); 9337 9338 // End compatible 9339 return this.each(function(){ 9340 var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm, bfer; 9341 if (!$t.grid ) { return; } 9342 ind = $($t).jqGrid("getInd",rowid,true); 9343 if( ind === false ) {return;} 9344 bfer = $.isFunction( o.beforeEditRow ) ? o.beforeEditRow.call($t,o, rowid) : undefined; 9345 if( bfer === undefined ) { 9346 bfer = true; 9347 } 9348 if(!bfer) { return; } 9349 editable = $(ind).attr("editable") || "0"; 9350 if (editable === "0" && !$(ind).hasClass("not-editable-row")) { 9351 cm = $t.p.colModel; 9352 $('td[role="gridcell"]',ind).each( function(i) { 9353 nm = cm[i].name; 9354 var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn; 9355 if(treeg) { tmp = $("span:first",this).html();} 9356 else { 9357 try { 9358 tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i); 9359 } catch (_) { 9360 tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html(); 9361 } 9362 } 9363 if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') { 9364 if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); } 9365 svr[nm]=tmp; 9366 if(cm[i].editable===true) { 9367 if(focus===null) { focus = i; } 9368 if (treeg) { $("span:first",this).html(""); } 9369 else { $(this).html(""); } 9370 var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm,rowId:rowid}); 9371 if(!cm[i].edittype) { cm[i].edittype = "text"; } 9372 if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';} 9373 var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {})); 9374 $(elc).addClass("editable"); 9375 if(treeg) { $("span:first",this).append(elc); } 9376 else { $(this).append(elc); } 9377 $.jgrid.bindEv.call($t, elc, opt); 9378 //Again IE 9379 if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie) { 9380 $(elc).width($(elc).width()); 9381 } 9382 cnt++; 9383 } 9384 } 9385 }); 9386 if(cnt > 0) { 9387 svr.id = rowid; $t.p.savedRow.push(svr); 9388 $(ind).attr("editable","1"); 9389 if(o.focusField ) { 9390 if(typeof o.focusField === 'number' && parseInt(o.focusField,10) <= cm.length) { 9391 focus = o.focusField; 9392 } 9393 setTimeout(function(){ 9394 var fe = $("td:eq("+focus+") input",ind).not(":disabled"); 9395 if(fe.length > 0) { 9396 fe.focus(); 9397 } 9398 },0); 9399 } 9400 if(o.keys===true) { 9401 $(ind).bind("keydown",function(e) { 9402 if (e.keyCode === 27) { 9403 $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc); 9404 if($t.p._inlinenav) { 9405 try { 9406 $($t).jqGrid('showAddEditButtons'); 9407 } catch (eer1) {} 9408 } 9409 return false;
9410 } 9411 if (e.keyCode === 13) { 9412 var ta = e.target; 9413 if(ta.tagName === 'TEXTAREA') { return true; } 9414 if( $($t).jqGrid("saveRow", rowid, o ) ) { 9415 if($t.p._inlinenav) { 9416 try { 9417 $($t).jqGrid('showAddEditButtons'); 9418 } catch (eer2) {} 9419 } 9420 } 9421 return false; 9422 } 9423 }); 9424 } 9425 $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]); 9426 if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); } 9427 } 9428 } 9429 }); 9430 }, 9431 saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) { 9432 // Compatible mode old versions 9433 var args = $.makeArray(arguments).slice(1), o = {}; 9434 9435 if( $.type(args[0]) === "object" ) { 9436 o = args[0]; 9437 } else { 9438 if ($.isFunction(successfunc)) { o.successfunc = successfunc; } 9439 if (url !== undefined) { o.url = url; } 9440 if (extraparam !== undefined) { o.extraparam = extraparam; } 9441 if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; } 9442 if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; } 9443 if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; } 9444 } 9445 o = $.extend(true, { 9446 successfunc: null, 9447 url: null, 9448 extraparam: {}, 9449 aftersavefunc: null, 9450 errorfunc: null, 9451 afterrestorefunc: null, 9452 restoreAfterError: true, 9453 mtype: "POST" 9454 }, $.jgrid.inlineEdit, o ); 9455 // End compatible 9456 9457 var success = false; 9458 var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind; 9459 if (!$t.grid ) { return success; } 9460 ind = $($t).jqGrid("getInd",rowid,true); 9461 if(ind === false) {return success;} 9462 var bfsr = $.isFunction( o.beforeSaveRow ) ? o.beforeSaveRow.call($t,o, rowid) : undefined; 9463 if( bfsr === undefined ) { 9464 bfsr = true; 9465 } 9466 if(!bfsr) { return; } 9467 editable = $(ind).attr("editable"); 9468 o.url = o.url || $t.p.editurl; 9469 if (editable==="1") { 9470 var cm; 9471 $('td[role="gridcell"]',ind).each(function(i) { 9472 cm = $t.p.colModel[i]; 9473 nm = cm.name; 9474 if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) { 9475 switch (cm.edittype) { 9476 case "checkbox": 9477 var cbv = ["Yes","No"]; 9478 if(cm.editoptions ) { 9479 cbv = cm.editoptions.value.split(":"); 9480 } 9481 tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1]; 9482 break; 9483 case 'text': 9484 case 'password': 9485 case 'textarea': 9486 case "button" : 9487 tmp[nm]=$("input, textarea",this).val(); 9488 break; 9489 case 'select': 9490 if(!cm.editoptions.multiple) { 9491 tmp[nm] = $("select option:selected",this).val(); 9492 tmp2[nm] = $("select option:selected", this).text(); 9493 } else { 9494 var sel = $("select",this), selectedText = []; 9495 tmp[nm] = $(sel).val(); 9496 if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; } 9497 $("select option:selected",this).each( 9498 function(i,selected){ 9499 selectedText[i] = $(selected).text(); 9500 } 9501 ); 9502 tmp2[nm] = selectedText.join(","); 9503 } 9504 if(cm.formatter && cm.formatter === 'select') { tmp2={}; } 9505 break; 9506 case 'custom' : 9507 try { 9508 if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) { 9509 tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get'); 9510 if (tmp[nm] === undefined) { throw "e2"; } 9511 } else { throw "e1"; } 9512 } catch (e) { 9513 if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); } 9514 if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); } 9515 else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); } 9516 } 9517 break; 9518 } 9519 cv = $.jgrid.checkValues.call($t,tmp[nm],i); 9520 if(cv[0] === false) { 9521 return false; 9522 } 9523 if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); } 9524 if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) { 9525 if(tmp[nm] === "") { 9526 tmp3[nm] = 'null';
9527 } 9528 } 9529 } 9530 }); 9531 if (cv[0] === false){ 9532 try { 9533 var tr = $($t).jqGrid('getGridRowById', rowid), positions = $.jgrid.findPos(tr); 9534 $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight()}); 9535 } catch (e) { 9536 alert(cv[1]); 9537 } 9538 return success; 9539 } 9540 var idname, opers = $t.p.prmNames, oldRowId = rowid; 9541 if ($t.p.keyName === false) { 9542 idname = opers.id; 9543 } else { 9544 idname = $t.p.keyName; 9545 } 9546 if(tmp) { 9547 tmp[opers.oper] = opers.editoper; 9548 if (tmp[idname] === undefined || tmp[idname]==="") { 9549 tmp[idname] = rowid; 9550 } else if (ind.id !== $t.p.idPrefix + tmp[idname]) { 9551 // rename rowid 9552 var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid); 9553 if ($t.p._index[oldid] !== undefined) { 9554 $t.p._index[tmp[idname]] = $t.p._index[oldid]; 9555 delete $t.p._index[oldid]; 9556 } 9557 rowid = $t.p.idPrefix + tmp[idname]; 9558 $(ind).attr("id", rowid); 9559 if ($t.p.selrow === oldRowId) { 9560 $t.p.selrow = rowid; 9561 } 9562 if ($.isArray($t.p.selarrrow)) { 9563 var i = $.inArray(oldRowId, $t.p.selarrrow); 9564 if (i>=0) { 9565 $t.p.selarrrow[i] = rowid; 9566 } 9567 } 9568 if ($t.p.multiselect) { 9569 var newCboxId = "jqg_" + $t.p.id + "_" + rowid; 9570 $("input.cbox",ind) 9571 .attr("id", newCboxId) 9572 .attr("name", newCboxId); 9573 } 9574 // TODO: to test the case of frozen columns 9575 } 9576 if($t.p.inlineData === undefined) { $t.p.inlineData ={}; } 9577 tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam); 9578 } 9579 if (o.url === 'clientArray') { 9580 tmp = $.extend({},tmp, tmp2); 9581 if($t.p.autoencode) { 9582 $.each(tmp,function(n,v){ 9583 tmp[n] = $.jgrid.htmlDecode(v); 9584 }); 9585 } 9586 var k, resp = $($t).jqGrid("setRowData",rowid,tmp); 9587 $(ind).attr("editable","0"); 9588 for(k=0;k<$t.p.savedRow.length;k++) { 9589 if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;} 9590 } 9591 if(fr >= 0) { $t.p.savedRow.splice(fr,1); } 9592 $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]); 9593 if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, resp, tmp, o); } 9594 success = true; 9595 $(ind).removeClass("jqgrid-new-row").unbind("keydown"); 9596 } else { 9597 $("#lui_"+$.jgrid.jqID($t.p.id)).show(); 9598 tmp3 = $.extend({},tmp,tmp3); 9599 tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]); 9600 $.ajax($.extend({ 9601 url:o.url, 9602 data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3, 9603 type: o.mtype, 9604 async : false, //?!? 9605 complete: function(res,stat){ 9606 $("#lui_"+$.jgrid.jqID($t.p.id)).hide(); 9607 if (stat === "success"){ 9608 var ret = true, sucret, k; 9609 sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]); 9610 if (!$.isArray(sucret)) {sucret = [true, tmp];} 9611 if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);} 9612 if($.isArray(sucret)) { 9613 // expect array - status, data, rowid 9614 ret = sucret[0]; 9615 tmp = sucret[1] || tmp; 9616 } else { 9617 ret = sucret; 9618 } 9619 if (ret===true) { 9620 if($t.p.autoencode) { 9621 $.each(tmp,function(n,v){ 9622 tmp[n] = $.jgrid.htmlDecode(v); 9623 }); 9624 } 9625 tmp = $.extend({},tmp, tmp2); 9626 $($t).jqGrid("setRowData",rowid,tmp); 9627 $(ind).attr("editable","0"); 9628 for(k=0;k<$t.p.savedRow.length;k++) { 9629 if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;} 9630 } 9631 if(fr >= 0) { $t.p.savedRow.splice(fr,1); } 9632 $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]); 9633 if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, res, tmp, o); } 9634 success = true; 9635 $(ind).removeClass("jqgrid-new-row").unbind("keydown"); 9636 } else { 9637 $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]); 9638 if($.isFunction(o.errorfunc) ) { 9639 o.errorfunc.call($t, rowid, res, stat, null); 9640 } 9641 if(o.restoreAfterError === true) { 9642 $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc); 9643 } 9644 } 9645 } 9646 }, 9647 error:function(res,stat,err){ 9648 $("#lui_"+$.jgrid.jqID($t.p.id)).hide(); 9649 $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]); 9650 if($.isFunction(o.errorfunc) ) { 9651 o.errorfunc.call($t, rowid, res, stat, err); 9652 } else { 9653 var rT = res.responseText || res.statusText; 9654 try {
9655 $.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ rT +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'}); 9656 } catch(e) { 9657 alert(rT); 9658 } 9659 } 9660 if(o.restoreAfterError === true) { 9661 $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc); 9662 } 9663 } 9664 }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {})); 9665 } 9666 } 9667 return success; 9668 }, 9669 restoreRow : function(rowid, afterrestorefunc) { 9670 // Compatible mode old versions 9671 var args = $.makeArray(arguments).slice(1), o={}; 9672 9673 if( $.type(args[0]) === "object" ) { 9674 o = args[0]; 9675 } else { 9676 if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; } 9677 } 9678 o = $.extend(true, {}, $.jgrid.inlineEdit, o ); 9679 9680 // End compatible 9681 9682 return this.each(function(){ 9683 var $t= this, fr=-1, ind, ares={}, k; 9684 if (!$t.grid ) { return; } 9685 ind = $($t).jqGrid("getInd",rowid,true); 9686 if(ind === false) {return;} 9687 var bfcr = $.isFunction( o.beforeCancelRow ) ? o.beforeCancelRow.call($t, o, sr) : undefined; 9688 if( bfcr === undefined ) { 9689 bfcr = true; 9690 } 9691 if(!bfcr) { return; } 9692 for(k=0;k<$t.p.savedRow.length;k++) { 9693 if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;} 9694 } 9695 if(fr >= 0) { 9696 if($.isFunction($.fn.datepicker)) { 9697 try { 9698 $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide'); 9699 } catch (e) {} 9700 } 9701 $.each($t.p.colModel, function(){ 9702 if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) { 9703 ares[this.name] = $t.p.savedRow[fr][this.name]; 9704 } 9705 }); 9706 $($t).jqGrid("setRowData",rowid,ares); 9707 $(ind).attr("editable","0").unbind("keydown"); 9708 $t.p.savedRow.splice(fr,1); 9709 if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){ 9710 setTimeout(function(){ 9711 $($t).jqGrid("delRowData",rowid); 9712 $($t).jqGrid('showAddEditButtons'); 9713 },0); 9714 } 9715 } 9716 $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]); 9717 if ($.isFunction(o.afterrestorefunc)) 9718 { 9719 o.afterrestorefunc.call($t, rowid); 9720 } 9721 }); 9722 }, 9723 addRow : function ( p ) { 9724 p = $.extend(true, { 9725 rowID : null, 9726 initdata : {}, 9727 position :"first", 9728 useDefValues : true, 9729 useFormatter : false, 9730 addRowParams : {extraparam:{}} 9731 },p || {}); 9732 return this.each(function(){ 9733 if (!this.grid ) { return; } 9734 var $t = this; 9735 var bfar = $.isFunction( p.beforeAddRow ) ? p.beforeAddRow.call($t,p.addRowParams) : undefined; 9736 if( bfar === undefined ) { 9737 bfar = true; 9738 } 9739 if(!bfar) { return; } 9740 p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId()); 9741 if(p.useDefValues === true) { 9742 $($t.p.colModel).each(function(){ 9743 if( this.editoptions && this.editoptions.defaultValue ) { 9744 var opt = this.editoptions.defaultValue, 9745 tmp = $.isFunction(opt) ? opt.call($t) : opt; 9746 p.initdata[this.name] = tmp; 9747 } 9748 }); 9749 } 9750 $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position); 9751 p.rowID = $t.p.idPrefix + p.rowID; 9752 $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row"); 9753 if(p.useFormatter) { 9754 $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click(); 9755 } else { 9756 var opers = $t.p.prmNames, 9757 oper = opers.oper; 9758 p.addRowParams.extraparam[oper] = opers.addoper; 9759 $($t).jqGrid('editRow', p.rowID, p.addRowParams); 9760 $($t).jqGrid('setSelection', p.rowID); 9761 } 9762 }); 9763 }, 9764 inlineNav : function (elem, o) { 9765 o = $.extend(true,{ 9766 edit: true, 9767 editicon: "ui-icon-pencil", 9768 add: true, 9769 addicon:"ui-icon-plus", 9770 save: true, 9771 saveicon:"ui-icon-disk", 9772 cancel: true, 9773 cancelicon:"ui-icon-cancel", 9774 addParams : {addRowParams: {extraparam: {}}}, 9775 editParams : {}, 9776 restoreAfterSelect : true 9777 }, $.jgrid.nav, o ||{}); 9778 return this.each(function(){ 9779 if (!this.grid ) { return; } 9780 var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id); 9781 $t.p._inlinenav = true; 9782 // detect the formatactions column 9783 if(o.addParams.useFormatter === true) { 9784 var cm = $t.p.colModel,i; 9785 for (i = 0; i<cm.length; i++) { 9786 if(cm[i].formatter && cm[i].formatter === "actions" ) { 9787 if(cm[i].formatoptions) { 9788 var defaults = { 9789 keys:false, 9790 onEdit : null, 9791 onSuccess: null, 9792 afterSave:null, 9793 onError: null, 9794 afterRestore: null, 9795 extraparam: {}, 9796 url: null 9797 }, 9798 ap = $.extend( defaults, cm[i].formatoptions ); 9799 o.addParams.addRowParams = { 9800 "keys" : ap.keys, 9801 "oneditfunc" : ap.onEdit, 9802 "successfunc" : ap.onSuccess, 9803 "url" : ap.url, 9804 "extraparam" : ap.extraparam, 9805 "aftersavefunc" : ap.afterSave, 9806 "errorfunc": ap.onError, 9807 "afterrestorefunc" : ap.afterRestore 9808 }; 9809 } 9810 break; 9811 } 9812 } 9813 } 9814 if(o.add) { 9815 $($t).jqGrid('navButtonAdd', elem,{ 9816 caption : o.addtext, 9817 title : o.addtitle, 9818 buttonicon : o.addicon, 9819 id : $t.p.id+"_iladd", 9820 onClickButton : function () { 9821 $($t).jqGrid('addRow', o.addParams); 9822 if(!o.addParams.useFormatter) { 9823 $("#"+gID+"_ilsave").removeClass('ui-state-disabled'); 9824 $("#"+gID+"_ilcancel").removeClass('ui-state-disabled'); 9825 $("#"+gID+"_iladd").addClass('ui-state-disabled'); 9826 $("#"+gID+"_iledit").addClass('ui-state-disabled'); 9827 } 9828 } 9829 }); 9830 } 9831 if(o.edit) { 9832 $($t).jqGrid('navButtonAdd', elem,{ 9833 caption : o.edittext, 9834 title : o.edittitle, 9835 buttonicon : o.editicon, 9836 id : $t.p.id+"_iledit", 9837 onClickButton : function () { 9838 var sr = $($t).jqGrid('getGridParam','selrow'); 9839 if(sr) { 9840 $($t).jqGrid('editRow', sr, o.editParams); 9841 $("#"+gID+"_ilsave").removeClass('ui-state-disabled'); 9842 $("#"+gID+"_ilcancel").removeClass('ui-state-disabled'); 9843 $("#"+gID+"_iladd").addClass('ui-state-disabled'); 9844 $("#"+gID+"_iledit").addClass('ui-state-disabled'); 9845 } else { 9846 $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus(); 9847 } 9848 } 9849 }); 9850 } 9851 if(o.save) { 9852 $($t).jqGrid('navButtonAdd', elem,{ 9853 caption : o.savetext || '', 9854 title : o.savetitle || 'Save row', 9855 buttonicon : o.saveicon, 9856 id : $t.p.id+"_ilsave", 9857 onClickButton : function () { 9858 var sr = $t.p.savedRow[0].id; 9859 if(sr) { 9860 var opers = $t.p.prmNames, 9861 oper = opers.oper, tmpParams = o.editParams; 9862 if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) { 9863 o.addParams.addRowParams.extraparam[oper] = opers.addoper; 9864 tmpParams = o.addParams.addRowParams; 9865 } else { 9866 if(!o.editParams.extraparam) { 9867 o.editParams.extraparam = {}; 9868 } 9869 o.editParams.extraparam[oper] = opers.editoper; 9870 } 9871 if( $($t).jqGrid('saveRow', sr, tmpParams) ) { 9872 $($t).jqGrid('showAddEditButtons'); 9873 } 9874 } else { 9875 $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus(); 9876 } 9877 } 9878 }); 9879 $("#"+gID+"_ilsave").addClass('ui-state-disabled'); 9880 } 9881 if(o.cancel) { 9882 $($t).jqGrid('navButtonAdd', elem,{ 9883 caption : o.canceltext || '', 9884 title : o.canceltitle || 'Cancel row editing', 9885 buttonicon : o.cancelicon, 9886 id : $t.p.id+"_ilcancel", 9887 onClickButton : function () { 9888 var sr = $t.p.savedRow[0].id, cancelPrm = o.editParams; 9889 if(sr) { 9890 if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) { 9891 cancelPrm = o.addParams.addRowParams; 9892 } 9893 $($t).jqGrid('restoreRow', sr, cancelPrm); 9894 $($t).jqGrid('showAddEditButtons'); 9895 } else { 9896 $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus(); 9897 } 9898 } 9899 }); 9900 $("#"+gID+"_ilcancel").addClass('ui-state-disabled'); 9901 } 9902 if(o.restoreAfterSelect === true) { 9903 if($.isFunction($t.p.beforeSelectRow)) { 9904 onSelect = $t.p.beforeSelectRow; 9905 } else { 9906 onSelect = false; 9907 } 9908 $t.p.beforeSelectRow = function(id, stat) { 9909 var ret = true; 9910 if($t.p.savedRow.length > 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) { 9911 if($t.p.selrow === o.addParams.rowID ) { 9912 $($t).jqGrid('delRowData', $t.p.selrow); 9913 } else { 9914 $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams); 9915 } 9916 $($t).jqGrid('showAddEditButtons'); 9917 } 9918 if(onSelect) { 9919 ret = onSelect.call($t, id, stat); 9920 } 9921 return ret; 9922 }; 9923 } 9924 9925 }); 9926 }, 9927 showAddEditButtons : function() { 9928 return this.each(function(){ 9929 if (!this.grid ) { return; } 9930 var gID = $.jgrid.jqID(this.p.id); 9931 $("#"+gID+"_ilsave").addClass('ui-state-disabled'); 9932 $("#"+gID+"_ilcancel").addClass('ui-state-disabled'); 9933 $("#"+gID+"_iladd").removeClass('ui-state-disabled'); 9934 $("#"+gID+"_iledit").removeClass('ui-state-disabled'); 9935 }); 9936 } 9937//end inline edit 9938}); 9939})(jQuery); 9940/*jshint eqeqeq:false */ 9941/*global jQuery */ 9942(function($){ 9943/* 9944** 9945 * jqGrid extension for cellediting Grid Data 9946 * Tony Tomov [email protected] 9947 * http://trirand.com/blog/ 9948 * Dual licensed under the MIT and GPL licenses: 9949 * http://www.opensource.org/licenses/mit-license.php 9950 * http://www.gnu.org/licenses/gpl-2.0.html 9951**/ 9952/** 9953 * all events and options here are aded anonynous and not in the base grid 9954 * since the array is to big. Here is the order of execution. 9955 * From this point we use jQuery isFunction 9956 * formatCell 9957 * beforeEditCell, 9958 * onSelectCell (used only for noneditable cels) 9959 * afterEditCell, 9960 * beforeSaveCell, (called before validation of values if any) 9961 * beforeSubmitCell (if cellsubmit remote (ajax)) 9962 * afterSubmitCell(if cellsubmit remote (ajax)), 9963 * afterSaveCell, 9964 * errorCell, 9965 * serializeCellData - new 9966 * Options 9967 * cellsubmit (remote,clientArray) (added in grid options) 9968 * cellurl 9969 * ajaxCellOptions 9970* */ 9971"use strict"; 9972$.jgrid.extend({ 9973 editCell : function (iRow,iCol, ed){ 9974 return this.each(function (){ 9975 var $t = this, nm, tmp,cc, cm; 9976 if (!$t.grid || $t.p.cellEdit !== true) {return;} 9977 iCol = parseInt(iCol,10); 9978 // select the row that can be used for other methods 9979 $t.p.selrow = $t.rows[iRow].id; 9980 if (!$t.p.knv) {$($t).jqGrid("GridNav");} 9981 // check to see if we have already edited cell 9982 if ($t.p.savedRow.length>0) { 9983 // prevent second click on that field and enable selects 9984 if (ed===true ) { 9985 if(iRow == $t.p.iRow && iCol == $t.p.iCol){ 9986 return; 9987 } 9988 } 9989 // save the cell 9990 $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic); 9991 } else { 9992 window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},1); 9993 } 9994 cm = $t.p.colModel[iCol]; 9995 nm = cm.name; 9996 if (nm==='subgrid' || nm==='cb' || nm==='rn') {return;} 9997 cc = $("td:eq("+iCol+")",$t.rows[iRow]); 9998 if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) { 9999 if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) { 10000 $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight"); 10001 $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover"); 10002 } 10003 $(cc).addClass("edit-cell ui-state-highlight"); 10004 $($t.rows[iRow]).addClass("selected-row ui-state-hover");
10005 try { 10006 tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol); 10007 } catch (_) { 10008 tmp = ( cm.edittype && cm.edittype === 'textarea' ) ? $(cc).text() : $(cc).html(); 10009 } 10010 if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); } 10011 if (!cm.edittype) {cm.edittype = "text";} 10012 $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp}); 10013 if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';} 10014 if($.isFunction($t.p.formatCell)) { 10015 var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); 10016 if(tmp2 !== undefined ) {tmp = tmp2;} 10017 } 10018 $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); 10019 if ($.isFunction($t.p.beforeEditCell)) { 10020 $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); 10021 } 10022 var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm,rowId: $t.rows[iRow].id}); 10023 var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {})); 10024 $(cc).html("").append(elc).attr("tabindex","0"); 10025 $.jgrid.bindEv.call($t, elc, opt); 10026 window.setTimeout(function () { $(elc).focus();},1); 10027 $("input, select, textarea",cc).bind("keydown",function(e) { 10028 if (e.keyCode === 27) { 10029 if($("input.hasDatepicker",cc).length >0) { 10030 if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); } 10031 else { $("input.hasDatepicker",cc).datepicker('hide'); } 10032 } else { 10033 $($t).jqGrid("restoreCell",iRow,iCol); 10034 } 10035 } //ESC 10036 if (e.keyCode === 13) { 10037 $($t).jqGrid("saveCell",iRow,iCol); 10038 // Prevent default action 10039 return false; 10040 } //Enter 10041 if (e.keyCode === 9) { 10042 if(!$t.grid.hDiv.loading ) { 10043 if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb 10044 else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab 10045 } else { 10046 return false; 10047 } 10048 } 10049 e.stopPropagation(); 10050 }); 10051 $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); 10052 if ($.isFunction($t.p.afterEditCell)) { 10053 $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); 10054 } 10055 } else { 10056 if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) { 10057 $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight"); 10058 $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover"); 10059 } 10060 cc.addClass("edit-cell ui-state-highlight"); 10061 $($t.rows[iRow]).addClass("selected-row ui-state-hover"); 10062 tmp = cc.html().replace(/\ \;/ig,''); 10063 $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); 10064 if ($.isFunction($t.p.onSelectCell)) { 10065 $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); 10066 } 10067 } 10068 $t.p.iCol = iCol; $t.p.iRow = iRow; 10069 }); 10070 }, 10071 saveCell : function (iRow, iCol){ 10072 return this.each(function(){ 10073 var $t= this, fr; 10074 if (!$t.grid || $t.p.cellEdit !== true) {return;} 10075 if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;} 10076 if(fr !== null) { 10077 var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2, 10078 cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ; 10079 switch (cm.edittype) { 10080 case "select": 10081 if(!cm.editoptions.multiple) { 10082 v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val(); 10083 v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text(); 10084 } else { 10085 var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = []; 10086 v = $(sel).val(); 10087 if(v) { v.join(",");} else { v=""; } 10088 $("option:selected",sel).each( 10089 function(i,selected){ 10090 selectedText[i] = $(selected).text(); 10091 } 10092 ); 10093 v2 = selectedText.join(","); 10094 } 10095 if(cm.formatter) { v2 = v; } 10096 break; 10097 case "checkbox": 10098 var cbv = ["Yes","No"]; 10099 if(cm.editoptions){ 10100 cbv = cm.editoptions.value.split(":"); 10101 } 10102 v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1]; 10103 v2=v; 10104 break; 10105 case "password": 10106 case "text": 10107 case "textarea": 10108 case "button" : 10109 v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val(); 10110 v2=v; 10111 break; 10112 case 'custom' : 10113 try { 10114 if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) { 10115 v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get'); 10116 if (v===undefined) { throw "e2";} else { v2=v; } 10117 } else { throw "e1"; } 10118 } catch (e) {
10119 if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); } 10120 if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); } 10121 else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); } 10122 } 10123 break; 10124 } 10125 // The common approach is if nothing changed do not do anything 10126 if (v2 !== $t.p.savedRow[fr].v){ 10127 var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); 10128 if (vvv) {v = vvv; v2=vvv;} 10129 if ($.isFunction($t.p.beforeSaveCell)) { 10130 var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); 10131 if (vv) {v = vv; v2=vv;} 10132 } 10133 var cv = $.jgrid.checkValues.call($t,v,iCol); 10134 if(cv[0] === true) { 10135 var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {}; 10136 if ($.isFunction($t.p.beforeSubmitCell)) { 10137 addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); 10138 if (!addpost) {addpost={};} 10139 } 10140 if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); } 10141 if ($t.p.cellsubmit === 'remote') { 10142 if ($t.p.cellurl) { 10143 var postdata = {}; 10144 if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); } 10145 postdata[nm] = v; 10146 var idname,oper, opers; 10147 opers = $t.p.prmNames; 10148 idname = opers.id; 10149 oper = opers.oper; 10150 postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id); 10151 postdata[oper] = opers.editoper; 10152 postdata = $.extend(addpost,postdata); 10153 $("#lui_"+$.jgrid.jqID($t.p.id)).show(); 10154 $t.grid.hDiv.loading = true; 10155 $.ajax( $.extend( { 10156 url: $t.p.cellurl, 10157 data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata, 10158 type: "POST", 10159 complete: function (result, stat) { 10160 $("#lui_"+$t.p.id).hide(); 10161 $t.grid.hDiv.loading = false; 10162 if (stat === 'success') { 10163 var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, '']; 10164 if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) { 10165 ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol); 10166 } 10167 if(ret[0] === true){ 10168 $(cc).empty(); 10169 $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true); 10170 $(cc).addClass("dirty-cell"); 10171 $($t.rows[iRow]).addClass("edited"); 10172 $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); 10173 if ($.isFunction($t.p.afterSaveCell)) { 10174 $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); 10175 } 10176 $t.p.savedRow.splice(0,1); 10177 } else { 10178 $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose); 10179 $($t).jqGrid("restoreCell",iRow,iCol); 10180 } 10181 } 10182 }, 10183 error:function(res,stat,err) { 10184 $("#lui_"+$.jgrid.jqID($t.p.id)).hide(); 10185 $t.grid.hDiv.loading = false; 10186 $($t).triggerHandler("jqGridErrorCell", [res, stat, err]); 10187 if ($.isFunction($t.p.errorCell)) { 10188 $t.p.errorCell.call($t, res,stat,err); 10189 $($t).jqGrid("restoreCell",iRow,iCol); 10190 } else { 10191 $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose); 10192 $($t).jqGrid("restoreCell",iRow,iCol); 10193 } 10194 } 10195 }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {})); 10196 } else { 10197 try { 10198 $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose); 10199 $($t).jqGrid("restoreCell",iRow,iCol); 10200 } catch (e) {} 10201 } 10202 } 10203 if ($t.p.cellsubmit === 'clientArray') { 10204 $(cc).empty(); 10205 $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true); 10206 $(cc).addClass("dirty-cell"); 10207 $($t.rows[iRow]).addClass("edited"); 10208 $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); 10209 if ($.isFunction($t.p.afterSaveCell)) { 10210 $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); 10211 } 10212 $t.p.savedRow.splice(0,1); 10213 } 10214 } else { 10215 try {
10216 window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100); 10217 $($t).jqGrid("restoreCell",iRow,iCol); 10218 } catch (e) {} 10219 } 10220 } else { 10221 $($t).jqGrid("restoreCell",iRow,iCol); 10222 } 10223 } 10224 window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0); 10225 }); 10226 }, 10227 restoreCell : function(iRow, iCol) { 10228 return this.each(function(){ 10229 var $t= this, fr; 10230 if (!$t.grid || $t.p.cellEdit !== true ) {return;} 10231 if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;} 10232 if(fr !== null) { 10233 var cc = $("td:eq("+iCol+")",$t.rows[iRow]); 10234 // datepicker fix 10235 if($.isFunction($.fn.datepicker)) { 10236 try { 10237 $("input.hasDatepicker",cc).datepicker('hide'); 10238 } catch (e) {} 10239 } 10240 $(cc).empty().attr("tabindex","-1"); 10241 $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true); 10242 $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]); 10243 if ($.isFunction($t.p.afterRestoreCell)) { 10244 $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol); 10245 } 10246 $t.p.savedRow.splice(0,1); 10247 } 10248 window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0); 10249 }); 10250 }, 10251 nextCell : function (iRow,iCol) { 10252 return this.each(function (){ 10253 var $t = this, nCol=false, i; 10254 if (!$t.grid || $t.p.cellEdit !== true) {return;} 10255 // try to find next editable cell 10256 for (i=iCol+1; i<$t.p.colModel.length; i++) { 10257 if ( $t.p.colModel[i].editable ===true) { 10258 nCol = i; break; 10259 } 10260 } 10261 if(nCol !== false) { 10262 $($t).jqGrid("editCell",iRow,nCol,true); 10263 } else { 10264 if ($t.p.savedRow.length >0) { 10265 $($t).jqGrid("saveCell",iRow,iCol); 10266 } 10267 } 10268 }); 10269 }, 10270 prevCell : function (iRow,iCol) { 10271 return this.each(function (){ 10272 var $t = this, nCol=false, i; 10273 if (!$t.grid || $t.p.cellEdit !== true) {return;} 10274 // try to find next editable cell 10275 for (i=iCol-1; i>=0; i--) { 10276 if ( $t.p.colModel[i].editable ===true) { 10277 nCol = i; break; 10278 } 10279 } 10280 if(nCol !== false) { 10281 $($t).jqGrid("editCell",iRow,nCol,true); 10282 } else { 10283 if ($t.p.savedRow.length >0) { 10284 $($t).jqGrid("saveCell",iRow,iCol); 10285 } 10286 } 10287 }); 10288 }, 10289 GridNav : function() { 10290 return this.each(function () { 10291 var $t = this; 10292 if (!$t.grid || $t.p.cellEdit !== true ) {return;} 10293 // trick to process keydown on non input elements 10294 $t.p.knv = $t.p.id + "_kn"; 10295 var selection = $("<div style='position:fixed;top:0px;width:1px;height:1px;' tabindex='0'><div tabindex='-1' style='width:1px;height:1px;' id='"+$t.p.knv+"'></div></div>"), 10296 i, kdir; 10297 function scrollGrid(iR, iC, tp){ 10298 if (tp.substr(0,1)==='v') { 10299 var ch = $($t.grid.bDiv)[0].clientHeight, 10300 st = $($t.grid.bDiv)[0].scrollTop, 10301 nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight, 10302 pROT = $t.rows[iR].offsetTop; 10303 if(tp === 'vd') { 10304 if(nROT >= ch) { 10305 $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight; 10306 } 10307 } 10308 if(tp === 'vu'){ 10309 if (pROT < st ) { 10310 $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight; 10311 } 10312 } 10313 } 10314 if(tp==='h') { 10315 var cw = $($t.grid.bDiv)[0].clientWidth, 10316 sl = $($t.grid.bDiv)[0].scrollLeft, 10317 nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth, 10318 pCOL = $t.rows[iR].cells[iC].offsetLeft; 10319 if(nCOL >= cw+parseInt(sl,10)) { 10320 $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth; 10321 } else if (pCOL < sl) { 10322 $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth; 10323 } 10324 } 10325 } 10326 function findNextVisible(iC,act){ 10327 var ind, i; 10328 if(act === 'lft') { 10329 ind = iC+1; 10330 for (i=iC;i>=0;i--){ 10331 if ($t.p.colModel[i].hidden !== true) { 10332 ind = i; 10333 break; 10334 } 10335 } 10336 } 10337 if(act === 'rgt') { 10338 ind = iC-1; 10339 for (i=iC; i<$t.p.colModel.length;i++){ 10340 if ($t.p.colModel[i].hidden !== true) { 10341 ind = i; 10342 break; 10343 } 10344 } 10345 } 10346 return ind; 10347 } 10348 10349 $(selection).insertBefore($t.grid.cDiv); 10350 $("#"+$t.p.knv) 10351 .focus() 10352 .keydown(function (e){ 10353 kdir = e.keyCode; 10354 if($t.p.direction === "rtl") { 10355 if(kdir===37) { kdir = 39;} 10356 else if (kdir===39) { kdir = 37; } 10357 } 10358 switch (kdir) { 10359 case 38: 10360 if ($t.p.iRow-1 >0 ) { 10361 scrollGrid($t.p.iRow-1,$t.p.iCol,'vu'); 10362 $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false); 10363 } 10364 break; 10365 case 40 : 10366 if ($t.p.iRow+1 <= $t.rows.length-1) { 10367 scrollGrid($t.p.iRow+1,$t.p.iCol,'vd'); 10368 $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false); 10369 } 10370 break; 10371 case 37 : 10372 if ($t.p.iCol -1 >= 0) { 10373 i = findNextVisible($t.p.iCol-1,'lft'); 10374 scrollGrid($t.p.iRow, i,'h'); 10375 $($t).jqGrid("editCell",$t.p.iRow, i,false); 10376 } 10377 break; 10378 case 39 : 10379 if ($t.p.iCol +1 <= $t.p.colModel.length-1) { 10380 i = findNextVisible($t.p.iCol+1,'rgt'); 10381 scrollGrid($t.p.iRow,i,'h'); 10382 $($t).jqGrid("editCell",$t.p.iRow,i,false); 10383 } 10384 break; 10385 case 13: 10386 if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) { 10387 $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true); 10388 } 10389 break; 10390 default : 10391 return true; 10392 } 10393 return false;
10394 }); 10395 }); 10396 }, 10397 getChangedCells : function (mthd) { 10398 var ret=[]; 10399 if (!mthd) {mthd='all';} 10400 this.each(function(){ 10401 var $t= this,nm; 10402 if (!$t.grid || $t.p.cellEdit !== true ) {return;} 10403 $($t.rows).each(function(j){ 10404 var res = {}; 10405 if ($(this).hasClass("edited")) { 10406 $('td',this).each( function(i) { 10407 nm = $t.p.colModel[i].name; 10408 if ( nm !== 'cb' && nm !== 'subgrid') { 10409 if (mthd==='dirty') { 10410 if ($(this).hasClass('dirty-cell')) { 10411 try { 10412 res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i); 10413 } catch (e){ 10414 res[nm] = $.jgrid.htmlDecode($(this).html()); 10415 } 10416 } 10417 } else { 10418 try { 10419 res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i); 10420 } catch (e) { 10421 res[nm] = $.jgrid.htmlDecode($(this).html()); 10422 } 10423 } 10424 } 10425 }); 10426 res.id = this.id; 10427 ret.push(res); 10428 } 10429 }); 10430 }); 10431 return ret; 10432 } 10433/// end cell editing 10434}); 10435})(jQuery); 10436/*jshint eqeqeq:false */ 10437/*global jQuery */ 10438(function($){ 10439/** 10440 * jqGrid extension for SubGrid Data 10441 * Tony Tomov [email protected] 10442 * http://trirand.com/blog/ 10443 * Dual licensed under the MIT and GPL licenses: 10444 * http://www.opensource.org/licenses/mit-license.php 10445 * http://www.gnu.org/licenses/gpl-2.0.html 10446**/ 10447"use strict"; 10448$.jgrid.extend({ 10449setSubGrid : function () { 10450 return this.each(function (){ 10451 var $t = this, cm, i, 10452 suboptions = { 10453 plusicon : "ui-icon-plus", 10454 minusicon : "ui-icon-minus", 10455 openicon: "ui-icon-carat-1-sw", 10456 expandOnLoad: false, 10457 delayOnLoad : 50, 10458 selectOnExpand : false, 10459 selectOnCollapse : false, 10460 reloadOnExpand : true 10461 }; 10462 $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {}); 10463 $t.p.colNames.unshift(""); 10464 $t.p.colModel.unshift({name:'subgrid',width: $.jgrid.cell_width ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true}); 10465 cm = $t.p.subGridModel; 10466 if(cm[0]) { 10467 cm[0].align = $.extend([],cm[0].align || []); 10468 for(i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';} 10469 } 10470 }); 10471}, 10472addSubGridCell :function (pos,iRow) { 10473 var prp='',ic,sid; 10474 this.each(function(){ 10475 prp = this.formatCol(pos,iRow); 10476 sid= this.p.id; 10477 ic = this.p.subGridOptions.plusicon; 10478 }); 10479 return "<td role=\"gridcell\" aria-describedby=\""+sid+"_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" "+prp+"><a style='cursor:pointer;'><span class='ui-icon "+ic+"'></span></a></td>"; 10480}, 10481addSubGrid : function( pos, sind ) { 10482 return this.each(function(){ 10483 var ts = this; 10484 if (!ts.grid ) { return; } 10485 //------------------------- 10486 var subGridCell = function(trdiv,cell,pos) 10487 { 10488 var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell); 10489 $(trdiv).append(tddiv); 10490 }; 10491 var subGridXml = function(sjxml, sbid){ 10492 var tddiv, i, sgmap, 10493 dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"), 10494 trdiv = $("<tr></tr>"); 10495 for (i = 0; i<ts.p.subGridModel[0].name.length; i++) { 10496 tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>"); 10497 $(tddiv).html(ts.p.subGridModel[0].name[i]); 10498 $(tddiv).width( ts.p.subGridModel[0].width[i]); 10499 $(trdiv).append(tddiv); 10500 } 10501 $(dummy).append(trdiv); 10502 if (sjxml){ 10503 sgmap = ts.p.xmlReader.subgrid; 10504 $(sgmap.root+" "+sgmap.row, sjxml).each( function(){ 10505 trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>"); 10506 if(sgmap.repeatitems === true) { 10507 $(sgmap.cell,this).each( function(i) { 10508 subGridCell(trdiv, $(this).text() || ' ',i); 10509 }); 10510 } else { 10511 var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name; 10512 if (f) { 10513 for (i=0;i<f.length;i++) { 10514 subGridCell(trdiv, $(f[i],this).text() || ' ',i); 10515 } 10516 } 10517 } 10518 $(dummy).append(trdiv); 10519 }); 10520 } 10521 var pID = $("table:first",ts.grid.bDiv).attr("id")+"_"; 10522 $("#"+$.jgrid.jqID(pID+sbid)).append(dummy); 10523 ts.grid.hDiv.loading = false;
10524 $("#load_"+$.jgrid.jqID(ts.p.id)).hide(); 10525 return false; 10526 }; 10527 var subGridJson = function(sjxml, sbid){ 10528 var tddiv,result,i,cur, sgmap,j, 10529 dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"), 10530 trdiv = $("<tr></tr>"); 10531 for (i = 0; i<ts.p.subGridModel[0].name.length; i++) { 10532 tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>"); 10533 $(tddiv).html(ts.p.subGridModel[0].name[i]); 10534 $(tddiv).width( ts.p.subGridModel[0].width[i]); 10535 $(trdiv).append(tddiv); 10536 } 10537 $(dummy).append(trdiv); 10538 if (sjxml){ 10539 sgmap = ts.p.jsonReader.subgrid; 10540 result = $.jgrid.getAccessor(sjxml, sgmap.root); 10541 if ( result !== undefined ) { 10542 for (i=0;i<result.length;i++) { 10543 cur = result[i]; 10544 trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>"); 10545 if(sgmap.repeatitems === true) { 10546 if(sgmap.cell) { cur=cur[sgmap.cell]; } 10547 for (j=0;j<cur.length;j++) { 10548 subGridCell(trdiv, cur[j] || ' ',j); 10549 } 10550 } else { 10551 var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name; 10552 if(f.length) { 10553 for (j=0;j<f.length;j++) { 10554 subGridCell(trdiv, cur[f[j]] || ' ',j); 10555 } 10556 } 10557 } 10558 $(dummy).append(trdiv); 10559 } 10560 } 10561 } 10562 var pID = $("table:first",ts.grid.bDiv).attr("id")+"_"; 10563 $("#"+$.jgrid.jqID(pID+sbid)).append(dummy); 10564 ts.grid.hDiv.loading = false; 10565 $("#load_"+$.jgrid.jqID(ts.p.id)).hide(); 10566 return false; 10567 }; 10568 var populatesubgrid = function( rd ) 10569 { 10570 var sid,dp, i, j; 10571 sid = $(rd).attr("id"); 10572 dp = {nd_: (new Date().getTime())}; 10573 dp[ts.p.prmNames.subgridid]=sid; 10574 if(!ts.p.subGridModel[0]) { return false; } 10575 if(ts.p.subGridModel[0].params) { 10576 for(j=0; j < ts.p.subGridModel[0].params.length; j++) { 10577 for(i=0; i<ts.p.colModel.length; i++) { 10578 if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) { 10579 dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\ \;/ig,''); 10580 } 10581 } 10582 } 10583 } 10584 if(!ts.grid.hDiv.loading) { 10585 ts.grid.hDiv.loading = true; 10586 $("#load_"+$.jgrid.jqID(ts.p.id)).show(); 10587 if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; } 10588 if($.isFunction(ts.p.subgridtype)) { 10589 ts.p.subgridtype.call(ts, dp); 10590 } else { 10591 ts.p.subgridtype = ts.p.subgridtype.toLowerCase(); 10592 } 10593 switch(ts.p.subgridtype) { 10594 case "xml": 10595 case "json": 10596 $.ajax($.extend({ 10597 type:ts.p.mtype, 10598 url: ts.p.subGridUrl, 10599 dataType:ts.p.subgridtype, 10600 data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp, 10601 complete: function(sxml) { 10602 if(ts.p.subgridtype === "xml") { 10603 subGridXml(sxml.responseXML, sid); 10604 } else { 10605 subGridJson($.jgrid.parse(sxml.responseText),sid); 10606 } 10607 sxml=null; 10608 } 10609 }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {})); 10610 break; 10611 } 10612 } 10613 return false; 10614 }; 10615 var _id, pID,atd, nhc=0, bfsc, r; 10616 $.each(ts.p.colModel,function(){ 10617 if(this.hidden === true || this.name === 'rn' || this.name === 'cb') { 10618 nhc++; 10619 } 10620 }); 10621 var len = ts.rows.length, i=1; 10622 if( sind !== undefined && sind > 0) { 10623 i = sind; 10624 len = sind+1; 10625 } 10626 while(i < len) { 10627 if($(ts.rows[i]).hasClass('jqgrow')) { 10628 if(ts.p.scroll) { 10629 $(ts.rows[i].cells[pos]).unbind('click'); 10630 } 10631 $(ts.rows[i].cells[pos]).bind('click', function() { 10632 var tr = $(this).parent("tr")[0]; 10633 r = tr.nextSibling; 10634 if($(this).hasClass("sgcollapsed")) { 10635 pID = ts.p.id; 10636 _id = tr.id; 10637 if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) { 10638 atd = pos >=1 ? "<td colspan='"+pos+"'> </td>":""; 10639 bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]); 10640 bfsc = (bfsc === false || bfsc === 'stop') ? false : true; 10641 if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) { 10642 bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id); 10643 } 10644 if(bfsc === false) {return false;} 10645 $(tr).after( "<tr role='row' class='ui-subgrid'>"+atd+"<td class='ui-widget-content subgrid-cell'><span class='ui-icon "+ts.p.subGridOptions.openicon+"'></span></td><td colspan='"+parseInt(ts.p.colNames.length-1-nhc,10)+"' class='ui-widget-content subgrid-data'><div id="+pID+"_"+_id+" class='tablediv'></div></td></tr>" ); 10646 $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
10647 if( $.isFunction(ts.p.subGridRowExpanded)) { 10648 ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id); 10649 } else { 10650 populatesubgrid(tr); 10651 } 10652 } else { 10653 $(r).show(); 10654 } 10655 $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded"); 10656 if(ts.p.subGridOptions.selectOnExpand) { 10657 $(ts).jqGrid('setSelection',_id); 10658 } 10659 } else if($(this).hasClass("sgexpanded")) { 10660 bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]); 10661 bfsc = (bfsc === false || bfsc === 'stop') ? false : true; 10662 _id = tr.id; 10663 if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) { 10664 bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id ); 10665 } 10666 if(bfsc===false) {return false;} 10667 if(ts.p.subGridOptions.reloadOnExpand === true) { 10668 $(r).remove(".ui-subgrid"); 10669 } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting 10670 $(r).hide(); 10671 } 10672 $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed"); 10673 if(ts.p.subGridOptions.selectOnCollapse) { 10674 $(ts).jqGrid('setSelection',_id); 10675 } 10676 } 10677 return false; 10678 }); 10679 } 10680 i++; 10681 } 10682 if(ts.p.subGridOptions.expandOnLoad === true) { 10683 $(ts.rows).filter('.jqgrow').each(function(index,row){ 10684 $(row.cells[0]).click(); 10685 }); 10686 } 10687 ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);}; 10688 ts.subGridJson = function(json,sid) {subGridJson(json,sid);}; 10689 }); 10690}, 10691expandSubGridRow : function(rowid) { 10692 return this.each(function () { 10693 var $t = this; 10694 if(!$t.grid && !rowid) {return;} 10695 if($t.p.subGrid===true) { 10696 var rc = $(this).jqGrid("getInd",rowid,true); 10697 if(rc) { 10698 var sgc = $("td.sgcollapsed",rc)[0]; 10699 if(sgc) { 10700 $(sgc).trigger("click"); 10701 } 10702 } 10703 } 10704 }); 10705}, 10706collapseSubGridRow : function(rowid) { 10707 return this.each(function () { 10708 var $t = this; 10709 if(!$t.grid && !rowid) {return;} 10710 if($t.p.subGrid===true) { 10711 var rc = $(this).jqGrid("getInd",rowid,true); 10712 if(rc) { 10713 var sgc = $("td.sgexpanded",rc)[0]; 10714 if(sgc) { 10715 $(sgc).trigger("click"); 10716 } 10717 } 10718 } 10719 }); 10720}, 10721toggleSubGridRow : function(rowid) { 10722 return this.each(function () { 10723 var $t = this; 10724 if(!$t.grid && !rowid) {return;} 10725 if($t.p.subGrid===true) { 10726 var rc = $(this).jqGrid("getInd",rowid,true); 10727 if(rc) { 10728 var sgc = $("td.sgcollapsed",rc)[0]; 10729 if(sgc) { 10730 $(sgc).trigger("click"); 10731 } else { 10732 sgc = $("td.sgexpanded",rc)[0]; 10733 if(sgc) { 10734 $(sgc).trigger("click"); 10735 } 10736 } 10737 } 10738 } 10739 }); 10740} 10741}); 10742})(jQuery); 10743/** 10744 * jqGrid extension - Tree Grid 10745 * Tony Tomov [email protected] 10746 * http://trirand.com/blog/ 10747 * Dual licensed under the MIT and GPL licenses: 10748 * http://www.opensource.org/licenses/mit-license.php 10749 * http://www.gnu.org/licenses/gpl.html 10750**/ 10751 10752/*jshint eqeqeq:false */ 10753/*global jQuery */ 10754(function($) { 10755"use strict"; 10756$.jgrid.extend({ 10757 setTreeNode : function(i, len){ 10758 return this.each(function(){ 10759 var $t = this; 10760 if( !$t.grid || !$t.p.treeGrid ) {return;} 10761 var expCol = $t.p.expColInd, 10762 expanded = $t.p.treeReader.expanded_field, 10763 isLeaf = $t.p.treeReader.leaf_field, 10764 level = $t.p.treeReader.level_field, 10765 icon = $t.p.treeReader.icon_field, 10766 loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap, 10767 ldat, lf; 10768 while(i<len) { 10769 var ind = $.jgrid.stripPref($t.p.idPrefix, $t.rows[i].id), dind = $t.p._index[ind], expan; 10770 ldat = $t.p.data[dind]; 10771 //$t.rows[i].level = ldat[level]; 10772 if($t.p.treeGridModel === 'nested') { 10773 if(!ldat[isLeaf]) { 10774 lft = parseInt(ldat[$t.p.treeReader.left_field],10); 10775 rgt = parseInt(ldat[$t.p.treeReader.right_field],10); 10776 // NS Model 10777 ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false'; 10778 $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf]; 10779 } 10780 } 10781 //else { 10782 //row.parent_id = rd[$t.p.treeReader.parent_id_field]; 10783 //} 10784 curLevel = parseInt(ldat[level],10); 10785 if($t.p.tree_root_level === 0) { 10786 ident = curLevel+1; 10787 lftpos = curLevel; 10788 } else { 10789 ident = curLevel; 10790 lftpos = curLevel -1; 10791 } 10792 twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>"; 10793 twrap += "<div style='"+($t.p.direction==="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon "; 10794 10795 10796 if(ldat[loaded] !== undefined) { 10797 if(ldat[loaded]==="true" || ldat[loaded]===true) { 10798 ldat[loaded] = true; 10799 } else { 10800 ldat[loaded] = false;
10801 } 10802 } 10803 if(ldat[isLeaf] === "true" || ldat[isLeaf] === true) { 10804 twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick"; 10805 ldat[isLeaf] = true; 10806 lf="leaf"; 10807 } else { 10808 ldat[isLeaf] = false; 10809 lf=""; 10810 } 10811 ldat[expanded] = ((ldat[expanded] === "true" || ldat[expanded] === true) ? true : false) && (ldat[loaded] || ldat[loaded] === undefined); 10812 if(ldat[expanded] === false) { 10813 twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'"); 10814 } else { 10815 twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'"); 10816 } 10817 10818 twrap += "></div></div>"; 10819 $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap); 10820 10821 if(curLevel !== parseInt($t.p.tree_root_level,10)) { 10822 var pn = $($t).jqGrid('getNodeParent',ldat); 10823 expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true; 10824 if( !expan ){ 10825 $($t.rows[i]).css("display","none"); 10826 } 10827 } 10828 $($t.rows[i].cells[expCol]) 10829 .find("div.treeclick") 10830 .bind("click",function(e){ 10831 var target = e.target || e.srcElement, 10832 ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id), 10833 pos = $t.p._index[ind2]; 10834 if(!$t.p.data[pos][isLeaf]){ 10835 if($t.p.data[pos][expanded]){ 10836 $($t).jqGrid("collapseRow",$t.p.data[pos]); 10837 $($t).jqGrid("collapseNode",$t.p.data[pos]); 10838 } else { 10839 $($t).jqGrid("expandRow",$t.p.data[pos]); 10840 $($t).jqGrid("expandNode",$t.p.data[pos]); 10841 } 10842 } 10843 return false; 10844 }); 10845 if($t.p.ExpandColClick === true) { 10846 $($t.rows[i].cells[expCol]) 10847 .find("span.cell-wrapper") 10848 .css("cursor","pointer") 10849 .bind("click",function(e) { 10850 var target = e.target || e.srcElement, 10851 ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id), 10852 pos = $t.p._index[ind2]; 10853 if(!$t.p.data[pos][isLeaf]){ 10854 if($t.p.data[pos][expanded]){ 10855 $($t).jqGrid("collapseRow",$t.p.data[pos]); 10856 $($t).jqGrid("collapseNode",$t.p.data[pos]); 10857 } else { 10858 $($t).jqGrid("expandRow",$t.p.data[pos]); 10859 $($t).jqGrid("expandNode",$t.p.data[pos]); 10860 } 10861 } 10862 $($t).jqGrid("setSelection",ind2); 10863 return false; 10864 }); 10865 } 10866 i++; 10867 } 10868 10869 }); 10870 }, 10871 setTreeGrid : function() { 10872 return this.each(function (){ 10873 var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[]; 10874 if(!$t.p.treeGrid) {return;} 10875 if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});} 10876 $t.p.subGrid = false;$t.p.altRows =false; 10877 $t.p.pgbuttons = false;$t.p.pginput = false; 10878 $t.p.gridview = true; 10879 if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; } 10880 $t.p.multiselect = false;$t.p.rowList = []; 10881 $t.p.expColInd = 0; 10882 pico = 'ui-icon-triangle-1-' + ($t.p.direction==="rtl" ? 'w' : 'e'); 10883 $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {}); 10884 if($t.p.treeGridModel === 'nested') { 10885 $t.p.treeReader = $.extend({ 10886 level_field: "level", 10887 left_field:"lft", 10888 right_field: "rgt", 10889 leaf_field: "isLeaf", 10890 expanded_field: "expanded", 10891 loaded: "loaded", 10892 icon_field: "icon" 10893 },$t.p.treeReader); 10894 } else if($t.p.treeGridModel === 'adjacency') { 10895 $t.p.treeReader = $.extend({ 10896 level_field: "level", 10897 parent_id_field: "parent", 10898 leaf_field: "isLeaf", 10899 expanded_field: "expanded", 10900 loaded: "loaded", 10901 icon_field: "icon" 10902 },$t.p.treeReader ); 10903 } 10904 for ( key in $t.p.colModel){ 10905 if($t.p.colModel.hasOwnProperty(key)) { 10906 nm = $t.p.colModel[key].name; 10907 if( nm === $t.p.ExpandColumn && !ecol ) { 10908 ecol = true; 10909 $t.p.expColInd = i; 10910 } 10911 i++; 10912 // 10913 for(tkey in $t.p.treeReader) { 10914 if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] === nm) { 10915 dupcols.push(nm); 10916 } 10917 } 10918 } 10919 } 10920 $.each($t.p.treeReader,function(j,n){ 10921 if(n && $.inArray(n, dupcols) === -1){ 10922 if(j==='leaf_field') { $t.p._treeleafpos= i; } 10923 i++; 10924 $t.p.colNames.push(n); 10925 $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false}); 10926 } 10927 }); 10928 }); 10929 }, 10930 expandRow: function (record){ 10931 this.each(function(){ 10932 var $t = this; 10933 if(!$t.grid || !$t.p.treeGrid) {return;} 10934 var childern = $($t).jqGrid("getNodeChildren",record), 10935 //if ($($t).jqGrid("isVisibleNode",record)) { 10936 expanded = $t.p.treeReader.expanded_field; 10937 $(childern).each(function(){ 10938 var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id); 10939 $($($t).jqGrid('getGridRowById', id)).css("display",""); 10940 if(this[expanded]) { 10941 $($t).jqGrid("expandRow",this); 10942 } 10943 }); 10944 //} 10945 }); 10946 }, 10947 collapseRow : function (record) { 10948 this.each(function(){ 10949 var $t = this; 10950 if(!$t.grid || !$t.p.treeGrid) {return;} 10951 var childern = $($t).jqGrid("getNodeChildren",record), 10952 expanded = $t.p.treeReader.expanded_field; 10953 $(childern).each(function(){ 10954 var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id); 10955 $($($t).jqGrid('getGridRowById', id)).css("display","none"); 10956 if(this[expanded]){ 10957 $($t).jqGrid("collapseRow",this); 10958 } 10959 }); 10960 }); 10961 }, 10962 // NS ,adjacency models 10963 getRootNodes : function() { 10964 var result = []; 10965 this.each(function(){ 10966 var $t = this; 10967 if(!$t.grid || !$t.p.treeGrid) {return;} 10968 switch ($t.p.treeGridModel) { 10969 case 'nested' : 10970 var level = $t.p.treeReader.level_field; 10971 $($t.p.data).each(function(){ 10972 if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) { 10973 result.push(this); 10974 } 10975 }); 10976 break; 10977 case 'adjacency' : 10978 var parent_id = $t.p.treeReader.parent_id_field; 10979 $($t.p.data).each(function(){ 10980 if(this[parent_id] === null || String(this[parent_id]).toLowerCase() === "null") { 10981 result.push(this); 10982 } 10983 }); 10984 break; 10985 } 10986 }); 10987 return result; 10988 }, 10989 getNodeDepth : function(rc) { 10990 var ret = null; 10991 this.each(function(){ 10992 if(!this.grid || !this.p.treeGrid) {return;} 10993 var $t = this; 10994 switch ($t.p.treeGridModel) { 10995 case 'nested' : 10996 var level = $t.p.treeReader.level_field; 10997 ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10); 10998 break; 10999 case 'adjacency' : 11000 ret = $($t).jqGrid("getNodeAncestors",rc).length; 11001 break; 11002 } 11003 }); 11004 return ret; 11005 }, 11006 getNodeParent : function(rc) { 11007 var result = null; 11008 this.each(function(){ 11009 var $t = this; 11010 if(!$t.grid || !$t.p.treeGrid) {return;} 11011 switch ($t.p.treeGridModel) { 11012 case 'nested' : 11013 var lftc = $t.p.treeReader.left_field, 11014 rgtc = $t.p.treeReader.right_field, 11015 levelc = $t.p.treeReader.level_field, 11016 lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10); 11017 $(this.p.data).each(function(){ 11018 if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) { 11019 result = this; 11020 return false;
11021 } 11022 }); 11023 break; 11024 case 'adjacency' : 11025 var parent_id = $t.p.treeReader.parent_id_field, 11026 dtid = $t.p.localReader.id, 11027 ind = rc[dtid], pos = $t.p._index[ind]; 11028 while(pos--) { 11029 if($t.p.data[pos][dtid] === $.jgrid.stripPref($t.p.idPrefix, rc[parent_id])) { 11030 result = $t.p.data[pos]; 11031 break; 11032 } 11033 } 11034 break; 11035 } 11036 }); 11037 return result; 11038 }, 11039 getNodeChildren : function(rc) { 11040 var result = []; 11041 this.each(function(){ 11042 var $t = this; 11043 if(!$t.grid || !$t.p.treeGrid) {return;} 11044 switch ($t.p.treeGridModel) { 11045 case 'nested' : 11046 var lftc = $t.p.treeReader.left_field, 11047 rgtc = $t.p.treeReader.right_field, 11048 levelc = $t.p.treeReader.level_field, 11049 lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10); 11050 $(this.p.data).each(function(){ 11051 if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) { 11052 result.push(this); 11053 } 11054 }); 11055 break; 11056 case 'adjacency' : 11057 var parent_id = $t.p.treeReader.parent_id_field, 11058 dtid = $t.p.localReader.id; 11059 $(this.p.data).each(function(){ 11060 if(this[parent_id] == $.jgrid.stripPref($t.p.idPrefix, rc[dtid])) { 11061 result.push(this); 11062 } 11063 }); 11064 break; 11065 } 11066 }); 11067 return result; 11068 }, 11069 getFullTreeNode : function(rc) { 11070 var result = []; 11071 this.each(function(){ 11072 var $t = this, len; 11073 if(!$t.grid || !$t.p.treeGrid) {return;} 11074 switch ($t.p.treeGridModel) { 11075 case 'nested' : 11076 var lftc = $t.p.treeReader.left_field, 11077 rgtc = $t.p.treeReader.right_field, 11078 levelc = $t.p.treeReader.level_field, 11079 lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10); 11080 $(this.p.data).each(function(){ 11081 if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) { 11082 result.push(this); 11083 } 11084 }); 11085 break; 11086 case 'adjacency' : 11087 if(rc) { 11088 result.push(rc); 11089 var parent_id = $t.p.treeReader.parent_id_field, 11090 dtid = $t.p.localReader.id; 11091 $(this.p.data).each(function(i){ 11092 len = result.length; 11093 for (i = 0; i < len; i++) { 11094 if ($.jgrid.stripPref($t.p.idPrefix, result[i][dtid]) === this[parent_id]) { 11095 result.push(this); 11096 break; 11097 } 11098 } 11099 }); 11100 } 11101 break; 11102 } 11103 }); 11104 return result; 11105 }, 11106 // End NS, adjacency Model 11107 getNodeAncestors : function(rc) { 11108 var ancestors = []; 11109 this.each(function(){ 11110 if(!this.grid || !this.p.treeGrid) {return;} 11111 var parent = $(this).jqGrid("getNodeParent",rc); 11112 while (parent) { 11113 ancestors.push(parent); 11114 parent = $(this).jqGrid("getNodeParent",parent); 11115 } 11116 }); 11117 return ancestors; 11118 }, 11119 isVisibleNode : function(rc) { 11120 var result = true; 11121 this.each(function(){ 11122 var $t = this; 11123 if(!$t.grid || !$t.p.treeGrid) {return;} 11124 var ancestors = $($t).jqGrid("getNodeAncestors",rc), 11125 expanded = $t.p.treeReader.expanded_field; 11126 $(ancestors).each(function(){ 11127 result = result && this[expanded]; 11128 if(!result) {return false;} 11129 }); 11130 }); 11131 return result; 11132 }, 11133 isNodeLoaded : function(rc) { 11134 var result; 11135 this.each(function(){ 11136 var $t = this; 11137 if(!$t.grid || !$t.p.treeGrid) {return;} 11138 var isLeaf = $t.p.treeReader.leaf_field, 11139 loaded = $t.p.treeReader.loaded; 11140 if(rc !== undefined ) { 11141 if(rc[loaded] !== undefined) { 11142 result = rc[loaded]; 11143 } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){ 11144 result = true; 11145 } else { 11146 result = false;
11147 } 11148 } else { 11149 result = false; 11150 } 11151 }); 11152 return result; 11153 }, 11154 expandNode : function(rc) { 11155 return this.each(function(){ 11156 if(!this.grid || !this.p.treeGrid) {return;} 11157 var expanded = this.p.treeReader.expanded_field, 11158 parent = this.p.treeReader.parent_id_field, 11159 loaded = this.p.treeReader.loaded, 11160 level = this.p.treeReader.level_field, 11161 lft = this.p.treeReader.left_field, 11162 rgt = this.p.treeReader.right_field; 11163 11164 if(!rc[expanded]) { 11165 var id = $.jgrid.getAccessor(rc,this.p.localReader.id); 11166 var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0]; 11167 var position = this.p._index[id]; 11168 if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) { 11169 rc[expanded] = true; 11170 $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus"); 11171 } else if (!this.grid.hDiv.loading) { 11172 rc[expanded] = true; 11173 $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus"); 11174 this.p.treeANode = rc1.rowIndex; 11175 this.p.datatype = this.p.treedatatype; 11176 if(this.p.treeGridModel === 'nested') { 11177 $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}}); 11178 } else { 11179 $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} ); 11180 } 11181 $(this).trigger("reloadGrid"); 11182 rc[loaded] = true; 11183 if(this.p.treeGridModel === 'nested') { 11184 $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}}); 11185 } else { 11186 $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}}); 11187 } 11188 } 11189 } 11190 }); 11191 }, 11192 collapseNode : function(rc) { 11193 return this.each(function(){ 11194 if(!this.grid || !this.p.treeGrid) {return;} 11195 var expanded = this.p.treeReader.expanded_field; 11196 if(rc[expanded]) { 11197 rc[expanded] = false; 11198 var id = $.jgrid.getAccessor(rc,this.p.localReader.id); 11199 var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0]; 11200 $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus"); 11201 } 11202 }); 11203 }, 11204 SortTree : function( sortname, newDir, st, datefmt) { 11205 return this.each(function(){ 11206 if(!this.grid || !this.p.treeGrid) {return;} 11207 var i, len, 11208 rec, records = [], $t = this, query, roots, 11209 rt = $(this).jqGrid("getRootNodes"); 11210 // Sorting roots 11211 query = $.jgrid.from(rt); 11212 query.orderBy(sortname,newDir,st, datefmt); 11213 roots = query.select(); 11214 11215 // Sorting children 11216 for (i = 0, len = roots.length; i < len; i++) { 11217 rec = roots[i]; 11218 records.push(rec); 11219 $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt); 11220 } 11221 $.each(records, function(index) { 11222 var id = $.jgrid.getAccessor(this,$t.p.localReader.id); 11223 $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id),$t.grid.bDiv)); 11224 }); 11225 query = null;roots=null;records=null; 11226 }); 11227 }, 11228 collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) { 11229 return this.each(function(){ 11230 if(!this.grid || !this.p.treeGrid) {return;} 11231 var i, len, 11232 child, ch, query, children; 11233 ch = $(this).jqGrid("getNodeChildren",rec); 11234 query = $.jgrid.from(ch); 11235 query.orderBy(sortname, newDir, st, datefmt); 11236 children = query.select(); 11237 for (i = 0, len = children.length; i < len; i++) { 11238 child = children[i]; 11239 records.push(child); 11240 $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt); 11241 } 11242 }); 11243 }, 11244 // experimental 11245 setTreeRow : function(rowid, data) { 11246 var success=false; 11247 this.each(function(){ 11248 var t = this; 11249 if(!t.grid || !t.p.treeGrid) {return;} 11250 success = $(t).jqGrid("setRowData",rowid,data); 11251 }); 11252 return success; 11253 }, 11254 delTreeNode : function (rowid) { 11255 return this.each(function () { 11256 var $t = this, rid = $t.p.localReader.id, i, 11257 left = $t.p.treeReader.left_field, 11258 right = $t.p.treeReader.right_field, myright, width, res, key; 11259 if(!$t.grid || !$t.p.treeGrid) {return;} 11260 var rc = $t.p._index[rowid]; 11261 if (rc !== undefined) { 11262 // nested 11263 myright = parseInt($t.p.data[rc][right],10); 11264 width = myright - parseInt($t.p.data[rc][left],10) + 1; 11265 var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]); 11266 if(dr.length>0){ 11267 for (i=0;i<dr.length;i++){ 11268 $($t).jqGrid("delRowData",dr[i][rid]); 11269 } 11270 } 11271 if( $t.p.treeGridModel === "nested") { 11272 // ToDo - update grid data 11273 res = $.jgrid.from($t.p.data) 11274 .greater(left,myright,{stype:'integer'}) 11275 .select(); 11276 if(res.length) { 11277 for( key in res) { 11278 if(res.hasOwnProperty(key)) { 11279 res[key][left] = parseInt(res[key][left],10) - width ; 11280 } 11281 } 11282 } 11283 res = $.jgrid.from($t.p.data) 11284 .greater(right,myright,{stype:'integer'}) 11285 .select(); 11286 if(res.length) { 11287 for( key in res) { 11288 if(res.hasOwnProperty(key)) { 11289 res[key][right] = parseInt(res[key][right],10) - width ; 11290 } 11291 } 11292 } 11293 } 11294 } 11295 }); 11296 }, 11297 addChildNode : function( nodeid, parentid, data, expandData ) { 11298 //return this.each(function(){ 11299 var $t = this[0]; 11300 if(data) { 11301 // we suppose tha the id is autoincremet and 11302 var expanded = $t.p.treeReader.expanded_field, 11303 isLeaf = $t.p.treeReader.leaf_field, 11304 level = $t.p.treeReader.level_field, 11305 //icon = $t.p.treeReader.icon_field, 11306 parent = $t.p.treeReader.parent_id_field, 11307 left = $t.p.treeReader.left_field, 11308 right = $t.p.treeReader.right_field, 11309 loaded = $t.p.treeReader.loaded, 11310 method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright; 11311 if(expandData===undefined) {expandData = false;} 11312 if ( nodeid === undefined || nodeid === null ) { 11313 i = $t.p.data.length-1; 11314 if( i>= 0 ) { 11315 while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;} 11316 } 11317 nodeid = max+1; 11318 } 11319 var prow = $($t).jqGrid('getInd', parentid); 11320 leaf = false;
11321 // if not a parent we assume root 11322 if ( parentid === undefined || parentid === null || parentid==="") { 11323 parentid = null; 11324 rowind = null; 11325 method = 'last'; 11326 parentlevel = $t.p.tree_root_level; 11327 i = $t.p.data.length+1; 11328 } else { 11329 method = 'after'; 11330 parentindex = $t.p._index[parentid]; 11331 parentdata = $t.p.data[parentindex]; 11332 parentid = parentdata[$t.p.localReader.id]; 11333 parentlevel = parseInt(parentdata[level],10)+1; 11334 var childs = $($t).jqGrid('getFullTreeNode', parentdata); 11335 // if there are child nodes get the last index of it 11336 if(childs.length) { 11337 i = childs[childs.length-1][$t.p.localReader.id]; 11338 rowind = i; 11339 i = $($t).jqGrid('getInd',rowind)+1; 11340 } else { 11341 i = $($t).jqGrid('getInd', parentid)+1; 11342 } 11343 // if the node is leaf 11344 if(parentdata[isLeaf]) { 11345 leaf = true; 11346 parentdata[expanded] = true; 11347 //var prow = $($t).jqGrid('getInd', parentid); 11348 $($t.rows[prow]) 11349 .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper") 11350 .end() 11351 .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus"); 11352 $t.p.data[parentindex][isLeaf] = false; 11353 parentdata[loaded] = true; 11354 } 11355 } 11356 len = i+1; 11357 11358 if( data[expanded]===undefined) {data[expanded]= false;} 11359 if( data[loaded]===undefined ) { data[loaded] = false;} 11360 data[level] = parentlevel; 11361 if( data[isLeaf]===undefined) {data[isLeaf]= true;} 11362 if( $t.p.treeGridModel === "adjacency") { 11363 data[parent] = parentid; 11364 } 11365 if( $t.p.treeGridModel === "nested") { 11366 // this method requiere more attention 11367 var query, res, key; 11368 //maxright = parseInt(maxright,10); 11369 // ToDo - update grid data 11370 if(parentid !== null) { 11371 maxright = parseInt(parentdata[right],10); 11372 query = $.jgrid.from($t.p.data); 11373 query = query.greaterOrEquals(right,maxright,{stype:'integer'}); 11374 res = query.select(); 11375 if(res.length) { 11376 for( key in res) { 11377 if(res.hasOwnProperty(key)) { 11378 res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left]; 11379 res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right]; 11380 } 11381 } 11382 } 11383 data[left] = maxright; 11384 data[right]= maxright+1; 11385 } else { 11386 maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10); 11387 res = $.jgrid.from($t.p.data) 11388 .greater(left,maxright,{stype:'integer'}) 11389 .select(); 11390 if(res.length) { 11391 for( key in res) { 11392 if(res.hasOwnProperty(key)) { 11393 res[key][left] = parseInt(res[key][left],10) +2 ; 11394 } 11395 } 11396 } 11397 res = $.jgrid.from($t.p.data) 11398 .greater(right,maxright,{stype:'integer'}) 11399 .select(); 11400 if(res.length) { 11401 for( key in res) { 11402 if(res.hasOwnProperty(key)) { 11403 res[key][right] = parseInt(res[key][right],10) +2 ; 11404 } 11405 } 11406 } 11407 data[left] = maxright+1; 11408 data[right] = maxright + 2; 11409 } 11410 } 11411 if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) { 11412 $($t).jqGrid('addRowData', nodeid, data, method, rowind); 11413 $($t).jqGrid('setTreeNode', i, len); 11414 } 11415 if(parentdata && !parentdata[expanded] && expandData) { 11416 $($t.rows[prow]) 11417 .find("div.treeclick") 11418 .click(); 11419 } 11420 } 11421 //}); 11422 } 11423}); 11424})(jQuery); 11425/*jshint eqeqeq:false, eqnull:true */ 11426/*global jQuery */ 11427// Grouping module 11428(function($){ 11429"use strict"; 11430$.extend($.jgrid,{ 11431 template : function(format){ //jqgformat 11432 var args = $.makeArray(arguments).slice(1), j, al = args.length; 11433 if(format==null) { format = ""; } 11434 return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){ 11435 if(!isNaN(parseInt(i,10))) { 11436 return args[parseInt(i,10)]; 11437 } 11438 for(j=0; j < al;j++) { 11439 if($.isArray(args[j])) { 11440 var nmarr = args[ j ], 11441 k = nmarr.length; 11442 while(k--) { 11443 if(i===nmarr[k].nm) { 11444 return nmarr[k].v; 11445 } 11446 } 11447 } 11448 } 11449 }); 11450 } 11451}); 11452$.jgrid.extend({ 11453 groupingSetup : function () { 11454 return this.each(function (){ 11455 var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView; 11456 if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) { 11457 if(!grp.groupField.length) { 11458 $t.p.grouping = false;
11459 } else { 11460 if (grp.visibiltyOnNextGrouping === undefined) { 11461 grp.visibiltyOnNextGrouping = []; 11462 } 11463 11464 grp.lastvalues=[]; 11465 if(!grp._locgr) { 11466 grp.groups =[]; 11467 } 11468 grp.counters =[]; 11469 for(i=0;i<grp.groupField.length;i++) { 11470 if(!grp.groupOrder[i]) { 11471 grp.groupOrder[i] = 'asc'; 11472 } 11473 if(!grp.groupText[i]) { 11474 grp.groupText[i] = '{0}'; 11475 } 11476 if( typeof grp.groupColumnShow[i] !== 'boolean') { 11477 grp.groupColumnShow[i] = true; 11478 } 11479 if( typeof grp.groupSummary[i] !== 'boolean') { 11480 grp.groupSummary[i] = false; 11481 } 11482 if( !grp.groupSummaryPos[i]) { 11483 grp.groupSummaryPos[i] = 'footer'; 11484 } 11485 if(grp.groupColumnShow[i] === true) { 11486 grp.visibiltyOnNextGrouping[i] = true; 11487 $($t).jqGrid('showCol',grp.groupField[i]); 11488 } else { 11489 grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id+"_"+grp.groupField[i])).is(":visible"); 11490 $($t).jqGrid('hideCol',grp.groupField[i]); 11491 } 11492 } 11493 grp.summary =[]; 11494 if(grp.hideFirstGroupCol) { 11495 grp.formatDisplayField[0] = function (v) { return v;}; 11496 } 11497 for(j=0, cml = cm.length; j < cml; j++) { 11498 if(grp.hideFirstGroupCol) { 11499 if(!cm[j].hidden && grp.groupField[0] === cm[j].name) { 11500 cm[j].formatter = function(){return '';}; 11501 } 11502 } 11503 if(cm[j].summaryType ) { 11504 if(cm[j].summaryDivider) { 11505 grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sd:cm[j].summaryDivider, vd:'', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'}); 11506 } else { 11507 grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'}); 11508 } 11509 } 11510 } 11511 } 11512 } else { 11513 $t.p.grouping = false; 11514 } 11515 }); 11516 }, 11517 groupingPrepare : function ( record, irow ) { 11518 this.each(function(){ 11519 var grp = this.p.groupingView, $t= this, i, 11520 grlen = grp.groupField.length, 11521 fieldName, 11522 v, 11523 displayName, 11524 displayValue, 11525 changed = 0; 11526 for(i=0;i<grlen;i++) { 11527 fieldName = grp.groupField[i]; 11528 displayName = grp.displayField[i]; 11529 v = record[fieldName]; 11530 displayValue = displayName == null ? null : record[displayName]; 11531 11532 if( displayValue == null ) { 11533 displayValue = v; 11534 } 11535 if( v !== undefined ) { 11536 if(irow === 0 ) { 11537 // First record always starts a new group 11538 grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } ); 11539 grp.lastvalues[i] = v; 11540 grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)}; 11541 $.each(grp.counters[i].summary,function() { 11542 if ($.isFunction(this.st)) { 11543 this.v = this.st.call($t, this.v, this.nm, record); 11544 } else { 11545 this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record); 11546 if(this.st.toLowerCase() === 'avg' && this.sd) { 11547 this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record); 11548 } 11549 } 11550 }); 11551 grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary; 11552 } else { 11553 if (typeof v !== "object" && ($.isArray(grp.isInTheSameGroup) && $.isFunction(grp.isInTheSameGroup[i]) ? ! grp.isInTheSameGroup[i].call($t, grp.lastvalues[i], v, i, grp): grp.lastvalues[i] !== v)) { 11554 // This record is not in same group as previous one 11555 grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } ); 11556 grp.lastvalues[i] = v; 11557 changed = 1; 11558 grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)}; 11559 $.each(grp.counters[i].summary,function() { 11560 if ($.isFunction(this.st)) { 11561 this.v = this.st.call($t, this.v, this.nm, record); 11562 } else { 11563 this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record); 11564 if(this.st.toLowerCase() === 'avg' && this.sd) { 11565 this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record); 11566 } 11567 } 11568 }); 11569 grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary; 11570 } else { 11571 if (changed === 1) { 11572 // This group has changed because an earlier group changed. 11573 grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } ); 11574 grp.lastvalues[i] = v; 11575 grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)}; 11576 $.each(grp.counters[i].summary,function() { 11577 if ($.isFunction(this.st)) { 11578 this.v = this.st.call($t, this.v, this.nm, record); 11579 } else { 11580 this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record); 11581 if(this.st.toLowerCase() === 'avg' && this.sd) { 11582 this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record); 11583 } 11584 } 11585 }); 11586 grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary; 11587 } else { 11588 grp.counters[i].cnt += 1; 11589 grp.groups[grp.counters[i].pos].cnt = grp.counters[i].cnt; 11590 $.each(grp.counters[i].summary,function() { 11591 if ($.isFunction(this.st)) { 11592 this.v = this.st.call($t, this.v, this.nm, record); 11593 } else { 11594 this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record); 11595 if(this.st.toLowerCase() === 'avg' && this.sd) { 11596 this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record); 11597 } 11598 } 11599 }); 11600 grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary; 11601 } 11602 } 11603 } 11604 } 11605 } 11606 //gdata.push( rData ); 11607 }); 11608 return this; 11609 }, 11610 groupingToggle : function(hid){ 11611 this.each(function(){ 11612 var $t = this, 11613 grp = $t.p.groupingView, 11614 strpos = hid.split('_'), 11615 num = parseInt(strpos[strpos.length-2], 10); 11616 strpos.splice(strpos.length-2,2); 11617 var uid = strpos.join("_"), 11618 minus = grp.minusicon, 11619 plus = grp.plusicon, 11620 tar = $("#"+$.jgrid.jqID(hid)), 11621 r = tar.length ? tar[0].nextSibling : null, 11622 tarspan = $("#"+$.jgrid.jqID(hid)+" span."+"tree-wrap-"+$t.p.direction), 11623 getGroupingLevelFromClass = function (className) { 11624 var nums = $.map(className.split(" "), function (item) { 11625 if (item.substring(0, uid.length + 1) === uid + "_") { 11626 return parseInt(item.substring(uid.length + 1), 10); 11627 } 11628 }); 11629 return nums.length > 0 ? nums[0] : undefined; 11630 }, 11631 itemGroupingLevel, 11632 showData, 11633 collapsed = false, 11634 frz = $t.p.frozenColumns ? $t.p.id+"_frozen" : false, 11635 tar2 = frz ? $("#"+$.jgrid.jqID(hid), "#"+$.jgrid.jqID(frz) ) : false, 11636 r2 = (tar2 && tar2.length) ? tar2[0].nextSibling : null; 11637 if( tarspan.hasClass(minus) ) { 11638 if(grp.showSummaryOnHide) { 11639 if(r){ 11640 while(r) { 11641 if($(r).hasClass('jqfoot') ) { 11642 var lv = parseInt($(r).attr("jqfootlevel"),10); 11643 if( lv <= num) { 11644 break; 11645 } 11646 } 11647 $(r).hide(); 11648 r = r.nextSibling; 11649 if(frz) { 11650 $(r2).hide(); 11651 r2 = r2.nextSibling; 11652 } 11653 } 11654 } 11655 } else { 11656 if(r){ 11657 while(r) { 11658 itemGroupingLevel = getGroupingLevelFromClass(r.className); 11659 if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) { 11660 break; 11661 } 11662 $(r).hide(); 11663 r = r.nextSibling; 11664 if(frz) { 11665 $(r2).hide(); 11666 r2 = r2.nextSibling; 11667 } 11668 } 11669 } 11670 } 11671 tarspan.removeClass(minus).addClass(plus); 11672 collapsed = true; 11673 } else { 11674 if(r){ 11675 showData = undefined; 11676 while(r) { 11677 itemGroupingLevel = getGroupingLevelFromClass(r.className); 11678 if (showData === undefined) { 11679 showData = itemGroupingLevel === undefined; // if the first row after the opening group is data row then show the data rows 11680 } 11681 if (itemGroupingLevel !== undefined) { 11682 if (itemGroupingLevel <= num) { 11683 break;// next item of the same lever are found 11684 } 11685 if (itemGroupingLevel === num + 1) { 11686 $(r).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus); 11687 if(frz) { 11688 $(r2).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus); 11689 } 11690 } 11691 } else if (showData) { 11692 $(r).show(); 11693 if(frz) { 11694 $(r2).show(); 11695 } 11696 } 11697 r = r.nextSibling; 11698 if(frz) { 11699 r2 = r2.nextSibling; 11700 } 11701 } 11702 } 11703 tarspan.removeClass(plus).addClass(minus); 11704 } 11705 $($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]); 11706 if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); } 11707 11708 }); 11709 return false;
11710 }, 11711 groupingRender : function (grdata, colspans, page, rn ) { 11712 return this.each(function(){ 11713 var $t = this, 11714 grp = $t.p.groupingView, 11715 str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length; 11716 pmrtl += " tree-wrap-"+$t.p.direction; 11717 $.each($t.p.colModel, function (i,n){ 11718 var ii; 11719 for(ii=0;ii<len;ii++) { 11720 if(grp.groupField[ii] === n.name ) { 11721 cp[ii] = i; 11722 break; 11723 } 11724 } 11725 }); 11726 var toEnd = 0; 11727 function findGroupIdx( ind , offset, grp) { 11728 var ret = false, i; 11729 if(offset===0) { 11730 ret = grp[ind]; 11731 } else { 11732 var id = grp[ind].idx; 11733 if(id===0) { 11734 ret = grp[ind]; 11735 } else { 11736 for(i=ind;i >= 0; i--) { 11737 if(grp[i].idx === id-offset) { 11738 ret = grp[i]; 11739 break; 11740 } 11741 } 11742 } 11743 } 11744 return ret; 11745 } 11746 function buildSummaryTd(i, ik, grp, foffset) { 11747 var fdata = findGroupIdx(i, ik, grp), 11748 cm = $t.p.colModel, 11749 vv, grlen = fdata.cnt, str="", k; 11750 for(k=foffset; k<colspans;k++) { 11751 var tmpdata = "<td "+$t.formatCol(k,1,'')+"> </td>", 11752 tplfld = "{0}"; 11753 $.each(fdata.summary,function(){ 11754 if(this.nm === cm[k].name) { 11755 if(cm[k].summaryTpl) { 11756 tplfld = cm[k].summaryTpl; 11757 } 11758 if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') { 11759 if(this.sd && this.vd) { 11760 this.v = (this.v/this.vd); 11761 } else if(this.v && grlen > 0) { 11762 this.v = (this.v/grlen); 11763 } 11764 } 11765 try { 11766 this.groupCount = fdata.cnt; 11767 this.groupIndex = fdata.dataIndex; 11768 this.groupValue = fdata.value; 11769 vv = $t.formatter('', this.v, k, this); 11770 } catch (ef) { 11771 vv = this.v; 11772 } 11773 tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>"; 11774 return false; 11775 } 11776 }); 11777 str += tmpdata; 11778 } 11779 return str; 11780 } 11781 var sumreverse = $.makeArray(grp.groupSummary), mul; 11782 sumreverse.reverse(); 11783 mul = $t.p.multiselect ? " colspan=\"2\"" : ""; 11784 $.each(grp.groups,function(i,n){ 11785 if(grp._locgr) { 11786 if( !(n.startRow +n.cnt > (page-1)*rn && n.startRow < page*rn)) { 11787 return true; 11788 } 11789 } 11790 toEnd++; 11791 clid = $t.p.id+"ghead_"+n.idx; 11792 hid = clid+"_"+i; 11793 icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>"; 11794 try { 11795 if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) { 11796 n.displayValue = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp); 11797 gv = n.displayValue; 11798 } else { 11799 gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value ); 11800 } 11801 } catch (egv) { 11802 gv = n.displayValue; 11803 } 11804 if(grp.groupSummaryPos[n.idx] === 'header') { 11805 str += "<tr id=\""+hid+"\"" +(grp.groupCollapse && n.idx>0 ? " style=\"display:none;\" " : " ") + "role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\"" + mul +">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td>"; 11806 str += buildSummaryTd(i, n.idx-1, grp.groups, (mul ==="") ? 1 : 2 ); 11807 str += "</tr>"; 11808 } else { 11809 str += "<tr id=\""+hid+"\"" +(grp.groupCollapse && n.idx>0 ? " style=\"display:none;\" " : " ") + "role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\" colspan=\""+colspans+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td></tr>"; 11810 } 11811 var leaf = len-1 === n.idx; 11812 if( leaf ) { 11813 var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow, 11814 end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt; 11815 if(grp._locgr) { 11816 offset = (page-1)*rn; 11817 if(offset > n.startRow) { 11818 sgr = offset; 11819 } 11820 } 11821 for(kk=sgr;kk<end;kk++) { 11822 if(!grdata[kk - offset]) { break; } 11823 str += grdata[kk - offset].join(''); 11824 } 11825 if(grp.groupSummaryPos[n.idx] !== 'header') { 11826 var jj; 11827 if (gg !== undefined) { 11828 for (jj = 0; jj < grp.groupField.length; jj++) { 11829 if (gg.dataIndex === grp.groupField[jj]) { 11830 break; 11831 } 11832 } 11833 toEnd = grp.groupField.length - jj; 11834 } 11835 for (ik = 0; ik < toEnd; ik++) { 11836 if(!sumreverse[ik]) { continue; } 11837 var hhdr = ""; 11838 if(grp.groupCollapse && !grp.showSummaryOnHide) { 11839 hhdr = " style=\"display:none;\""; 11840 } 11841 str += "<tr"+hhdr+" jqfootlevel=\""+(n.idx-ik)+"\" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">"; 11842 str += buildSummaryTd(i, ik, grp.groups, 0); 11843 str += "</tr>"; 11844 } 11845 toEnd = jj; 11846 } 11847 } 11848 }); 11849 $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str); 11850 // free up memory 11851 str = null; 11852 }); 11853 }, 11854 groupingGroupBy : function (name, options ) { 11855 return this.each(function(){ 11856 var $t = this; 11857 if(typeof name === "string") { 11858 name = [name]; 11859 } 11860 var grp = $t.p.groupingView; 11861 $t.p.grouping = true; 11862 11863 //Set default, in case visibilityOnNextGrouping is undefined 11864 if (grp.visibiltyOnNextGrouping === undefined) { 11865 grp.visibiltyOnNextGrouping = []; 11866 } 11867 var i; 11868 // show previous hidden groups if they are hidden and weren't removed yet 11869 for(i=0;i<grp.groupField.length;i++) { 11870 if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) { 11871 $($t).jqGrid('showCol',grp.groupField[i]); 11872 } 11873 } 11874 // set visibility status of current group columns on next grouping 11875 for(i=0;i<name.length;i++) { 11876 grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(name[i])).is(":visible"); 11877 } 11878 $t.p.groupingView = $.extend($t.p.groupingView, options || {}); 11879 grp.groupField = name; 11880 $($t).trigger("reloadGrid"); 11881 }); 11882 }, 11883 groupingRemove : function (current) { 11884 return this.each(function(){ 11885 var $t = this; 11886 if(current === undefined) { 11887 current = true; 11888 } 11889 $t.p.grouping = false;
11890 if(current===true) { 11891 var grp = $t.p.groupingView, i; 11892 // show previous hidden groups if they are hidden and weren't removed yet 11893 for(i=0;i<grp.groupField.length;i++) { 11894 if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) { 11895 $($t).jqGrid('showCol', grp.groupField); 11896 } 11897 } 11898 $("tr.jqgroup, tr.jqfoot","#"+$.jgrid.jqID($t.p.id)+" tbody:first").remove(); 11899 $("tr.jqgrow:hidden","#"+$.jgrid.jqID($t.p.id)+" tbody:first").show(); 11900 } else { 11901 $($t).trigger("reloadGrid"); 11902 } 11903 }); 11904 }, 11905 groupingCalculations : { 11906 handler: function(fn, v, field, round, roundType, rc) { 11907 var funcs = { 11908 sum: function() { 11909 return parseFloat(v||0) + parseFloat((rc[field]||0)); 11910 }, 11911 11912 min: function() { 11913 if(v==="") { 11914 return parseFloat(rc[field]||0); 11915 } 11916 return Math.min(parseFloat(v),parseFloat(rc[field]||0)); 11917 }, 11918 11919 max: function() { 11920 if(v==="") { 11921 return parseFloat(rc[field]||0); 11922 } 11923 return Math.max(parseFloat(v),parseFloat(rc[field]||0)); 11924 }, 11925 11926 count: function() { 11927 if(v==="") {v=0;} 11928 if(rc.hasOwnProperty(field)) { 11929 return v+1; 11930 } 11931 return 0; 11932 }, 11933 11934 avg: function() { 11935 // the same as sum, but at end we divide it 11936 // so use sum instead of duplicating the code (?) 11937 return funcs.sum(); 11938 } 11939 }; 11940 11941 if(!funcs[fn]) { 11942 throw ("jqGrid Grouping No such method: " + fn); 11943 } 11944 var res = funcs[fn](); 11945 11946 if (round != null) { 11947 if (roundType === 'fixed') { 11948 res = res.toFixed(round); 11949 } else { 11950 var mul = Math.pow(10, round); 11951 res = Math.round(res * mul) / mul; 11952 } 11953 } 11954 11955 return res; 11956 } 11957 } 11958}); 11959})(jQuery); 11960/*jshint eqeqeq:false, eqnull:true, devel:true */ 11961/*global jQuery, xmlJsonClass */ 11962(function($){ 11963/* 11964 * jqGrid extension for constructing Grid Data from external file 11965 * Tony Tomov [email protected] 11966 * http://trirand.com/blog/ 11967 * Dual licensed under the MIT and GPL licenses: 11968 * http://www.opensource.org/licenses/mit-license.php 11969 * http://www.gnu.org/licenses/gpl-2.0.html 11970**/ 11971 11972"use strict"; 11973 $.jgrid.extend({ 11974 jqGridImport : function(o) { 11975 o = $.extend({ 11976 imptype : "xml", // xml, json, xmlstring, jsonstring 11977 impstring: "", 11978 impurl: "", 11979 mtype: "GET", 11980 impData : {}, 11981 xmlGrid :{ 11982 config : "roots>grid", 11983 data: "roots>rows" 11984 }, 11985 jsonGrid :{ 11986 config : "grid", 11987 data: "data" 11988 }, 11989 ajaxOptions :{} 11990 }, o || {}); 11991 return this.each(function(){ 11992 var $t = this; 11993 var xmlConvert = function (xml,o) { 11994 var cnfg = $(o.xmlGrid.config,xml)[0]; 11995 var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1, key; 11996 if(xmlJsonClass.xml2json && $.jgrid.parse) { 11997 jstr = xmlJsonClass.xml2json(cnfg," "); 11998 jstr = $.jgrid.parse(jstr); 11999 for(key in jstr) { 12000 if(jstr.hasOwnProperty(key)) { 12001 jstr1=jstr[key]; 12002 } 12003 } 12004 if(xmldata) { 12005 // save the datatype 12006 var svdatatype = jstr.grid.datatype; 12007 jstr.grid.datatype = 'xmlstring'; 12008 jstr.grid.datastr = xml; 12009 $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype}); 12010 } else { 12011 $($t).jqGrid( jstr1 ); 12012 } 12013 jstr = null;jstr1=null; 12014 } else { 12015 alert("xml2json or parse are not present"); 12016 } 12017 }; 12018 var jsonConvert = function (jsonstr,o){ 12019 if (jsonstr && typeof jsonstr === 'string') { 12020 var _jsonparse = false;
12021 if($.jgrid.useJSON) { 12022 $.jgrid.useJSON = false; 12023 _jsonparse = true; 12024 } 12025 var json = $.jgrid.parse(jsonstr); 12026 if(_jsonparse) { $.jgrid.useJSON = true; } 12027 var gprm = json[o.jsonGrid.config]; 12028 var jdata = json[o.jsonGrid.data]; 12029 if(jdata) { 12030 var svdatatype = gprm.datatype; 12031 gprm.datatype = 'jsonstring'; 12032 gprm.datastr = jdata; 12033 $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype}); 12034 } else { 12035 $($t).jqGrid( gprm ); 12036 } 12037 } 12038 }; 12039 switch (o.imptype){ 12040 case 'xml': 12041 $.ajax($.extend({ 12042 url:o.impurl, 12043 type:o.mtype, 12044 data: o.impData, 12045 dataType:"xml", 12046 complete: function(xml,stat) { 12047 if(stat === 'success') { 12048 xmlConvert(xml.responseXML,o); 12049 $($t).triggerHandler("jqGridImportComplete", [xml, o]); 12050 if($.isFunction(o.importComplete)) { 12051 o.importComplete(xml); 12052 } 12053 } 12054 xml=null; 12055 } 12056 }, o.ajaxOptions)); 12057 break; 12058 case 'xmlstring' : 12059 // we need to make just the conversion and use the same code as xml 12060 if(o.impstring && typeof o.impstring === 'string') { 12061 var xmld = $.parseXML(o.impstring); 12062 if(xmld) { 12063 xmlConvert(xmld,o); 12064 $($t).triggerHandler("jqGridImportComplete", [xmld, o]); 12065 if($.isFunction(o.importComplete)) { 12066 o.importComplete(xmld); 12067 } 12068 o.impstring = null; 12069 } 12070 xmld = null; 12071 } 12072 break; 12073 case 'json': 12074 $.ajax($.extend({ 12075 url:o.impurl, 12076 type:o.mtype, 12077 data: o.impData, 12078 dataType:"json", 12079 complete: function(json) { 12080 try { 12081 jsonConvert(json.responseText,o ); 12082 $($t).triggerHandler("jqGridImportComplete", [json, o]); 12083 if($.isFunction(o.importComplete)) { 12084 o.importComplete(json); 12085 } 12086 } catch (ee){} 12087 json=null; 12088 } 12089 }, o.ajaxOptions )); 12090 break; 12091 case 'jsonstring' : 12092 if(o.impstring && typeof o.impstring === 'string') { 12093 jsonConvert(o.impstring,o ); 12094 $($t).triggerHandler("jqGridImportComplete", [o.impstring, o]); 12095 if($.isFunction(o.importComplete)) { 12096 o.importComplete(o.impstring); 12097 } 12098 o.impstring = null; 12099 } 12100 break; 12101 } 12102 }); 12103 }, 12104 jqGridExport : function(o) { 12105 o = $.extend({ 12106 exptype : "xmlstring", 12107 root: "grid", 12108 ident: "\t" 12109 }, o || {}); 12110 var ret = null; 12111 this.each(function () { 12112 if(!this.grid) { return;} 12113 var key, gprm = $.extend(true, {},$(this).jqGrid("getGridParam")); 12114 // we need to check for: 12115 // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames 12116 if(gprm.rownumbers) { 12117 gprm.colNames.splice(0,1); 12118 gprm.colModel.splice(0,1); 12119 } 12120 if(gprm.multiselect) { 12121 gprm.colNames.splice(0,1); 12122 gprm.colModel.splice(0,1); 12123 } 12124 if(gprm.subGrid) { 12125 gprm.colNames.splice(0,1); 12126 gprm.colModel.splice(0,1); 12127 } 12128 gprm.knv = null; 12129 if(gprm.treeGrid) { 12130 for (key in gprm.treeReader) { 12131 if(gprm.treeReader.hasOwnProperty(key)) { 12132 gprm.colNames.splice(gprm.colNames.length-1); 12133 gprm.colModel.splice(gprm.colModel.length-1); 12134 } 12135 } 12136 } 12137 switch (o.exptype) { 12138 case 'xmlstring' : 12139 ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">"; 12140 break; 12141 case 'jsonstring' : 12142 ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}"; 12143 if(gprm.postData.filters !== undefined) { 12144 ret=ret.replace(/filters":"/,'filters":'); 12145 ret=ret.replace(/}]}"/,'}]}'); 12146 } 12147 break; 12148 } 12149 }); 12150 return ret; 12151 }, 12152 excelExport : function(o) { 12153 o = $.extend({ 12154 exptype : "remote", 12155 url : null, 12156 oper: "oper", 12157 tag: "excel", 12158 exportOptions : {} 12159 }, o || {}); 12160 return this.each(function(){ 12161 if(!this.grid) { return;} 12162 var url; 12163 if(o.exptype === "remote") { 12164 var pdata = $.extend({},this.p.postData); 12165 pdata[o.oper] = o.tag; 12166 var params = jQuery.param(pdata); 12167 if(o.url.indexOf("?") !== -1) { url = o.url+"&"+params; } 12168 else { url = o.url+"?"+params; } 12169 window.location = url; 12170 } 12171 }); 12172 } 12173 }); 12174})(jQuery); 12175/*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */ 12176/*global jQuery */ 12177(function($){ 12178/* 12179** 12180 * jqGrid addons using jQuery UI 12181 * Author: Mark Williams 12182 * Dual licensed under the MIT and GPL licenses: 12183 * http://www.opensource.org/licenses/mit-license.php 12184 * http://www.gnu.org/licenses/gpl-2.0.html 12185 * depends on jQuery UI 12186**/ 12187"use strict";
12188if ($.jgrid.msie && $.jgrid.msiever()===8) { 12189 $.expr[":"].hidden = function(elem) { 12190 return elem.offsetWidth === 0 || elem.offsetHeight === 0 || 12191 elem.style.display === "none"; 12192 }; 12193} 12194// requiere load multiselect before grid 12195$.jgrid._multiselect = false; 12196if($.ui) { 12197 if ($.ui.multiselect ) { 12198 if($.ui.multiselect.prototype._setSelected) { 12199 var setSelected = $.ui.multiselect.prototype._setSelected; 12200 $.ui.multiselect.prototype._setSelected = function(item,selected) { 12201 var ret = setSelected.call(this,item,selected); 12202 if (selected && this.selectedList) { 12203 var elt = this.element; 12204 this.selectedList.find('li').each(function() { 12205 if ($(this).data('optionLink')) { 12206 $(this).data('optionLink').remove().appendTo(elt); 12207 } 12208 }); 12209 } 12210 return ret; 12211 }; 12212 } 12213 if($.ui.multiselect.prototype.destroy) { 12214 $.ui.multiselect.prototype.destroy = function() { 12215 this.element.show(); 12216 this.container.remove(); 12217 if ($.Widget === undefined) { 12218 $.widget.prototype.destroy.apply(this, arguments); 12219 } else { 12220 $.Widget.prototype.destroy.apply(this, arguments); 12221 } 12222 }; 12223 } 12224 $.jgrid._multiselect = true; 12225 } 12226} 12227 12228$.jgrid.extend({ 12229 sortableColumns : function (tblrow) 12230 { 12231 return this.each(function (){ 12232 var ts = this, tid= $.jgrid.jqID( ts.p.id ); 12233 function start() {ts.p.disableClick = true;} 12234 var sortable_opts = { 12235 "tolerance" : "pointer", 12236 "axis" : "x", 12237 "scrollSensitivity": "1", 12238 "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)', 12239 "placeholder": { 12240 element: function(item) { 12241 var el = $(document.createElement(item[0].nodeName)) 12242 .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight") 12243 .removeClass("ui-sortable-helper")[0]; 12244 return el; 12245 }, 12246 update: function(self, p) {
12247 p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10)); 12248 p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10)); 12249 } 12250 }, 12251 "update": function(event, ui) { 12252 var p = $(ui.item).parent(), 12253 th = $(">th", p), 12254 colModel = ts.p.colModel, 12255 cmMap = {}, tid= ts.p.id+"_"; 12256 $.each(colModel, function(i) { cmMap[this.name]=i; }); 12257 var permutation = []; 12258 th.each(function() { 12259 var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,""); 12260 if (cmMap.hasOwnProperty(id)) { 12261 permutation.push(cmMap[id]); 12262 } 12263 }); 12264 12265 $(ts).jqGrid("remapColumns",permutation, true, true); 12266 if ($.isFunction(ts.p.sortable.update)) { 12267 ts.p.sortable.update(permutation); 12268 } 12269 setTimeout(function(){ts.p.disableClick=false;}, 50); 12270 } 12271 }; 12272 if (ts.p.sortable.options) { 12273 $.extend(sortable_opts, ts.p.sortable.options); 12274 } else if ($.isFunction(ts.p.sortable)) { 12275 ts.p.sortable = { "update" : ts.p.sortable }; 12276 } 12277 if (sortable_opts.start) { 12278 var s = sortable_opts.start; 12279 sortable_opts.start = function(e,ui) { 12280 start(); 12281 s.call(this,e,ui); 12282 }; 12283 } else { 12284 sortable_opts.start = start; 12285 } 12286 if (ts.p.sortable.exclude) { 12287 sortable_opts.items += ":not("+ts.p.sortable.exclude+")"; 12288 } 12289 tblrow.sortable(sortable_opts).data("sortable").floating = true; 12290 }); 12291 }, 12292 columnChooser : function(opts) { 12293 var self = this; 12294 if($("#colchooser_"+$.jgrid.jqID(self[0].p.id)).length ) { return; } 12295 var selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>'); 12296 var select = $('select', selector); 12297 12298 function insert(perm,i,v) { 12299 if(i>=0){ 12300 var a = perm.slice(); 12301 var b = a.splice(i,Math.max(perm.length-i,i)); 12302 if(i>perm.length) { i = perm.length; } 12303 a[i] = v; 12304 return a.concat(b); 12305 } 12306 } 12307 opts = $.extend({ 12308 "width" : 420, 12309 "height" : 240, 12310 "classname" : null, 12311 "done" : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } }, 12312 /* msel is either the name of a ui widget class that 12313 extends a multiselect, or a function that supports 12314 creating a multiselect object (with no argument, 12315 or when passed an object), and destroying it (when 12316 passed the string "destroy"). */ 12317 "msel" : "multiselect", 12318 /* "msel_opts" : {}, */ 12319 12320 /* dlog is either the name of a ui widget class that 12321 behaves in a dialog-like way, or a function, that 12322 supports creating a dialog (when passed dlog_opts) 12323 or destroying a dialog (when passed the string 12324 "destroy") 12325 */ 12326 "dlog" : "dialog", 12327 "dialog_opts" : { 12328 "minWidth": 470 12329 }, 12330 /* dlog_opts is either an option object to be passed 12331 to "dlog", or (more likely) a function that creates 12332 the options object. 12333 The default produces a suitable options object for 12334 ui.dialog */ 12335 "dlog_opts" : function(opts) { 12336 var buttons = {}; 12337 buttons[opts.bSubmit] = function() { 12338 opts.apply_perm(); 12339 opts.cleanup(false); 12340 }; 12341 buttons[opts.bCancel] = function() { 12342 opts.cleanup(true); 12343 }; 12344 return $.extend(true, { 12345 "buttons": buttons, 12346 "close": function() { 12347 opts.cleanup(true); 12348 }, 12349 "modal" : opts.modal || false, 12350 "resizable": opts.resizable || true, 12351 "width": opts.width+20 12352 }, opts.dialog_opts || {}); 12353 }, 12354 /* Function to get the permutation array, and pass it to the 12355 "done" function */ 12356 "apply_perm" : function() { 12357 $('option',select).each(function() { 12358 if (this.selected) { 12359 self.jqGrid("showCol", colModel[this.value].name); 12360 } else { 12361 self.jqGrid("hideCol", colModel[this.value].name); 12362 } 12363 }); 12364 12365 var perm = []; 12366 //fixedCols.slice(0); 12367 $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); }); 12368 $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; }); 12369 $.each(colMap, function() { 12370 var ti = parseInt(this,10); 12371 perm = insert(perm,ti,ti); 12372 }); 12373 if (opts.done) { 12374 opts.done.call(self, perm); 12375 } 12376 }, 12377 /* Function to cleanup the dialog, and select. Also calls the 12378 done function with no permutation (to indicate that the 12379 columnChooser was aborted */ 12380 "cleanup" : function(calldone) { 12381 call(opts.dlog, selector, 'destroy'); 12382 call(opts.msel, select, 'destroy'); 12383 selector.remove(); 12384 if (calldone && opts.done) { 12385 opts.done.call(self); 12386 } 12387 }, 12388 "msel_opts" : {} 12389 }, $.jgrid.col, opts || {}); 12390 if($.ui) { 12391 if ($.ui.multiselect ) { 12392 if(opts.msel === "multiselect") { 12393 if(!$.jgrid._multiselect) { 12394 // should be in language file 12395 alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!"); 12396 return; 12397 } 12398 opts.msel_opts = $.extend($.ui.multiselect.defaults,opts.msel_opts); 12399 } 12400 } 12401 } 12402 if (opts.caption) { 12403 selector.attr("title", opts.caption); 12404 } 12405 if (opts.classname) { 12406 selector.addClass(opts.classname); 12407 select.addClass(opts.classname); 12408 } 12409 if (opts.width) { 12410 $(">div",selector).css({"width": opts.width,"margin":"0 auto"}); 12411 select.css("width", opts.width); 12412 } 12413 if (opts.height) { 12414 $(">div",selector).css("height", opts.height); 12415 select.css("height", opts.height - 10); 12416 } 12417 var colModel = self.jqGrid("getGridParam", "colModel"); 12418 var colNames = self.jqGrid("getGridParam", "colNames"); 12419 var colMap = {}, fixedCols = []; 12420 12421 select.empty(); 12422 $.each(colModel, function(i) { 12423 colMap[this.name] = i; 12424 if (this.hidedlg) { 12425 if (!this.hidden) { 12426 fixedCols.push(i); 12427 } 12428 return; 12429 } 12430 12431 select.append("<option value='"+i+"' "+ 12432 (this.hidden?"":"selected='selected'")+">
vendor: 4,900 bytes, lines 12432-12572
12432"+$.jgrid.stripHtml(colNames[i])+"</option>"); 12433 }); 12434 function call(fn, obj) { 12435 if (!fn) { return; } 12436 if (typeof fn === 'string') { 12437 if ($.fn[fn]) { 12438 $.fn[fn].apply(obj, $.makeArray(arguments).slice(2)); 12439 } 12440 } else if ($.isFunction(fn)) { 12441 fn.apply(obj, $.makeArray(arguments).slice(2)); 12442 } 12443 } 12444 12445 var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts; 12446 call(opts.dlog, selector, dopts); 12447 var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts; 12448 call(opts.msel, select, mopts); 12449 }, 12450 sortableRows : function (opts) { 12451 // Can accept all sortable options and events 12452 return this.each(function(){ 12453 var $t = this; 12454 if(!$t.grid) { return; } 12455 // Currently we disable a treeGrid sortable 12456 if($t.p.treeGrid) { return; } 12457 if($.fn.sortable) { 12458 opts = $.extend({ 12459 "cursor":"move", 12460 "axis" : "y", 12461 "items": ".jqgrow" 12462 }, 12463 opts || {}); 12464 if(opts.start && $.isFunction(opts.start)) { 12465 opts._start_ = opts.start; 12466 delete opts.start; 12467 } else {opts._start_=false;} 12468 if(opts.update && $.isFunction(opts.update)) { 12469 opts._update_ = opts.update; 12470 delete opts.update; 12471 } else {opts._update_ = false;} 12472 opts.start = function(ev,ui) { 12473 $(ui.item).css("border-width","0"); 12474 $("td",ui.item).each(function(i){ 12475 this.style.width = $t.grid.cols[i].style.width; 12476 }); 12477 if($t.p.subGrid) { 12478 var subgid = $(ui.item).attr("id"); 12479 try { 12480 $($t).jqGrid('collapseSubGridRow',subgid); 12481 } catch (e) {} 12482 } 12483 if(opts._start_) { 12484 opts._start_.apply(this,[ev,ui]); 12485 } 12486 }; 12487 opts.update = function (ev,ui) { 12488 $(ui.item).css("border-width",""); 12489 if($t.p.rownumbers === true) { 12490 $("td.jqgrid-rownum",$t.rows).each(function( i ){ 12491 $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) ); 12492 }); 12493 } 12494 if(opts._update_) { 12495 opts._update_.apply(this,[ev,ui]); 12496 } 12497 }; 12498 $("tbody:first",$t).sortable(opts); 12499 $("tbody:first",$t).disableSelection(); 12500 } 12501 }); 12502 }, 12503 gridDnD : function(opts) { 12504 return this.each(function(){ 12505 var $t = this, i, cn; 12506 if(!$t.grid) { return; } 12507 // Currently we disable a treeGrid drag and drop 12508 if($t.p.treeGrid) { return; } 12509 if(!$.fn.draggable || !$.fn.droppable) { return; } 12510 function updateDnD () 12511 { 12512 var datadnd = $.data($t,"dnd"); 12513 $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag); 12514 } 12515 var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>"; 12516 if($("#jqgrid_dnd")[0] === undefined) { 12517 $('body').append(appender); 12518 } 12519 12520 if(typeof opts === 'string' && opts === 'updateDnD' && $t.p.jqgdnd===true) { 12521 updateDnD(); 12522 return; 12523 } 12524 opts = $.extend({ 12525 "drag" : function (opts) { 12526 return $.extend({ 12527 start : function (ev, ui) { 12528 var i, subgid; 12529 // if we are in subgrid mode try to collapse the node 12530 if($t.p.subGrid) { 12531 subgid = $(ui.helper).attr("id"); 12532 try { 12533 $($t).jqGrid('collapseSubGridRow',subgid); 12534 } catch (e) {} 12535 } 12536 // hack 12537 // drag and drop does not insert tr in table, when the table has no rows 12538 // we try to insert new empty row on the target(s) 12539 for (i=0;i<$.data($t,"dnd").connectWith.length;i++){ 12540 if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') === 0 ){ 12541 $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{}); 12542 } 12543 } 12544 ui.helper.addClass("ui-state-highlight"); 12545 $("td",ui.helper).each(function(i) { 12546 this.style.width = $t.grid.headers[i].width+"px"; 12547 }); 12548 if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); } 12549 }, 12550 stop :function(ev,ui) { 12551 var i, ids; 12552 if(ui.helper.dropped && !opts.dragcopy) { 12553 ids = $(ui.helper).attr("id"); 12554 if(ids === undefined) { ids = $(this).attr("id"); } 12555 $($t).jqGrid('delRowData',ids ); 12556 } 12557 // if we have a empty row inserted from start event try to delete it 12558 for (i=0;i<$.data($t,"dnd").connectWith.length;i++){ 12559 $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row'); 12560 } 12561 if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); } 12562 } 12563 },opts.drag_opts || {}); 12564 }, 12565 "drop" : function (opts) { 12566 return $.extend({ 12567 accept: function(d) { 12568 if (!$(d).hasClass('jqgrow')) { return d;} 12569 var tid = $(d).closest("table.ui-jqgrid-btable"); 12570 if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) { 12571 var cn = $.data(tid[0],"dnd").connectWith; 12572 return $.inArray('#'+$.jgrid.jqID(this.id),cn) !== -1 ? true : false;
12573 } 12574 return false; 12575 }, 12576 drop: function(ev, ui) { 12577 if (!$(ui.draggable).hasClass('jqgrow')) { return; } 12578 var accept = $(ui.draggable).attr("id"); 12579 var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept); 12580 if(!opts.dropbyname) { 12581 var j =0, tmpdata = {}, nm, key; 12582 var dropmodel = $("#"+$.jgrid.jqID(this.id)).jqGrid('getGridParam','colModel'); 12583 try { 12584 for (key in getdata) { 12585 if (getdata.hasOwnProperty(key)) { 12586 nm = dropmodel[j].name; 12587 if( !(nm === 'cb' || nm === 'rn' || nm === 'subgrid' )) { 12588 if(getdata.hasOwnProperty(key) && dropmodel[j]) { 12589 tmpdata[nm] = getdata[key]; 12590 } 12591 } 12592 j++; 12593 } 12594 } 12595 getdata = tmpdata; 12596 } catch (e) {} 12597 } 12598 ui.helper.dropped = true; 12599 if(opts.beforedrop && $.isFunction(opts.beforedrop) ) { 12600 //parameters to this callback - event, element, data to be inserted, sender, reciever 12601 // should return object which will be inserted into the reciever 12602 var datatoinsert = opts.beforedrop.call(this,ev,ui,getdata,$('#'+$.jgrid.jqID($t.p.id)),$(this)); 12603 if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert === "object") { getdata = datatoinsert; } 12604 } 12605 if(ui.helper.dropped) { 12606 var grid; 12607 if(opts.autoid) { 12608 if($.isFunction(opts.autoid)) { 12609 grid = opts.autoid.call(this,getdata); 12610 } else { 12611 grid = Math.ceil(Math.random()*1000); 12612 grid = opts.autoidprefix+grid; 12613 } 12614 } 12615 // NULL is interpreted as undefined while null as object 12616 $("#"+$.jgrid.jqID(this.id)).jqGrid('addRowData',grid,getdata,opts.droppos); 12617 } 12618 if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); } 12619 }}, opts.drop_opts || {}); 12620 }, 12621 "onstart" : null, 12622 "onstop" : null, 12623 "beforedrop": null, 12624 "ondrop" : null, 12625 "drop_opts" : { 12626 "activeClass": "ui-state-active", 12627 "hoverClass": "ui-state-hover" 12628 }, 12629 "drag_opts" : {
12630 "revert": "invalid", 12631 "helper": "clone", 12632 "cursor": "move", 12633 "appendTo" : "#jqgrid_dnd", 12634 "zIndex": 5000 12635 }, 12636 "dragcopy": false, 12637 "dropbyname" : false, 12638 "droppos" : "first", 12639 "autoid" : true, 12640 "autoidprefix" : "dnd_" 12641 }, opts || {}); 12642 12643 if(!opts.connectWith) { return; } 12644 opts.connectWith = opts.connectWith.split(","); 12645 opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);}); 12646 $.data($t,"dnd",opts); 12647 12648 if($t.p.reccount !== 0 && !$t.p.jqgdnd) { 12649 updateDnD(); 12650 } 12651 $t.p.jqgdnd = true; 12652 for (i=0;i<opts.connectWith.length;i++){ 12653 cn =opts.connectWith[i]; 12654 $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop); 12655 } 12656 }); 12657 }, 12658 gridResize : function(opts) { 12659 return this.each(function(){ 12660 var $t = this, gID = $.jgrid.jqID($t.p.id); 12661 if(!$t.grid || !$.fn.resizable) { return; } 12662 opts = $.extend({}, opts || {}); 12663 if(opts.alsoResize ) { 12664 opts._alsoResize_ = opts.alsoResize; 12665 delete opts.alsoResize; 12666 } else { 12667 opts._alsoResize_ = false; 12668 } 12669 if(opts.stop && $.isFunction(opts.stop)) { 12670 opts._stop_ = opts.stop; 12671 delete opts.stop; 12672 } else { 12673 opts._stop_ = false; 12674 } 12675 opts.stop = function (ev, ui) { 12676 $($t).jqGrid('setGridParam',{height:$("#gview_"+gID+" .ui-jqgrid-bdiv").height()}); 12677 $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit); 12678 if(opts._stop_) { opts._stop_.call($t,ev,ui); } 12679 }; 12680 if(opts._alsoResize_) { 12681 var optstest = "{\'#gview_"+gID+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}"; 12682 opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this 12683 } else { 12684 opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+gID); 12685 } 12686 delete opts._alsoResize_; 12687 $("#gbox_"+gID).resizable(opts); 12688 }); 12689 } 12690}); 12691})(jQuery); 12692/* 12693 Transform a table to a jqGrid. 12694 Peter Romianowski <[email protected]> 12695 If the first column of the table contains checkboxes or 12696 radiobuttons then the jqGrid is made selectable. 12697*/ 12698// Addition - selector can be a class or id 12699function tableToGrid(selector, options) { 12700jQuery(selector).each(function() { 12701 if(this.grid) {return;} //Adedd from Tony Tomov 12702 // This is a small "hack" to make the width of the jqGrid 100% 12703 jQuery(this).width("99%"); 12704 var w = jQuery(this).width(); 12705 12706 // Text whether we have single or multi select 12707 var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this)); 12708 var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this)); 12709 var selectMultiple = inputCheckbox.length > 0; 12710 var selectSingle = !selectMultiple && inputRadio.length > 0; 12711 var selectable = selectMultiple || selectSingle; 12712 //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name"); 12713 12714 // Build up the columnModel and the data 12715 var colModel = []; 12716 var colNames = []; 12717 jQuery('th', jQuery(this)).each(function() { 12718 if (colModel.length === 0 && selectable) { 12719 colModel.push({ 12720 name: '__selection__', 12721 index: '__selection__', 12722 width: 0, 12723 hidden: true 12724 }); 12725 colNames.push('__selection__'); 12726 } else { 12727 colModel.push({ 12728 name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'), 12729 index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'), 12730 width: jQuery(this).width() || 150 12731 }); 12732 colNames.push(jQuery(this).html()); 12733 } 12734 }); 12735 var data = []; 12736 var rowIds = []; 12737 var rowChecked = []; 12738 jQuery('tbody > tr', jQuery(this)).each(function() { 12739 var row = {}; 12740 var rowPos = 0; 12741 jQuery('td', jQuery(this)).each(function() { 12742 if (rowPos === 0 && selectable) { 12743 var input = jQuery('input', jQuery(this)); 12744 var rowId = input.attr("value"); 12745 rowIds.push(rowId || data.length); 12746 if (input.is(":checked")) { 12747 rowChecked.push(rowId); 12748 } 12749 row[colModel[rowPos].name] = input.attr("value"); 12750 } else { 12751 row[colModel[rowPos].name] = jQuery(this).html(); 12752 } 12753 rowPos++; 12754 }); 12755 if(rowPos >0) { data.push(row); } 12756 }); 12757 12758 // Clear the original HTML table 12759 jQuery(this).empty(); 12760 12761 // Mark it as jqGrid 12762 jQuery(this).addClass("scroll"); 12763 12764 jQuery(this).jqGrid(jQuery.extend({ 12765 datatype: "local", 12766 width: w, 12767 colNames: colNames, 12768 colModel: colModel, 12769 multiselect: selectMultiple 12770 //inputName: inputName, 12771 //inputValueCol: imputName != null ? "__selection__" : null 12772 }, options || {})); 12773 12774 // Add data 12775 var a; 12776 for (a = 0; a < data.length; a++) { 12777 var id = null; 12778 if (rowIds.length > 0) { 12779 id = rowIds[a]; 12780 if (id && id.replace) { 12781 // We have to do this since the value of a checkbox 12782 // or radio button can be anything 12783 id = encodeURIComponent(id).replace(/[.\-%]/g, "_"); 12784 } 12785 } 12786 if (id === null) { 12787 id = a + 1; 12788 } 12789 jQuery(this).jqGrid("addRowData",id, data[a]); 12790 } 12791 12792 // Set the selection 12793 for (a = 0; a < rowChecked.length; a++) { 12794 jQuery(this).jqGrid("setSelection",rowChecked[a]); 12795 } 12796}); 12797}; 12798/*jshint eqeqeq:false */ 12799/*global jQuery */ 12800(function($){ 12801/** 12802 * jqGrid pivot functions 12803 * Tony Tomov [email protected] 12804 * http://trirand.com/blog/ 12805 * Dual licensed under the MIT and GPL licenses: 12806 * http://www.opensource.org/licenses/mit-license.php 12807 * http://www.gnu.org/licenses/gpl-2.0.html 12808*/ 12809"use strict";
12810// To optimize the search we need custom array filter 12811// This code is taken from 12812// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter 12813 12814function _pivotfilter (fn, context) { 12815 var i, 12816 value, 12817 result = [], 12818 length; 12819 12820 if (!this || typeof fn !== 'function' || (fn instanceof RegExp)) { 12821 throw new TypeError(); 12822 } 12823 12824 length = this.length; 12825 12826 for (i = 0; i < length; i++) { 12827 if (this.hasOwnProperty(i)) { 12828 value = this[i]; 12829 if (fn.call(context, value, i, this)) { 12830 result.push(value); 12831 // We need break in order to cancel loop 12832 // in case the row is found 12833 break; 12834 } 12835 } 12836 } 12837 return result; 12838} 12839$.assocArraySize = function(obj) { 12840 // http://stackoverflow.com/a/6700/11236 12841 var size = 0, key; 12842 for (key in obj) { 12843 if (obj.hasOwnProperty(key)) { 12844 size++; 12845 } 12846 } 12847 return size; 12848}; 12849 12850$.jgrid.extend({ 12851 pivotSetup : function( data, options ){ 12852 // data should come in json format 12853 // The function return the new colModel and the transformed data 12854 // again with group setup options which then will be passed to the grid 12855 var columns =[], 12856 pivotrows =[], 12857 summaries = [], 12858 member=[], 12859 groupOptions = { 12860 grouping : true, 12861 groupingView : { 12862 groupField : [], 12863 groupSummary: [], 12864 groupSummaryPos:[] 12865 } 12866 }, 12867 headers = [], 12868 o = $.extend ( { 12869 rowTotals : false, 12870 rowTotalsText : 'Total', 12871 // summary columns 12872 colTotals : false, 12873 groupSummary : true, 12874 groupSummaryPos : 'header', 12875 frozenStaticCols : false 12876 }, options || {}); 12877 this.each(function(){ 12878 12879 var 12880 row, 12881 rowindex, 12882 i, 12883 12884 rowlen = data.length, 12885 xlen, ylen, aggrlen, 12886 tmp, 12887 newObj, 12888 r=0; 12889 // utility funcs 12890 /* 12891 * Filter the data to a given criteria. Return the firt occurance 12892 */ 12893 function find(ar, fun, extra) { 12894 var res; 12895 res = _pivotfilter.call(ar, fun, extra); 12896 return res.length > 0 ? res[0] : null; 12897 } 12898 /* 12899 * Check if the grouped row column exist (See find) 12900 * If the row is not find in pivot rows retun null, 12901 * otherviese the column 12902 */ 12903 function findGroup(item, index) { 12904 var j = 0, ret = true, i; 12905 for(i in item) { 12906 if(item[i] != this[j]) { 12907 ret = false; 12908 break; 12909 } 12910 j++; 12911 if(j>=this.length) { 12912 break; 12913 } 12914 } 12915 if(ret) { 12916 rowindex = index; 12917 } 12918 return ret; 12919 } 12920 /* 12921 * Perform calculations of the pivot values. 12922 */ 12923 function calculation(oper, v, field, rc) { 12924 var ret; 12925 switch (oper) { 12926 case "sum" : 12927 ret = parseFloat(v||0) + parseFloat((rc[field]||0)); 12928 break; 12929 case "count" : 12930 if(v==="" || v == null) { 12931 v=0; 12932 } 12933 if(rc.hasOwnProperty(field)) { 12934 ret = v+1; 12935 } else { 12936 ret = 0; 12937 } 12938 break; 12939 case "min" : 12940 if(v==="" || v == null) { 12941 ret = parseFloat(rc[field]||0); 12942 } else { 12943 ret =Math.min(parseFloat(v),parseFloat(rc[field]||0)); 12944 } 12945 break; 12946 case "max" : 12947 if(v==="" || v == null) { 12948 ret = parseFloat(rc[field]||0); 12949 } else { 12950 ret = Math.max(parseFloat(v),parseFloat(rc[field]||0)); 12951 } 12952 break; 12953 } 12954 return ret; 12955 } 12956 /* 12957 * The function agragates the values of the pivot grid. 12958 * Return the current row with pivot summary values 12959 */ 12960 function agregateFunc ( row, aggr, value, curr) { 12961 // default is sum 12962 var arrln = aggr.length, i, label, j, jv; 12963 if($.isArray(value)) { 12964 jv = value.length; 12965 } else { 12966 jv = 1; 12967 } 12968 member = []; 12969 member.root = 0; 12970 for(j=0;j<jv;j++) { 12971 var tmpmember = [], vl; 12972 for(i=0; i < arrln; i++) { 12973 if(value == null) { 12974 label = $.trim(aggr[i].member)+"_"+aggr[i].aggregator; 12975 vl = label; 12976 } else { 12977 vl = value[j].replace(/\s+/g, ''); 12978 try { 12979 label = (arrln === 1 ? vl : vl+"_"+aggr[i].aggregator+"_"+i); 12980 } catch(e) {} 12981 } 12982 label = !isNaN(parseInt(label,10)) ? label + " " : label; 12983 curr[label] = tmpmember[label] = calculation( aggr[i].aggregator, curr[label], aggr[i].member, row); 12984 } 12985 vl = !isNaN(parseInt(vl,10)) ? vl + " " : vl; 12986 member[vl] = tmpmember; 12987 } 12988 return curr; 12989 } 12990 // Making the row totals without to add in yDimension 12991 if(o.rowTotals && o.yDimension.length > 0) { 12992 var dn = o.yDimension[0].dataName; 12993 o.yDimension.splice(0,0,{dataName:dn}); 12994 o.yDimension[0].converter = function(){ return '_r_Totals'; }; 12995 } 12996 // build initial columns (colModel) from xDimension 12997 xlen = $.isArray(o.xDimension) ? o.xDimension.length : 0; 12998 ylen = o.yDimension.length; 12999 aggrlen = $.isArray(o.aggregates) ? o.aggregates.length : 0; 13000 if(xlen === 0 || aggrlen === 0) { 13001 throw("xDimension or aggregates optiona are not set!"); 13002 } 13003 var colc; 13004 for(i = 0; i< xlen; i++) { 13005 colc = {name:o.xDimension[i].dataName, frozen: o.frozenStaticCols}; 13006 if(o.xDimension[i].isGroupField == null) { 13007 o.xDimension[i].isGroupField = true; 13008 } 13009 colc = $.extend(true, colc, o.xDimension[i]); 13010 columns.push( colc ); 13011 } 13012 var groupfields = xlen - 1, tree={}; 13013 //tree = { text: 'root', leaf: false, children: [] }; 13014 //loop over alll the source data 13015 while( r < rowlen ) { 13016 row = data[r]; 13017 var xValue = []; 13018 var yValue = []; 13019 tmp = {}; 13020 i = 0; 13021 // build the data from xDimension 13022 do { 13023 xValue[i] = $.trim(row[o.xDimension[i].dataName]); 13024 tmp[o.xDimension[i].dataName] = xValue[i]; 13025 i++; 13026 } while( i < xlen ); 13027 13028 var k = 0; 13029 rowindex = -1; 13030 // check to see if the row is in our new pivotrow set 13031 newObj = find(pivotrows, findGroup, xValue); 13032 if(!newObj) { 13033 // if the row is not in our set 13034 k = 0; 13035 // if yDimension is set 13036 if(ylen>=1) { 13037 // build the cols set in yDimension 13038 for(k=0;k<ylen;k++) { 13039 yValue[k] = $.trim(row[o.yDimension[k].dataName]); 13040 // Check to see if we have user defined conditions 13041 if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) { 13042 yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue); 13043 } 13044 } 13045 // make the colums based on aggregates definition 13046 // and return the members for late calculation 13047 tmp = agregateFunc( row, o.aggregates, yValue, tmp ); 13048 } else if( ylen === 0 ) { 13049 // if not set use direct the aggregates 13050 tmp = agregateFunc( row, o.aggregates, null, tmp ); 13051 } 13052 // add the result in pivot rows 13053 pivotrows.push( tmp ); 13054 } else { 13055 // the pivot exists 13056 if( rowindex >= 0) { 13057 k = 0; 13058 // make the recalculations 13059 if(ylen>=1) { 13060 for(k=0;k<ylen;k++) { 13061 yValue[k] = $.trim(row[o.yDimension[k].dataName]); 13062 if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) { 13063 yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue); 13064 } 13065 } 13066 newObj = agregateFunc( row, o.aggregates, yValue, newObj ); 13067 } else if( ylen === 0 ) { 13068 newObj = agregateFunc( row, o.aggregates, null, newObj ); 13069 } 13070 // update the row 13071 pivotrows[rowindex] = newObj; 13072 } 13073 } 13074 var kj=0, current = null,existing = null, kk; 13075 // Build a JSON tree from the member (see aggregateFunc) 13076 // to make later the columns 13077 // 13078 for (kk in member) { 13079 if(kj === 0) { 13080 if (!tree.children||tree.children === undefined){ 13081 tree = { text: kk, level : 0, children: [] }; 13082 } 13083 current = tree.children; 13084 } else { 13085 existing = null; 13086 for (i=0; i < current.length; i++) { 13087 if (current[i].text === kk) { 13088 //current[i].fields=member[kk]; 13089 existing = current[i]; 13090 break; 13091 } 13092 } 13093 if (existing) { 13094 current = existing.children; 13095 } else { 13096 current.push({ children: [], text: kk, level: kj, fields: member[kk] }); 13097 current = current[current.length - 1].children; 13098 } 13099 }
13100 kj++; 13101 } 13102 r++; 13103 } 13104 var lastval=[], initColLen = columns.length, swaplen = initColLen; 13105 if(ylen>0) { 13106 headers[ylen-1] = { useColSpanStyle: false, groupHeaders: []}; 13107 } 13108 /* 13109 * Recursive function which uses the tree to build the 13110 * columns from the pivot values and set the group Headers 13111 */ 13112 function list(items) { 13113 var l, j, key, k, col; 13114 for (key in items) { // iterate 13115 if (items.hasOwnProperty(key)) { 13116 // write amount of spaces according to level 13117 // and write name and newline 13118 if(typeof items[key] !== "object") { 13119 // If not a object build the header of the appropriate level 13120 if( key === 'level') { 13121 if(lastval[items.level] === undefined) { 13122 lastval[items.level] =''; 13123 if(items.level>0 && items.text !== '_r_Totals') { 13124 headers[items.level-1] = { 13125 useColSpanStyle: false, 13126 groupHeaders: [] 13127 }; 13128 } 13129 } 13130 if(lastval[items.level] !== items.text && items.children.length && items.text !== '_r_Totals') { 13131 if(items.level>0) { 13132 headers[items.level-1].groupHeaders.push({ 13133 titleText: items.text 13134 }); 13135 var collen = headers[items.level-1].groupHeaders.length, 13136 colpos = collen === 1 ? swaplen : initColLen+(collen-1)*aggrlen; 13137 headers[items.level-1].groupHeaders[collen-1].startColumnName = columns[colpos].name; 13138 headers[items.level-1].groupHeaders[collen-1].numberOfColumns = columns.length - colpos; 13139 initColLen = columns.length; 13140 } 13141 } 13142 lastval[items.level] = items.text; 13143 } 13144 // This is in case when the member contain more than one summary item 13145 if(items.level === ylen && key==='level' && ylen >0) { 13146 if( aggrlen > 1){ 13147 var ll=1; 13148 for( l in items.fields) { 13149 if(ll===1) { 13150 headers[ylen-1].groupHeaders.push({startColumnName: l, numberOfColumns: 1, titleText: items.text}); 13151 } 13152 ll++; 13153 } 13154 headers[ylen-1].groupHeaders[headers[ylen-1].groupHeaders.length-1].numberOfColumns = ll-1; 13155 } else { 13156 headers.splice(ylen-1,1); 13157 } 13158 } 13159 } 13160 // if object, call recursively 13161 if (items[key] != null && typeof items[key] === "object") { 13162 list(items[key]); 13163 } 13164 // Finally build the coulumns 13165 if( key === 'level') { 13166 if(items.level >0){ 13167 j=0; 13168 for(l in items.fields) { 13169 col = {}; 13170 for(k in o.aggregates[j]) { 13171 if(o.aggregates[j].hasOwnProperty(k)) { 13172 switch( k ) { 13173 case 'member': 13174 case 'label': 13175 case 'aggregator': 13176 break; 13177 default: 13178 col[k] = o.aggregates[j][k]; 13179 } 13180 } 13181 } 13182 if(aggrlen>1) { 13183 col.name = l; 13184 col.label = o.aggregates[j].label || l; 13185 } else { 13186 col.name = items.text; 13187 col.label = items.text==='_r_Totals' ? o.rowTotalsText : items.text; 13188 } 13189 columns.push (col); 13190 j++; 13191 } 13192 } 13193 } 13194 } 13195 } 13196 } 13197 13198 list(tree, 0); 13199 var nm; 13200 // loop again trougth the pivot rows in order to build grand total 13201 if(o.colTotals) { 13202 var plen = pivotrows.length; 13203 while(plen--) { 13204 for(i=xlen;i<columns.length;i++) { 13205 nm = columns[i].name; 13206 if(!summaries[nm]) { 13207 summaries[nm] = parseFloat(pivotrows[plen][nm] || 0); 13208 } else { 13209 summaries[nm] += parseFloat(pivotrows[plen][nm] || 0); 13210 } 13211 } 13212 } 13213 } 13214 // based on xDimension levels build grouping 13215 if( groupfields > 0) { 13216 for(i=0;i<groupfields;i++) { 13217 if(columns[i].isGroupField) { 13218 groupOptions.groupingView.groupField.push(columns[i].name); 13219 groupOptions.groupingView.groupSummary.push(o.groupSummary); 13220 groupOptions.groupingView.groupSummaryPos.push(o.groupSummaryPos); 13221 } 13222 } 13223 } else { 13224 // no grouping is needed 13225 groupOptions.grouping = false; 13226 } 13227 groupOptions.sortname = columns[groupfields].name; 13228 groupOptions.groupingView.hideFirstGroupCol = true; 13229 }); 13230 // return the final result. 13231 return { "colModel" : columns, "rows": pivotrows, "groupOptions" : groupOptions, "groupHeaders" : headers, summary : summaries }; 13232 },
13233 jqPivot : function( data, pivotOpt, gridOpt, ajaxOpt) { 13234 return this.each(function(){ 13235 var $t = this; 13236 13237 function pivot( data) { 13238 var pivotGrid = jQuery($t).jqGrid('pivotSetup',data, pivotOpt), 13239 footerrow = $.assocArraySize(pivotGrid.summary) > 0 ? true : false, 13240 query= $.jgrid.from(pivotGrid.rows), i; 13241 for(i=0; i< pivotGrid.groupOptions.groupingView.groupField.length; i++) { 13242 query.orderBy(pivotGrid.groupOptions.groupingView.groupField[i], "a", 'text', ''); 13243 } 13244 jQuery($t).jqGrid($.extend(true, { 13245 datastr: $.extend(query.select(),footerrow ? {userdata:pivotGrid.summary} : {}), 13246 datatype: "jsonstring", 13247 footerrow : footerrow, 13248 userDataOnFooter: footerrow, 13249 colModel: pivotGrid.colModel, 13250 viewrecords: true, 13251 sortname: pivotOpt.xDimension[0].dataName // ????? 13252 }, pivotGrid.groupOptions, gridOpt || {})); 13253 var gHead = pivotGrid.groupHeaders; 13254 if(gHead.length) { 13255 for( i = 0;i < gHead.length ; i++) { 13256 if(gHead[i] && gHead[i].groupHeaders.length) { 13257 jQuery($t).jqGrid('setGroupHeaders',gHead[i]); 13258 } 13259 } 13260 } 13261 if(pivotOpt.frozenStaticCols) { 13262 jQuery($t).jqGrid("setFrozenColumns"); 13263 } 13264 } 13265 13266 if(typeof data === "string") { 13267 $.ajax($.extend({ 13268 url : data, 13269 dataType: 'json', 13270 success : function(response) {
13271 pivot($.jgrid.getAccessor(response, ajaxOpt && ajaxOpt.reader ? ajaxOpt.reader: 'rows') ); 13272 } 13273 }, ajaxOpt || {}) ); 13274 } else { 13275 pivot( data ); 13276 } 13277 }); 13278 } 13279}); 13280})(jQuery); 13281
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.