PageRenderTime 70ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/JqGridMvc/JqGridMvc/Scripts/js/jquery.jqGrid.src.js

#
JavaScript | 11317 lines | 7874 code | 28 blank | 3415 comment | 311 complexity | 22eb8dd1f96cb897f38797c15444ff71 MD5 | raw file
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license jqGrid 4.2.0 - jQuery Grid
  5. * Copyright (c) 2008, Tony Tomov, tony@trirand.com
  6. * Dual licensed under the MIT and GPL licenses
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.gnu.org/licenses/gpl-2.0.html
  9. * Date: 2011-10-11
  10. */
  11. //jsHint options
  12. /*global document, window, jQuery, DOMParser, ActiveXObject $ */
  13. (function ($) {
  14. $.jgrid = $.jgrid || {};
  15. $.extend($.jgrid,{
  16. htmlDecode : function(value){
  17. if(value && (value==' ' || value==' ' || (value.length==1 && value.charCodeAt(0)==160))) { return "";}
  18. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  19. },
  20. htmlEncode : function (value){
  21. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  22. },
  23. format : function(format){ //jqgformat
  24. var args = $.makeArray(arguments).slice(1);
  25. if(format===undefined) { format = ""; }
  26. return format.replace(/\{(\d+)\}/g, function(m, i){
  27. return args[i];
  28. });
  29. },
  30. getCellIndex : function (cell) {
  31. var c = $(cell);
  32. if (c.is('tr')) { return -1; }
  33. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  34. if ($.browser.msie) { return $.inArray(c, c.parentNode.cells); }
  35. return c.cellIndex;
  36. },
  37. stripHtml : function(v) {
  38. v = v+"";
  39. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  40. if (v) {
  41. v = v.replace(regexp,"");
  42. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  43. } else {
  44. return v;
  45. }
  46. },
  47. stripPref : function (pref, id) {
  48. var obj = Object.prototype.toString.call(pref).slice(8, -1);
  49. if( obj == "String" || obj =="Number") {
  50. pref = String(pref);
  51. id = pref != "" ? String(id).replace(String(pref), "") : id;
  52. }
  53. return id;
  54. },
  55. stringToDoc : function (xmlString) {
  56. var xmlDoc;
  57. if(typeof xmlString !== 'string') { return xmlString; }
  58. try {
  59. var parser = new DOMParser();
  60. xmlDoc = parser.parseFromString(xmlString,"text/xml");
  61. }
  62. catch(e) {
  63. xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  64. xmlDoc.async=false;
  65. xmlDoc.loadXML(xmlString);
  66. }
  67. return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null;
  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) {
  79. var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0},k,hl,dM, regdate = /[\\\/:_;.,\t\T\s-]/;
  80. if(date && date !== null && date !== undefined){
  81. date = $.trim(date);
  82. date = date.split(regdate);
  83. format = format.split(regdate);
  84. var dfmt = $.jgrid.formatter.date.monthNames;
  85. var afmt = $.jgrid.formatter.date.AmPm;
  86. var h12to24 = function(ampm, h){
  87. if (ampm === 0){ if (h == 12) { h = 0;} }
  88. else { if (h != 12) { h += 12; } }
  89. return h;
  90. };
  91. for(k=0,hl=format.length;k<hl;k++){
  92. if(format[k] == 'M') {
  93. dM = $.inArray(date[k],dfmt);
  94. if(dM !== -1 && dM < 12){date[k] = dM+1;}
  95. }
  96. if(format[k] == 'F') {
  97. dM = $.inArray(date[k],dfmt);
  98. if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
  99. }
  100. if(format[k] == 'a') {
  101. dM = $.inArray(date[k],afmt);
  102. if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){
  103. date[k] = dM;
  104. tsp.h = h12to24(date[k], tsp.h);
  105. }
  106. }
  107. if(format[k] == 'A') {
  108. dM = $.inArray(date[k],afmt);
  109. if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){
  110. date[k] = dM-2;
  111. tsp.h = h12to24(date[k], tsp.h);
  112. }
  113. }
  114. if(date[k] !== undefined) {
  115. tsp[format[k].toLowerCase()] = parseInt(date[k],10);
  116. }
  117. }
  118. tsp.m = parseInt(tsp.m,10)-1;
  119. var ty = tsp.y;
  120. if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;}
  121. else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;}
  122. }
  123. return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s,0);
  124. },
  125. jqID : function(sid){
  126. return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&");
  127. },
  128. guid : 1,
  129. uidPref: 'jqg',
  130. randId : function( prefix ) {
  131. return (prefix? prefix: $.jgrid.uidPref) + ($.jgrid.guid++);
  132. },
  133. getAccessor : function(obj, expr) {
  134. var ret,p,prm = [], i;
  135. if( typeof expr === 'function') { return expr(obj); }
  136. ret = obj[expr];
  137. if(ret===undefined) {
  138. try {
  139. if ( typeof expr === 'string' ) {
  140. prm = expr.split('.');
  141. }
  142. i = prm.length;
  143. if( i ) {
  144. ret = obj;
  145. while (ret && i--) {
  146. p = prm.shift();
  147. ret = ret[p];
  148. }
  149. }
  150. } catch (e) {}
  151. }
  152. return ret;
  153. },
  154. ajaxOptions: {},
  155. from : function(source,initalQuery){
  156. // Original Author Hugo Bonacci
  157. // License MIT http://jlinq.codeplex.com/license
  158. var queryObject=function(d,q){
  159. if(typeof(d)=="string"){
  160. d=$.data(d);
  161. }
  162. var self=this,
  163. _data=d,
  164. _usecase=true,
  165. _trim=false,
  166. _query=q,
  167. _stripNum = /[\$,%]/g,
  168. _lastCommand=null,
  169. _lastField=null,
  170. _orDepth=0,
  171. _negate=false,
  172. _queuedOperator="",
  173. _sorting=[],
  174. _useProperties=true;
  175. if(typeof(d)=="object"&&d.push) {
  176. if(d.length>0){
  177. if(typeof(d[0])!="object"){
  178. _useProperties=false;
  179. }else{
  180. _useProperties=true;
  181. }
  182. }
  183. }else{
  184. throw "data provides is not an array";
  185. }
  186. this._hasData=function(){
  187. return _data===null?false:_data.length===0?false:true;
  188. };
  189. this._getStr=function(s){
  190. var phrase=[];
  191. if(_trim){
  192. phrase.push("jQuery.trim(");
  193. }
  194. phrase.push("String("+s+")");
  195. if(_trim){
  196. phrase.push(")");
  197. }
  198. if(!_usecase){
  199. phrase.push(".toLowerCase()");
  200. }
  201. return phrase.join("");
  202. };
  203. this._strComp=function(val){
  204. if(typeof(val)=="string"){
  205. return".toString()";
  206. }else{
  207. return"";
  208. }
  209. };
  210. this._group=function(f,u){
  211. return({field:f.toString(),unique:u,items:[]});
  212. };
  213. this._toStr=function(phrase){
  214. if(_trim){
  215. phrase=$.trim(phrase);
  216. }
  217. if(!_usecase){
  218. phrase=phrase.toLowerCase();
  219. }
  220. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  221. return phrase;
  222. };
  223. this._funcLoop=function(func){
  224. var results=[];
  225. $.each(_data,function(i,v){
  226. results.push(func(v));
  227. });
  228. return results;
  229. };
  230. this._append=function(s){
  231. var i;
  232. if(_query===null){
  233. _query="";
  234. } else {
  235. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  236. }
  237. for (i=0;i<_orDepth;i++){
  238. _query+="(";
  239. }
  240. if(_negate){
  241. _query+="!";
  242. }
  243. _query+="("+s+")";
  244. _negate=false;
  245. _queuedOperator="";
  246. _orDepth=0;
  247. };
  248. this._setCommand=function(f,c){
  249. _lastCommand=f;
  250. _lastField=c;
  251. };
  252. this._resetNegate=function(){
  253. _negate=false;
  254. };
  255. this._repeatCommand=function(f,v){
  256. if(_lastCommand===null){
  257. return self;
  258. }
  259. if(f!==null&&v!==null){
  260. return _lastCommand(f,v);
  261. }
  262. if(_lastField===null){
  263. return _lastCommand(f);
  264. }
  265. if(!_useProperties){
  266. return _lastCommand(f);
  267. }
  268. return _lastCommand(_lastField,f);
  269. };
  270. this._equals=function(a,b){
  271. return(self._compare(a,b,1)===0);
  272. };
  273. this._compare=function(a,b,d){
  274. if( d === undefined) { d = 1; }
  275. if(a===undefined) { a = null; }
  276. if(b===undefined) { b = null; }
  277. if(a===null && b===null){
  278. return 0;
  279. }
  280. if(a===null&&b!==null){
  281. return 1;
  282. }
  283. if(a!==null&&b===null){
  284. return -1;
  285. }
  286. if(!_usecase && typeof(a) !== "number" && typeof(b) !== "number" ) {
  287. a=String(a).toLowerCase();
  288. b=String(b).toLowerCase();
  289. }
  290. if(a<b){return -d;}
  291. if(a>b){return d;}
  292. return 0;
  293. };
  294. this._performSort=function(){
  295. if(_sorting.length===0){return;}
  296. _data=self._doSort(_data,0);
  297. };
  298. this._doSort=function(d,q){
  299. var by=_sorting[q].by,
  300. dir=_sorting[q].dir,
  301. type = _sorting[q].type,
  302. dfmt = _sorting[q].datefmt;
  303. if(q==_sorting.length-1){
  304. return self._getOrder(d, by, dir, type, dfmt);
  305. }
  306. q++;
  307. var values=self._getGroup(d,by,dir,type,dfmt);
  308. var results=[];
  309. for(var i=0;i<values.length;i++){
  310. var sorted=self._doSort(values[i].items,q);
  311. for(var j=0;j<sorted.length;j++){
  312. results.push(sorted[j]);
  313. }
  314. }
  315. return results;
  316. };
  317. this._getOrder=function(data,by,dir,type, dfmt){
  318. var sortData=[],_sortData=[], newDir = dir=="a" ? 1 : -1, i,ab,j,
  319. findSortKey;
  320. if(type === undefined ) { type = "text"; }
  321. if (type == 'float' || type== 'number' || type== 'currency' || type== 'numeric') {
  322. findSortKey = function($cell, a) {
  323. var key = parseFloat( String($cell).replace(_stripNum, ''));
  324. return isNaN(key) ? 0.00 : key;
  325. };
  326. } else if (type=='int' || type=='integer') {
  327. findSortKey = function($cell, a) {
  328. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
  329. };
  330. } else if(type == 'date' || type == 'datetime') {
  331. findSortKey = function($cell, a) {
  332. return $.jgrid.parseDate(dfmt,$cell).getTime();
  333. };
  334. } else if($.isFunction(type)) {
  335. findSortKey = type;
  336. } else {
  337. findSortKey = function($cell, a) {
  338. if(!$cell) {$cell ="";}
  339. return $.trim(String($cell).toUpperCase());
  340. };
  341. }
  342. $.each(data,function(i,v){
  343. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  344. if(ab === undefined) { ab = ""; }
  345. ab = findSortKey(ab, v);
  346. _sortData.push({ 'vSort': ab,'index':i});
  347. });
  348. _sortData.sort(function(a,b){
  349. a = a.vSort;
  350. b = b.vSort;
  351. return self._compare(a,b,newDir);
  352. });
  353. j=0;
  354. var nrec= data.length;
  355. // overhead, but we do not change the original data.
  356. while(j<nrec) {
  357. i = _sortData[j].index;
  358. sortData.push(data[i]);
  359. j++;
  360. }
  361. return sortData;
  362. };
  363. this._getGroup=function(data,by,dir,type, dfmt){
  364. var results=[],
  365. group=null,
  366. last=null, val;
  367. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  368. val = $.jgrid.getAccessor(v, by);
  369. if(val === undefined) { val = ""; }
  370. if(!self._equals(last,val)){
  371. last=val;
  372. if(group !== null){
  373. results.push(group);
  374. }
  375. group=self._group(by,val);
  376. }
  377. group.items.push(v);
  378. });
  379. if(group !== null){
  380. results.push(group);
  381. }
  382. return results;
  383. };
  384. this.ignoreCase=function(){
  385. _usecase=false;
  386. return self;
  387. };
  388. this.useCase=function(){
  389. _usecase=true;
  390. return self;
  391. };
  392. this.trim=function(){
  393. _trim=true;
  394. return self;
  395. };
  396. this.noTrim=function(){
  397. _trim=false;
  398. return self;
  399. };
  400. this.execute=function(){
  401. var match=_query, results=[];
  402. if(match === null){
  403. return self;
  404. }
  405. $.each(_data,function(){
  406. if(eval(match)){results.push(this);}
  407. });
  408. _data=results;
  409. return self;
  410. };
  411. this.data=function(){
  412. return _data;
  413. };
  414. this.select=function(f){
  415. self._performSort();
  416. if(!self._hasData()){ return[]; }
  417. self.execute();
  418. if($.isFunction(f)){
  419. var results=[];
  420. $.each(_data,function(i,v){
  421. results.push(f(v));
  422. });
  423. return results;
  424. }
  425. return _data;
  426. };
  427. this.hasMatch=function(f){
  428. if(!self._hasData()) { return false; }
  429. self.execute();
  430. return _data.length>0;
  431. };
  432. this.andNot=function(f,v,x){
  433. _negate=!_negate;
  434. return self.and(f,v,x);
  435. };
  436. this.orNot=function(f,v,x){
  437. _negate=!_negate;
  438. return self.or(f,v,x);
  439. };
  440. this.not=function(f,v,x){
  441. return self.andNot(f,v,x);
  442. };
  443. this.and=function(f,v,x){
  444. _queuedOperator=" && ";
  445. if(f===undefined){
  446. return self;
  447. }
  448. return self._repeatCommand(f,v,x);
  449. };
  450. this.or=function(f,v,x){
  451. _queuedOperator=" || ";
  452. if(f===undefined) { return self; }
  453. return self._repeatCommand(f,v,x);
  454. };
  455. this.orBegin=function(){
  456. _orDepth++;
  457. return self;
  458. };
  459. this.orEnd=function(){
  460. if (_query !== null){
  461. _query+=")";
  462. }
  463. return self;
  464. };
  465. this.isNot=function(f){
  466. _negate=!_negate;
  467. return self.is(f);
  468. };
  469. this.is=function(f){
  470. self._append('this.'+f);
  471. self._resetNegate();
  472. return self;
  473. };
  474. this._compareValues=function(func,f,v,how,t){
  475. var fld;
  476. if(_useProperties){
  477. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  478. }else{
  479. fld='this';
  480. }
  481. if(v===undefined) { v = null; }
  482. //var val=v===null?f:v,
  483. var val =v,
  484. swst = t.stype === undefined ? "text" : t.stype;
  485. if(v !== null) {
  486. switch(swst) {
  487. case 'int':
  488. case 'integer':
  489. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  490. fld = 'parseInt('+fld+',10)';
  491. val = 'parseInt('+val+',10)';
  492. break;
  493. case 'float':
  494. case 'number':
  495. case 'numeric':
  496. val = String(val).replace(_stripNum, '');
  497. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  498. fld = 'parseFloat('+fld+')';
  499. val = 'parseFloat('+val+')';
  500. break;
  501. case 'date':
  502. case 'datetime':
  503. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  504. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  505. break;
  506. default :
  507. fld=self._getStr(fld);
  508. val=self._getStr('"'+self._toStr(val)+'"');
  509. }
  510. }
  511. self._append(fld+' '+how+' '+val);
  512. self._setCommand(func,f);
  513. self._resetNegate();
  514. return self;
  515. };
  516. this.equals=function(f,v,t){
  517. return self._compareValues(self.equals,f,v,"==",t);
  518. };
  519. this.notEquals=function(f,v,t){
  520. return self._compareValues(self.equals,f,v,"!==",t);
  521. };
  522. this.isNull = function(f,v,t){
  523. return self._compareValues(self.equals,f,null,"===",t);
  524. };
  525. this.greater=function(f,v,t){
  526. return self._compareValues(self.greater,f,v,">",t);
  527. };
  528. this.less=function(f,v,t){
  529. return self._compareValues(self.less,f,v,"<",t);
  530. };
  531. this.greaterOrEquals=function(f,v,t){
  532. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  533. };
  534. this.lessOrEquals=function(f,v,t){
  535. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  536. };
  537. this.startsWith=function(f,v){
  538. var val = (v===undefined || v===null) ? f: v,
  539. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  540. if(_useProperties){
  541. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  542. }else{
  543. length=_trim?$.trim(v.toString()).length:v.toString().length;
  544. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  545. }
  546. self._setCommand(self.startsWith,f);
  547. self._resetNegate();
  548. return self;
  549. };
  550. this.endsWith=function(f,v){
  551. var val = (v===undefined || v===null) ? f: v,
  552. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  553. if(_useProperties){
  554. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  555. } else {
  556. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  557. }
  558. self._setCommand(self.endsWith,f);self._resetNegate();
  559. return self;
  560. };
  561. this.contains=function(f,v){
  562. if(_useProperties){
  563. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  564. }else{
  565. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  566. }
  567. self._setCommand(self.contains,f);
  568. self._resetNegate();
  569. return self;
  570. };
  571. this.groupBy=function(by,dir,type, datefmt){
  572. if(!self._hasData()){
  573. return null;
  574. }
  575. return self._getGroup(_data,by,dir,type, datefmt);
  576. };
  577. this.orderBy=function(by,dir,stype, dfmt){
  578. dir = dir === undefined || dir === null ? "a" :$.trim(dir.toString().toLowerCase());
  579. if(stype === null || stype === undefined) { stype = "text"; }
  580. if(dfmt === null || dfmt === undefined) { dfmt = "Y-m-d"; }
  581. if(dir=="desc"||dir=="descending"){dir="d";}
  582. if(dir=="asc"||dir=="ascending"){dir="a";}
  583. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt});
  584. return self;
  585. };
  586. return self;
  587. };
  588. return new queryObject(source,null);
  589. },
  590. extend : function(methods) {
  591. $.extend($.fn.jqGrid,methods);
  592. if (!this.no_legacy_api) {
  593. $.fn.extend(methods);
  594. }
  595. }
  596. });
  597. $.fn.jqGrid = function( pin ) {
  598. if (typeof pin == 'string') {
  599. //var fn = $.fn.jqGrid[pin];
  600. var fn = $.jgrid.getAccessor($.fn.jqGrid,pin);
  601. if (!fn) {
  602. throw ("jqGrid - No such method: " + pin);
  603. }
  604. var args = $.makeArray(arguments).slice(1);
  605. return fn.apply(this,args);
  606. }
  607. return this.each( function() {
  608. if(this.grid) {return;}
  609. var p = $.extend(true,{
  610. url: "",
  611. height: 150,
  612. page: 1,
  613. rowNum: 20,
  614. rowTotal : null,
  615. records: 0,
  616. pager: "",
  617. pgbuttons: true,
  618. pginput: true,
  619. colModel: [],
  620. rowList: [],
  621. colNames: [],
  622. sortorder: "asc",
  623. sortname: "",
  624. datatype: "xml",
  625. mtype: "GET",
  626. altRows: false,
  627. selarrrow: [],
  628. savedRow: [],
  629. shrinkToFit: true,
  630. xmlReader: {},
  631. jsonReader: {},
  632. subGrid: false,
  633. subGridModel :[],
  634. reccount: 0,
  635. lastpage: 0,
  636. lastsort: 0,
  637. selrow: null,
  638. beforeSelectRow: null,
  639. onSelectRow: null,
  640. onSortCol: null,
  641. ondblClickRow: null,
  642. onRightClickRow: null,
  643. onPaging: null,
  644. onSelectAll: null,
  645. loadComplete: null,
  646. gridComplete: null,
  647. loadError: null,
  648. loadBeforeSend: null,
  649. afterInsertRow: null,
  650. beforeRequest: null,
  651. beforeProcessing : null,
  652. onHeaderClick: null,
  653. viewrecords: false,
  654. loadonce: false,
  655. multiselect: false,
  656. multikey: false,
  657. editurl: null,
  658. search: false,
  659. caption: "",
  660. hidegrid: true,
  661. hiddengrid: false,
  662. postData: {},
  663. userData: {},
  664. treeGrid : false,
  665. treeGridModel : 'nested',
  666. treeReader : {},
  667. treeANode : -1,
  668. ExpandColumn: null,
  669. tree_root_level : 0,
  670. 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"},
  671. forceFit : false,
  672. gridstate : "visible",
  673. cellEdit: false,
  674. cellsubmit: "remote",
  675. nv:0,
  676. loadui: "enable",
  677. toolbar: [false,""],
  678. scroll: false,
  679. multiboxonly : false,
  680. deselectAfterSort : true,
  681. scrollrows : false,
  682. autowidth: false,
  683. scrollOffset :18,
  684. cellLayout: 5,
  685. subGridWidth: 20,
  686. multiselectWidth: 20,
  687. gridview: false,
  688. rownumWidth: 25,
  689. rownumbers : false,
  690. pagerpos: 'center',
  691. recordpos: 'right',
  692. footerrow : false,
  693. userDataOnFooter : false,
  694. hoverrows : true,
  695. altclass : 'ui-priority-secondary',
  696. viewsortcols : [false,'vertical',true],
  697. resizeclass : '',
  698. autoencode : false,
  699. remapColumns : [],
  700. ajaxGridOptions :{},
  701. direction : "ltr",
  702. toppager: false,
  703. headertitles: false,
  704. scrollTimeout: 40,
  705. data : [],
  706. _index : {},
  707. grouping : false,
  708. groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], groupDataSorted : false, summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus'},
  709. ignoreCase : false,
  710. cmTemplate : {},
  711. idPrefix : ""
  712. }, $.jgrid.defaults, pin || {});
  713. var grid={
  714. headers:[],
  715. cols:[],
  716. footers: [],
  717. dragStart: function(i,x,y) {
  718. this.resizing = { idx: i, startX: x.clientX, sOL : y[0]};
  719. this.hDiv.style.cursor = "col-resize";
  720. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  721. this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]});
  722. if($.isFunction(p.resizeStart)) { p.resizeStart.call(this,x,i); }
  723. document.onselectstart=function(){return false;};
  724. },
  725. dragMove: function(x) {
  726. if(this.resizing) {
  727. var diff = x.clientX-this.resizing.startX,
  728. h = this.headers[this.resizing.idx],
  729. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  730. if(newWidth > 33) {
  731. this.curGbox.css({left:this.resizing.sOL+diff});
  732. if(p.forceFit===true ){
  733. hn = this.headers[this.resizing.idx+p.nv];
  734. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  735. if(nWn >33) {
  736. h.newWidth = newWidth;
  737. hn.newWidth = nWn;
  738. }
  739. } else {
  740. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  741. h.newWidth = newWidth;
  742. }
  743. }
  744. }
  745. },
  746. dragEnd: function() {
  747. this.hDiv.style.cursor = "default";
  748. if(this.resizing) {
  749. var idx = this.resizing.idx,
  750. nw = this.headers[idx].newWidth || this.headers[idx].width;
  751. nw = parseInt(nw,10);
  752. this.resizing = false;
  753. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  754. p.colModel[idx].width = nw;
  755. this.headers[idx].width = nw;
  756. this.headers[idx].el.style.width = nw + "px";
  757. this.cols[idx].style.width = nw+"px";
  758. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  759. if(p.forceFit===true){
  760. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  761. this.headers[idx+p.nv].width = nw;
  762. this.headers[idx+p.nv].el.style.width = nw + "px";
  763. this.cols[idx+p.nv].style.width = nw+"px";
  764. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  765. p.colModel[idx+p.nv].width = nw;
  766. } else {
  767. p.tblwidth = this.newWidth || p.tblwidth;
  768. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  769. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  770. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  771. if(p.footerrow) {
  772. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  773. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  774. }
  775. }
  776. if($.isFunction(p.resizeStop)) { p.resizeStop.call(this,nw,idx); }
  777. }
  778. this.curGbox = null;
  779. document.onselectstart=function(){return true;};
  780. },
  781. populateVisible: function() {
  782. if (grid.timer) { clearTimeout(grid.timer); }
  783. grid.timer = null;
  784. var dh = $(grid.bDiv).height();
  785. if (!dh) { return; }
  786. var table = $("table:first", grid.bDiv);
  787. var rows, rh;
  788. if(table[0].rows.length) {
  789. try {
  790. rows = table[0].rows[1];
  791. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  792. } catch (pv) {
  793. rh = grid.prevRowHeight;
  794. }
  795. }
  796. if (!rh) { return; }
  797. grid.prevRowHeight = rh;
  798. var rn = p.rowNum;
  799. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  800. var ttop = Math.round(table.position().top) - scrollTop;
  801. var tbot = ttop + table.height();
  802. var div = rh * rn;
  803. var page, npage, empty;
  804. if ( tbot < dh && ttop <= 0 &&
  805. (p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage))
  806. {
  807. npage = parseInt((dh - tbot + div - 1) / div,10);
  808. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  809. page = Math.round((tbot + scrollTop) / div) + 1;
  810. ttop = -1;
  811. } else {
  812. ttop = 1;
  813. }
  814. }
  815. if (ttop > 0) {
  816. page = parseInt(scrollTop / div,10) + 1;
  817. npage = parseInt((scrollTop + dh) / div,10) + 2 - page;
  818. empty = true;
  819. }
  820. if (npage) {
  821. if (p.lastpage && page > p.lastpage || p.lastpage==1 || (page === p.page && page===p.lastpage) ) {
  822. return;
  823. }
  824. if (grid.hDiv.loading) {
  825. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  826. } else {
  827. p.page = page;
  828. if (empty) {
  829. grid.selectionPreserver(table[0]);
  830. grid.emptyRows(grid.bDiv,false, false);
  831. }
  832. grid.populate(npage);
  833. }
  834. }
  835. },
  836. scrollGrid: function( e ) {
  837. if(p.scroll) {
  838. var scrollTop = grid.bDiv.scrollTop;
  839. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  840. if (scrollTop != grid.scrollTop) {
  841. grid.scrollTop = scrollTop;
  842. if (grid.timer) { clearTimeout(grid.timer); }
  843. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  844. }
  845. }
  846. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  847. if(p.footerrow) {
  848. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  849. }
  850. if( e ) { e.stopPropagation(); }
  851. },
  852. selectionPreserver : function(ts) {
  853. var p = ts.p;
  854. var sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null;
  855. var left = ts.grid.bDiv.scrollLeft;
  856. var complete = p.gridComplete;
  857. p.gridComplete = function() {
  858. p.selrow = null;
  859. p.selarrrow = [];
  860. if(p.multiselect && sra && sra.length>0) {
  861. for(var i=0;i<sra.length;i++){
  862. if (sra[i] != sr) {
  863. $(ts).jqGrid("setSelection",sra[i],false);
  864. }
  865. }
  866. }
  867. if (sr) {
  868. $(ts).jqGrid("setSelection",sr,false);
  869. }
  870. ts.grid.bDiv.scrollLeft = left;
  871. p.gridComplete = complete;
  872. if (p.gridComplete) {
  873. complete();
  874. }
  875. };
  876. }
  877. };
  878. if(this.tagName.toUpperCase()!='TABLE') {
  879. alert("Element is not a table");
  880. return;
  881. }
  882. $(this).empty().attr("tabindex","1");
  883. this.p = p ;
  884. this.p.useProp = !!$.fn.prop;
  885. var i, dir,ts;
  886. if(this.p.colNames.length === 0) {
  887. for (i=0;i<this.p.colModel.length;i++){
  888. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  889. }
  890. }
  891. if( this.p.colNames.length !== this.p.colModel.length ) {
  892. alert($.jgrid.errors.model);
  893. return;
  894. }
  895. var gv = $("<div class='ui-jqgrid-view'></div>"), ii,
  896. isMSIE = $.browser.msie ? true:false,
  897. isSafari = $.browser.webkit || $.browser.safari ? true : false;
  898. ts = this;
  899. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  900. if($.inArray(ts.p.direction,["ltr","rtl"]) == -1) { ts.p.direction = "ltr"; }
  901. dir = ts.p.direction;
  902. $(gv).insertBefore(this);
  903. $(this).appendTo(gv).removeClass("scroll");
  904. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  905. $(eg).insertBefore(gv).attr({"id" : "gbox_"+this.id,"dir":dir});
  906. $(gv).appendTo(eg).attr("id","gview_"+this.id);
  907. if (isMSIE && $.browser.version <= 6) {
  908. ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
  909. } else { ii="";}
  910. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").append(ii).insertBefore(gv);
  911. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  912. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  913. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  914. intNum = function(val,defval) {
  915. val = parseInt(val,10);
  916. if (isNaN(val)) { return defval ? defval : 0;}
  917. else {return val;}
  918. },
  919. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  920. var cm = ts.p.colModel[pos],
  921. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  922. if(ral) { result += "text-align:"+ral+";"; }
  923. if(cm.hidden===true) { result += "display:none;"; }
  924. if(rowInd===0) {
  925. result += "width: "+grid.headers[pos].width+"px;";
  926. } else if (cm.cellattr && $.isFunction(cm.cellattr))
  927. {
  928. celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
  929. if(celp && typeof(celp) === "string") {
  930. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  931. if(celp.indexOf('title') > -1) { cm.title=false;}
  932. if(celp.indexOf('class') > -1) { clas = undefined;}
  933. acp = celp.split("style");
  934. if(acp.length === 2 ) {
  935. acp[1] = $.trim(acp[1].replace("=",""));
  936. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  937. acp[1] = acp[1].substring(1);
  938. }
  939. result += acp[1].replace(/'/gi,'"');
  940. } else {
  941. result += "\"";
  942. }
  943. }
  944. }
  945. if(!acp.length) { acp[0] = ""; result += "\"";}
  946. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  947. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  948. return result + acp[0];
  949. },
  950. cellVal = function (val) {
  951. return val === undefined || val === null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : val+"");
  952. },
  953. formatter = function (rowId, cellval , colpos, rwdat, _act){
  954. var cm = ts.p.colModel[colpos],v;
  955. if(typeof cm.formatter !== 'undefined') {
  956. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  957. if($.isFunction( cm.formatter ) ) {
  958. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  959. } else if($.fmatter){
  960. v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act);
  961. } else {
  962. v = cellVal(cellval);
  963. }
  964. } else {
  965. v = cellVal(cellval);
  966. }
  967. return v;
  968. },
  969. addCell = function(rowId,cell,pos,irow, srvr) {
  970. var v,prp;
  971. v = formatter(rowId,cell,pos,srvr,'add');
  972. prp = formatCol( pos,irow, v, srvr, rowId, true);
  973. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  974. },
  975. addMulti = function(rowid,pos,irow){
  976. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"/>",
  977. prp = formatCol( pos,irow,'',null, rowid, true);
  978. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  979. },
  980. addRowNum = function (pos,irow,pG,rN) {
  981. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  982. prp = formatCol( pos,irow,v, null, irow, true);
  983. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  984. },
  985. reader = function (datatype) {
  986. var field, f=[], j=0, i;
  987. for(i =0; i<ts.p.colModel.length; i++){
  988. field = ts.p.colModel[i];
  989. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  990. if(datatype == "local") {
  991. f[j] = field.name;
  992. } else {
  993. f[j] = (datatype=="xml") ? field.xmlmap || field.name : field.jsonmap || field.name;
  994. }
  995. j++;
  996. }
  997. }
  998. return f;
  999. },
  1000. orderedCols = function (offset) {
  1001. var order = ts.p.remapColumns;
  1002. if (!order || !order.length) {
  1003. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1004. }
  1005. if (offset) {
  1006. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1007. }
  1008. return order;
  1009. },
  1010. emptyRows = function (parent, scroll, locdata) {
  1011. if(ts.p.deepempty) {$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first tr:gt(0)").remove();}
  1012. else {
  1013. var trf = $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first tr:first")[0];
  1014. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").empty().append(trf);
  1015. }
  1016. if (scroll && ts.p.scroll) {
  1017. $(">div:first", parent).css({height:"auto"}).children("div:first").css({height:0,display:"none"});
  1018. parent.scrollTop = 0;
  1019. }
  1020. if(locdata === true) {
  1021. if(ts.p.treeGrid === true ) {
  1022. ts.p.data = []; ts.p._index = {};
  1023. }
  1024. }
  1025. },
  1026. refreshIndex = function() {
  1027. var datalen = ts.p.data.length, idname, i, val,
  1028. ni = ts.p.rownumbers===true ? 1 :0,
  1029. gi = ts.p.multiselect ===true ? 1 :0,
  1030. si = ts.p.subGrid===true ? 1 :0;
  1031. if(ts.p.keyIndex === false || ts.p.loadonce === true) {
  1032. idname = ts.p.localReader.id;
  1033. } else {
  1034. idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name;
  1035. }
  1036. for(i =0;i < datalen; i++) {
  1037. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1038. ts.p._index[val] = i;
  1039. }
  1040. },
  1041. addXmlData = function (xml,t, rcnt, more, adjust) {
  1042. var startReq = new Date(),
  1043. locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "xmlstring",
  1044. xmlid = "_id_",
  1045. frd = ts.p.datatype == "local" ? "local" : "xml";
  1046. if(locdata) {
  1047. ts.p.data = [];
  1048. ts.p._index = {};
  1049. ts.p.localReader.id = xmlid;
  1050. }
  1051. ts.p.reccount = 0;
  1052. if($.isXMLDoc(xml)) {
  1053. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1054. emptyRows(t,false, true);
  1055. rcnt=1;
  1056. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1057. } else { return; }
  1058. var i,fpos,ir=0,v,row,gi=0,si=0,ni=0,idn, getId,f=[],F,rd ={}, xmlr,rid, rowData=[], cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1;
  1059. if(!ts.p.xmlReader.repeatitems) {f = reader(frd);}
  1060. if( ts.p.keyIndex===false) {
  1061. idn = ts.p.xmlReader.id;
  1062. } else {
  1063. idn = ts.p.keyIndex;
  1064. }
  1065. if(f.length>0 && !isNaN(idn)) {
  1066. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1067. idn = $.inArray(idn, ts.p.remapColumns);
  1068. }
  1069. idn=f[idn];
  1070. }
  1071. if( (idn+"").indexOf("[") === -1 ) {
  1072. if (f.length) {
  1073. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1074. } else {
  1075. getId = function( trow, k) {return $(ts.p.xmlReader.cell,trow).eq(idn).text() || k;};
  1076. }
  1077. }
  1078. else {
  1079. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1080. }
  1081. ts.p.userData = {};
  1082. $(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text || 0; });
  1083. $(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text; if(ts.p.lastpage===undefined) { ts.p.lastpage=1; } } );
  1084. $(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text || 0; } );
  1085. $(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1086. var gxml = $(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml);
  1087. if (!gxml) { gxml = []; }
  1088. var gl = gxml.length, j=0, grpdata={}, rn;
  1089. if(gxml && gl){
  1090. rn = parseInt(ts.p.rowNum,10);
  1091. var br=ts.p.scroll?$.jgrid.randId():1,altr;
  1092. if (adjust) { rn *= adjust+1; }
  1093. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow="";
  1094. if(ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
  1095. hiderow = " style=\"display:none;\"";
  1096. }
  1097. while (j<gl) {
  1098. xmlr = gxml[j];
  1099. rid = getId(xmlr,br+j);
  1100. rid = ts.p.idPrefix + rid;
  1101. altr = rcnt === 0 ? 0 : rcnt+1;
  1102. cn1 = (altr+j)%2 == 1 ? cn : '';
  1103. rowData.push( "<tr"+hiderow+" id=\""+rid+"\" tabindex=\"-1\" role=\"row\" class =\"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">" );
  1104. if(ts.p.rownumbers===true) {
  1105. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1106. ni=1;
  1107. }
  1108. if(ts.p.multiselect===true) {
  1109. rowData.push( addMulti(rid,ni,j) );
  1110. gi=1;
  1111. }
  1112. if (ts.p.subGrid===true) {
  1113. rowData.push( $(ts).jqGrid("addSubGridCell",gi+ni,j+rcnt) );
  1114. si= 1;
  1115. }
  1116. if(ts.p.xmlReader.repeatitems){
  1117. if (!F) { F=orderedCols(gi+si+ni); }
  1118. var cells = $(ts.p.xmlReader.cell,xmlr);
  1119. $.each(F, function (k) {
  1120. var cell = cells[this];
  1121. if (!cell) { return false; }
  1122. v = cell.textContent || cell.text;
  1123. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1124. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr) );
  1125. });
  1126. } else {
  1127. for(i = 0; i < f.length;i++) {
  1128. v = $(f[i],xmlr).text();
  1129. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1130. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr) );
  1131. }
  1132. }
  1133. rowData.push("</tr>");
  1134. if(ts.p.grouping) {
  1135. var grlen = ts.p.groupingView.groupField.length, grpitem = [];
  1136. for(var z=0;z<grlen;z++) {
  1137. grpitem.push(rd[ts.p.groupingView.groupField[z]]);
  1138. }
  1139. grpdata = $(ts).jqGrid('groupingPrepare',rowData, grpitem, grpdata, rd);
  1140. rowData = [];
  1141. }
  1142. if(locdata || ts.p.treeGrid === true) {
  1143. rd[xmlid] = rid;
  1144. ts.p.data.push(rd);
  1145. ts.p._index[rid] = ts.p.data.length-1;
  1146. }
  1147. if(ts.p.gridview === false ) {
  1148. $("tbody:first",t).append(rowData.join(''));
  1149. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1150. rowData=[];
  1151. }
  1152. rd={};
  1153. ir++;
  1154. j++;
  1155. if(ir==rn) {break;}
  1156. }
  1157. }
  1158. if(ts.p.gridview === true) {
  1159. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1160. if(ts.p.grouping) {
  1161. $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1162. grpdata = null;
  1163. } else if(ts.p.treeGrid === true && fpos > 0) {
  1164. $(ts.rows[fpos]).after(rowData.join(''));
  1165. } else {
  1166. $("tbody:first",t).append(rowData.join(''));
  1167. }
  1168. }
  1169. if(ts.p.subGrid === true ) {
  1170. try {$(ts).jqGrid("addSubGrid",gi+ni);} catch (_){}
  1171. }
  1172. ts.p.totaltime = new Date() - startReq;
  1173. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1174. rowData =null;
  1175. if( ts.p.treeGrid === true) {
  1176. try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1177. }
  1178. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1179. ts.p.reccount=ir;
  1180. ts.p.treeANode = -1;
  1181. if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
  1182. if(locdata) {
  1183. ts.p.records = gl;
  1184. ts.p.lastpage = Math.ceil(gl/ rn);
  1185. }
  1186. if (!more) { ts.updatepager(false,true); }
  1187. if(locdata) {
  1188. while (ir<gl) {
  1189. xmlr = gxml[ir];
  1190. rid = getId(xmlr,ir);
  1191. rid = ts.p.idPrefix + rid;
  1192. if(ts.p.xmlReader.repeatitems){
  1193. if (!F) { F=orderedCols(gi+si+ni); }
  1194. var cells2 = $(ts.p.xmlReader.cell,xmlr);
  1195. $.each(F, function (k) {
  1196. var cell = cells2[this];
  1197. if (!cell) { return false; }
  1198. v = cell.textContent || cell.text;
  1199. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1200. });
  1201. } else {
  1202. for(i = 0; i < f.length;i++) {
  1203. v = $(f[i],xmlr).text();
  1204. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1205. }
  1206. }
  1207. rd[xmlid] = rid;
  1208. ts.p.data.push(rd);
  1209. ts.p._index[rid] = ts.p.data.length-1;
  1210. rd = {};
  1211. ir++;
  1212. }
  1213. }
  1214. },
  1215. addJSONData = function(data,t, rcnt, more, adjust) {
  1216. var startReq = new Date();
  1217. if(data) {
  1218. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1219. emptyRows(t,false, true);
  1220. rcnt=1;
  1221. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1222. } else { return; }
  1223. var dReader, locid = "_id_", frd,
  1224. locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "jsonstring";
  1225. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1226. ts.p.reccount = 0;
  1227. if(ts.p.datatype == "local") {
  1228. dReader = ts.p.localReader;
  1229. frd= 'local';
  1230. } else {
  1231. dReader = ts.p.jsonReader;
  1232. frd='json';
  1233. }
  1234. var ir=0,v,i,j,f=[],F,cur,gi=0,si=0,ni=0,len,drows,idn,rd={}, fpos, idr,rowData=[],cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1,lp;
  1235. ts.p.page = $.jgrid.getAccessor(data,dReader.page) || 0;
  1236. lp = $.jgrid.getAccessor(data,dReader.total);
  1237. ts.p.lastpage = lp === undefined ? 1 : lp;
  1238. ts.p.records = $.jgrid.getAccessor(data,dReader.records) || 0;
  1239. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1240. if(!dReader.repeatitems) {
  1241. F = f = reader(frd);
  1242. }
  1243. if( ts.p.keyIndex===false ) {
  1244. idn = dReader.id;
  1245. } else {
  1246. idn = ts.p.keyIndex;
  1247. }
  1248. if(f.length>0 && !isNaN(idn)) {
  1249. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1250. idn = $.inArray(idn, ts.p.remapColumns);
  1251. }
  1252. idn=f[idn];
  1253. }
  1254. drows = $.jgrid.getAccessor(data,dReader.root);
  1255. if (!drows) { drows = []; }
  1256. len = drows.length; i=0;
  1257. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr;
  1258. if (adjust) { rn *= adjust+1; }
  1259. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata={}, hiderow="";
  1260. if(ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
  1261. hiderow = " style=\"display:none;\"";
  1262. }
  1263. while (i<len) {
  1264. cur = drows[i];
  1265. idr = $.jgrid.getAccessor(cur,idn);
  1266. if(idr === undefined) {
  1267. idr = br+i;
  1268. if(f.length===0){
  1269. if(dReader.cell){
  1270. var ccur = $.jgrid.getAccessor(cur,dReader.cell);
  1271. idr = ccur[idn] || idr;
  1272. ccur=null;
  1273. }
  1274. }
  1275. }
  1276. idr = ts.p.idPrefix + idr;
  1277. altr = rcnt === 1 ? 0 : rcnt;
  1278. cn1 = (altr+i)%2 == 1 ? cn : '';
  1279. rowData.push("<tr"+hiderow+" id=\""+ idr +"\" tabindex=\"-1\" role=\"row\" class= \"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">");
  1280. if(ts.p.rownumbers===true) {
  1281. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1282. ni=1;
  1283. }
  1284. if(ts.p.multiselect){
  1285. rowData.push( addMulti(idr,ni,i) );
  1286. gi = 1;
  1287. }
  1288. if (ts.p.subGrid) {
  1289. rowData.push( $(ts).jqGrid("addSubGridCell",gi+ni,i+rcnt) );
  1290. si= 1;
  1291. }
  1292. if (dReader.repeatitems) {
  1293. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
  1294. if (!F) { F=orderedCols(gi+si+ni); }
  1295. }
  1296. for (j=0;j<F.length;j++) {
  1297. v = $.jgrid.getAccessor(cur,F[j]);
  1298. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur) );
  1299. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1300. }
  1301. rowData.push( "</tr>" );
  1302. if(ts.p.grouping) {
  1303. var grlen = ts.p.groupingView.groupField.length, grpitem = [];
  1304. for(var z=0;z<grlen;z++) {
  1305. grpitem.push(rd[ts.p.groupingView.groupField[z]]);
  1306. }
  1307. grpdata = $(ts).jqGrid('groupingPrepare',rowData, grpitem, grpdata, rd);
  1308. rowData = [];
  1309. }
  1310. if(locdata || ts.p.treeGrid===true) {
  1311. rd[locid] = idr;
  1312. ts.p.data.push(rd);
  1313. ts.p._index[idr] = ts.p.data.length-1;
  1314. }
  1315. if(ts.p.gridview === false ) {
  1316. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1317. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1318. rowData=[];//ari=0;
  1319. }
  1320. rd={};
  1321. ir++;
  1322. i++;
  1323. if(ir==rn) { break; }
  1324. }
  1325. if(ts.p.gridview === true ) {
  1326. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1327. if(ts.p.grouping) {
  1328. $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1329. grpdata = null;
  1330. } else if(ts.p.treeGrid === true && fpos > 0) {
  1331. $(ts.rows[fpos]).after(rowData.join(''));
  1332. } else {
  1333. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1334. }
  1335. }
  1336. if(ts.p.subGrid === true ) {
  1337. try { $(ts).jqGrid("addSubGrid",gi+ni);} catch (_){}
  1338. }
  1339. ts.p.totaltime = new Date() - startReq;
  1340. if(ir>0) {
  1341. if(ts.p.records===0) { ts.p.records=len; }
  1342. }
  1343. rowData = null;
  1344. if( ts.p.treeGrid === true) {
  1345. try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1346. }
  1347. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1348. ts.p.reccount=ir;
  1349. ts.p.treeANode = -1;
  1350. if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
  1351. if(locdata) {
  1352. ts.p.records = len;
  1353. ts.p.lastpage = Math.ceil(len/ rn);
  1354. }
  1355. if (!more) { ts.updatepager(false,true); }
  1356. if(locdata) {
  1357. while (ir<len && drows[ir]) {
  1358. cur = drows[ir];
  1359. idr = $.jgrid.getAccessor(cur,idn);
  1360. if(idr === undefined) {
  1361. idr = br+ir;
  1362. if(f.length===0){
  1363. if(dReader.cell){
  1364. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell);
  1365. idr = ccur2[idn] || idr;
  1366. ccur2=null;
  1367. }
  1368. }
  1369. }
  1370. if(cur) {
  1371. idr = ts.p.idPrefix + idr;
  1372. if (dReader.repeatitems) {
  1373. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
  1374. if (!F) { F=orderedCols(gi+si+ni); }
  1375. }
  1376. for (j=0;j<F.length;j++) {
  1377. v = $.jgrid.getAccessor(cur,F[j]);
  1378. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1379. }
  1380. rd[locid] = idr;
  1381. ts.p.data.push(rd);
  1382. ts.p._index[idr] = ts.p.data.length-1;
  1383. rd = {};
  1384. }
  1385. ir++;
  1386. }
  1387. }
  1388. },
  1389. addLocalData = function() {
  1390. var st, fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1391. if(!$.isArray(ts.p.data)) {
  1392. return;
  1393. }
  1394. var grpview = ts.p.grouping ? ts.p.groupingView : false;
  1395. $.each(ts.p.colModel,function(i,v){
  1396. sorttype = this.sorttype || "text";
  1397. if(sorttype == "date" || sorttype == "datetime") {
  1398. if(this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date') {
  1399. if(this.formatoptions && this.formatoptions.srcformat) {
  1400. srcformat = this.formatoptions.srcformat;
  1401. } else {
  1402. srcformat = $.jgrid.formatter.date.srcformat;
  1403. }
  1404. if(this.formatoptions && this.formatoptions.newformat) {
  1405. newformat = this.formatoptions.newformat;
  1406. } else {
  1407. newformat = $.jgrid.formatter.date.newformat;
  1408. }
  1409. } else {
  1410. srcformat = newformat = this.datefmt || "Y-m-d";
  1411. }
  1412. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat};
  1413. } else {
  1414. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":''};
  1415. }
  1416. if(ts.p.grouping && this.name == grpview.groupField[0]) {
  1417. var grindex = this.name;
  1418. if (typeof this.index != 'undefined') {
  1419. grindex = this.index;
  1420. }
  1421. grtypes[0] = cmtypes[grindex];
  1422. grindexes.push(grindex);
  1423. }
  1424. if(!fndsort && (this.index == ts.p.sortname || this.name == ts.p.sortname)){
  1425. st = this.name; // ???
  1426. fndsort = true;
  1427. }
  1428. });
  1429. if(ts.p.treeGrid) {
  1430. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype, cmtypes[st].srcfmt);
  1431. return;
  1432. }
  1433. var compareFnMap = {
  1434. 'eq':function(queryObj, op) {return queryObj.equals;},
  1435. 'ne':function(queryObj,op) {return queryObj.notEquals;},
  1436. 'lt':function(queryObj,op) {return queryObj.less;},
  1437. 'le':function(queryObj,op) {return queryObj.lessOrEquals;},
  1438. 'gt':function(queryObj,op) {return queryObj.greater;},
  1439. 'ge':function(queryObj,op) {return queryObj.greaterOrEquals;},
  1440. 'cn':function(queryObj,op) {return queryObj.contains;},
  1441. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1442. 'bw':function(queryObj,op) {return queryObj.startsWith;},
  1443. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1444. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1445. 'ew':function(queryObj,op) {return queryObj.endsWith;},
  1446. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1447. 'in':function(queryObj,op) {return queryObj.equals;},
  1448. 'nu':function(queryObj,op) {return queryObj.isNull;},
  1449. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1450. },
  1451. query = $.jgrid.from(ts.p.data);
  1452. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1453. function tojLinq ( group ) {
  1454. var s = 0, index, gor, ror, opr, rule;
  1455. if (group.groups !== undefined) {
  1456. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1457. if (gor) {
  1458. query.orBegin();
  1459. }
  1460. for (index = 0; index < group.groups.length; index++) {
  1461. if (s > 0 && gor) {
  1462. query.or();
  1463. }
  1464. try {
  1465. tojLinq(group.groups[index]);
  1466. } catch (e) {alert(e);}
  1467. s++;
  1468. }
  1469. if (gor) {
  1470. query.orEnd();
  1471. }
  1472. }
  1473. if (group.rules !== undefined) {
  1474. if(s>0) {
  1475. var result = query.select();
  1476. query = $.jgrid.from( result);
  1477. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1478. }
  1479. try{
  1480. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1481. if (ror) {
  1482. query.orBegin();
  1483. }
  1484. for (index = 0; index < group.rules.length; index++) {
  1485. rule = group.rules[index];
  1486. opr = group.groupOp.toString().toUpperCase();
  1487. if (compareFnMap[rule.op] && rule.field ) {
  1488. if(s > 0 && opr && opr === "OR") {
  1489. query = query.or();
  1490. }
  1491. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1492. }
  1493. s++;
  1494. }
  1495. if (ror) {
  1496. query.orEnd();
  1497. }
  1498. } catch (g) {alert(g);}
  1499. }
  1500. }
  1501. if (ts.p.search === true) {
  1502. var srules = ts.p.postData.filters;
  1503. if(srules) {
  1504. if(typeof srules == "string") { srules = $.jgrid.parse(srules);}
  1505. tojLinq( srules );
  1506. } else {
  1507. try {
  1508. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1509. } catch (se){}
  1510. }
  1511. }
  1512. if(ts.p.grouping) {
  1513. query.orderBy(grindexes,grpview.groupOrder[0],grtypes[0].stype, grtypes[0].srcfmt);
  1514. grpview.groupDataSorted = true;
  1515. }
  1516. if (st && ts.p.sortorder && fndsort) {
  1517. if(ts.p.sortorder.toUpperCase() == "DESC") {
  1518. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt);
  1519. } else {
  1520. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt);
  1521. }
  1522. }
  1523. var queryResults = query.select(),
  1524. recordsperpage = parseInt(ts.p.rowNum,10),
  1525. total = queryResults.length,
  1526. page = parseInt(ts.p.page,10),
  1527. totalpages = Math.ceil(total / recordsperpage),
  1528. retresult = {};
  1529. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1530. query = null;
  1531. cmtypes = null;
  1532. retresult[ts.p.localReader.total] = totalpages;
  1533. retresult[ts.p.localReader.page] = page;
  1534. retresult[ts.p.localReader.records] = total;
  1535. retresult[ts.p.localReader.root] = queryResults;
  1536. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1537. queryResults = null;
  1538. return retresult;
  1539. },
  1540. updatepager = function(rn, dnd) {
  1541. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  1542. tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
  1543. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  1544. base = parseInt(ts.p.page,10)-1;
  1545. if(base < 0) { base = 0; }
  1546. base = base*parseInt(ts.p.rowNum,10);
  1547. to = base + ts.p.reccount;
  1548. if (ts.p.scroll) {
  1549. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  1550. base = to - rows.length;
  1551. ts.p.reccount = rows.length;
  1552. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  1553. if (rh) {
  1554. var top = base * rh;
  1555. var height = parseInt(ts.p.records,10) * rh;
  1556. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  1557. }
  1558. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  1559. }
  1560. pgboxes = ts.p.pager ? ts.p.pager : "";
  1561. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  1562. if(pgboxes) {
  1563. fmt = $.jgrid.formatter.integer || {};
  1564. cp = intNum(ts.p.page);
  1565. last = intNum(ts.p.lastpage);
  1566. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  1567. if(ts.p.pginput===true) {
  1568. $('.ui-pg-input',pgboxes).val(ts.p.page);
  1569. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
  1570. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  1571. }
  1572. if (ts.p.viewrecords){
  1573. if(ts.p.reccount === 0) {
  1574. $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
  1575. } else {
  1576. from = base+1;
  1577. tot=ts.p.records;
  1578. if($.fmatter) {
  1579. from = $.fmatter.util.NumberFormat(from,fmt);
  1580. to = $.fmatter.util.NumberFormat(to,fmt);
  1581. tot = $.fmatter.util.NumberFormat(tot,fmt);
  1582. }
  1583. $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
  1584. }
  1585. }
  1586. if(ts.p.pgbuttons===true) {
  1587. if(cp<=0) {cp = last = 0;}
  1588. if(cp==1 || cp === 0) {
  1589. $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1590. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1591. } else {
  1592. $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled');
  1593. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); }
  1594. }
  1595. if(cp==last || cp === 0) {
  1596. $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1597. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1598. } else {
  1599. $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled');
  1600. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); }
  1601. }
  1602. }
  1603. }
  1604. if(rn===true && ts.p.rownumbers === true) {
  1605. $("td.jqgrid-rownum",ts.rows).each(function(i){
  1606. $(this).html(base+1+i);
  1607. });
  1608. }
  1609. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  1610. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  1611. },
  1612. beginReq = function() {
  1613. ts.grid.hDiv.loading = true;
  1614. if(ts.p.hiddengrid) { return;}
  1615. switch(ts.p.loadui) {
  1616. case "disable":
  1617. break;
  1618. case "enable":
  1619. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1620. break;
  1621. case "block":
  1622. $("#lui_"+$.jgrid.jqID(ts.p.id)).show();
  1623. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1624. break;
  1625. }
  1626. },
  1627. endReq = function() {
  1628. ts.grid.hDiv.loading = false;
  1629. switch(ts.p.loadui) {
  1630. case "disable":
  1631. break;
  1632. case "enable":
  1633. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1634. break;
  1635. case "block":
  1636. $("#lui_"+$.jgrid.jqID(ts.p.id)).hide();
  1637. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1638. break;
  1639. }
  1640. },
  1641. populate = function (npage) {
  1642. if(!ts.grid.hDiv.loading) {
  1643. var pvis = ts.p.scroll && npage === false;
  1644. var prm = {}, dt, dstr, pN=ts.p.prmNames;
  1645. if(ts.p.page <=0) { ts.p.page = 1; }
  1646. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  1647. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  1648. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  1649. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  1650. var lc = ts.p.loadComplete;
  1651. var lcf = $.isFunction(lc);
  1652. if (!lcf) { lc = null; }
  1653. var adjust = 0;
  1654. npage = npage || 1;
  1655. if (npage > 1) {
  1656. if(pN.npage !== null) {
  1657. prm[pN.npage] = npage;
  1658. adjust = npage - 1;
  1659. npage = 1;
  1660. } else {
  1661. lc = function(req) {
  1662. ts.p.page++;
  1663. ts.grid.hDiv.loading = false;
  1664. if (lcf) {
  1665. ts.p.loadComplete.call(ts,req);
  1666. }
  1667. populate(npage-1);
  1668. };
  1669. }
  1670. } else if (pN.npage !== null) {
  1671. delete ts.p.postData[pN.npage];
  1672. }
  1673. if(ts.p.grouping) {
  1674. $(ts).jqGrid('groupingSetup');
  1675. if(ts.p.groupingView.groupDataSorted === true) {
  1676. prm[pN.sort] = ts.p.groupingView.groupField[0] +" "+ ts.p.groupingView.groupOrder[0]+", "+prm[pN.sort];
  1677. }
  1678. }
  1679. $.extend(ts.p.postData,prm);
  1680. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  1681. if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id); return;}
  1682. else if($.isFunction(ts.p.beforeRequest)) {
  1683. var bfr = ts.p.beforeRequest.call(ts);
  1684. if(bfr === undefined) { bfr = true; }
  1685. if ( bfr === false ) { return; }
  1686. }
  1687. dt = ts.p.datatype.toLowerCase();
  1688. switch(dt)
  1689. {
  1690. case "json":
  1691. case "jsonp":
  1692. case "xml":
  1693. case "script":
  1694. $.ajax($.extend({
  1695. url:ts.p.url,
  1696. type:ts.p.mtype,
  1697. dataType: dt ,
  1698. data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  1699. success:function(data,st, xhr) {
  1700. if ($.isFunction(ts.p.beforeProcessing)) {
  1701. ts.p.beforeProcessing.call(ts, data, st, xhr);
  1702. }
  1703. if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  1704. else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  1705. if(lc) { lc.call(ts,data); }
  1706. if (pvis) { ts.grid.populateVisible(); }
  1707. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  1708. data=null;
  1709. if (npage === 1) { endReq(); }
  1710. },
  1711. error:function(xhr,st,err){
  1712. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  1713. if (npage === 1) { endReq(); }
  1714. xhr=null;
  1715. },
  1716. beforeSend: function(xhr, settings ){
  1717. var gotoreq = true;
  1718. if($.isFunction(ts.p.loadBeforeSend)) {
  1719. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  1720. }
  1721. if(gotoreq === undefined) { gotoreq = true; }
  1722. if(gotoreq === false) {
  1723. return false;
  1724. } else {
  1725. beginReq();
  1726. }
  1727. }
  1728. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  1729. break;
  1730. case "xmlstring":
  1731. beginReq();
  1732. dstr = $.jgrid.stringToDoc(ts.p.datastr);
  1733. addXmlData(dstr,ts.grid.bDiv);
  1734. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  1735. ts.p.datatype = "local";
  1736. ts.p.datastr = null;
  1737. endReq();
  1738. break;
  1739. case "jsonstring":
  1740. beginReq();
  1741. if(typeof ts.p.datastr == 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  1742. else { dstr = ts.p.datastr; }
  1743. addJSONData(dstr,ts.grid.bDiv);
  1744. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  1745. ts.p.datatype = "local";
  1746. ts.p.datastr = null;
  1747. endReq();
  1748. break;
  1749. case "local":
  1750. case "clientside":
  1751. beginReq();
  1752. ts.p.datatype = "local";
  1753. var req = addLocalData();
  1754. addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
  1755. if(lc) { lc.call(ts,req); }
  1756. if (pvis) { ts.grid.populateVisible(); }
  1757. endReq();
  1758. break;
  1759. }
  1760. }
  1761. },
  1762. setPager = function (pgid, tp){
  1763. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  1764. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  1765. pginp = "",
  1766. pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
  1767. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  1768. clearVals = function(onpaging){
  1769. var ret;
  1770. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
  1771. ts.p.selrow = null;
  1772. if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);}
  1773. ts.p.savedRow = [];
  1774. if(ret=='stop') {return false;}
  1775. return true;
  1776. };
  1777. pgid = pgid.substr(1);
  1778. tp += "_" + pgid;
  1779. pgcnt = "pg_"+pgid;
  1780. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  1781. $("#"+$.jgrid.jqID(pgid) )
  1782. .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>")
  1783. .attr("dir","ltr"); //explicit setting
  1784. if(ts.p.rowList.length >0){
  1785. str = "<td dir='"+dir+"'>";
  1786. str +="<select class='ui-pg-selbox' role='listbox'>";
  1787. for(i=0;i<ts.p.rowList.length;i++){
  1788. str +="<option role=\"option\" value=\""+ts.p.rowList[i]+"\""+((ts.p.rowNum == ts.p.rowList[i])?" selected=\"selected\"":"")+">"+ts.p.rowList[i]+"</option>";
  1789. }
  1790. str +="</select></td>";
  1791. }
  1792. if(dir=="rtl") { pgl += str; }
  1793. 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>";}
  1794. if(ts.p.pgbuttons===true) {
  1795. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir=="rtl") { po.reverse(); }
  1796. pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-first'></span></td>";
  1797. pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-prev'></span></td>";
  1798. pgl += pginp !== "" ? sep+pginp+sep:"";
  1799. pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-next'></span></td>";
  1800. pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-end'></span></td>";
  1801. } else if (pginp !== "") { pgl += pginp; }
  1802. if(dir=="ltr") { pgl += str; }
  1803. pgl += "</tr></tbody></table>";
  1804. 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>");}
  1805. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  1806. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  1807. $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  1808. twd = $(pgl).clone().appendTo("#testpg").width();
  1809. $("#testpg").remove();
  1810. if(twd > 0) {
  1811. if(pginp !== "") { twd += 50; } //should be param
  1812. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  1813. }
  1814. ts.p._nvtd = [];
  1815. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  1816. ts.p._nvtd[1] = 0;
  1817. pgl=null;
  1818. $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
  1819. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  1820. ts.p.rowNum = this.value;
  1821. if(tp) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  1822. else if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  1823. if(!clearVals('records')) { return false; }
  1824. populate();
  1825. return false;
  1826. });
  1827. if(ts.p.pgbuttons===true) {
  1828. $(".ui-pg-button","#"+pgcnt).hover(function(e){
  1829. if($(this).hasClass('ui-state-disabled')) {
  1830. this.style.cursor='default';
  1831. } else {
  1832. $(this).addClass('ui-state-hover');
  1833. this.style.cursor='pointer';
  1834. }
  1835. },function(e) {
  1836. if($(this).hasClass('ui-state-disabled')) {
  1837. } else {
  1838. $(this).removeClass('ui-state-hover');
  1839. this.style.cursor= "default";
  1840. }
  1841. });
  1842. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function(e) {
  1843. var cp = intNum(ts.p.page,1),
  1844. last = intNum(ts.p.lastpage,1), selclick = false,
  1845. fp=true, pp=true, np=true,lp=true;
  1846. if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
  1847. else if( last>1 && cp >=1) {
  1848. if( cp === 1) { fp=false; pp=false; }
  1849. else if( cp>1 && cp <last){ }
  1850. else if( cp===last){ np=false;lp=false; }
  1851. } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
  1852. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  1853. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  1854. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  1855. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  1856. if(selclick) {
  1857. if(!clearVals(this.id)) { return false; }
  1858. populate();
  1859. }
  1860. return false;
  1861. });
  1862. }
  1863. if(ts.p.pginput===true) {
  1864. $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
  1865. var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
  1866. if(key == 13) {
  1867. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  1868. if(!clearVals('user')) { return false; }
  1869. populate();
  1870. return false;
  1871. }
  1872. return this;
  1873. });
  1874. }
  1875. },
  1876. sortData = function (index, idxcol,reload,sor){
  1877. if(!ts.p.colModel[idxcol].sortable) { return; }
  1878. var so;
  1879. if(ts.p.savedRow.length > 0) {return;}
  1880. if(!reload) {
  1881. if( ts.p.lastsort == idxcol ) {
  1882. if( ts.p.sortorder == 'asc') {
  1883. ts.p.sortorder = 'desc';
  1884. } else if(ts.p.sortorder == 'desc') { ts.p.sortorder = 'asc';}
  1885. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  1886. ts.p.page = 1;
  1887. }
  1888. if(sor) {
  1889. if(ts.p.lastsort == idxcol && ts.p.sortorder == sor && !reload) { return; }
  1890. else { ts.p.sortorder = sor; }
  1891. }
  1892. var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.grid.headers[idxcol].el;
  1893. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  1894. $(previousSelectedTh).attr("aria-selected","false");
  1895. $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  1896. $(newSelectedTh).attr("aria-selected","true");
  1897. if(!ts.p.viewsortcols[0]) {
  1898. if(ts.p.lastsort != idxcol) {
  1899. $("span.s-ico",previousSelectedTh).hide();
  1900. $("span.s-ico",newSelectedTh).show();
  1901. }
  1902. }
  1903. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  1904. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  1905. so = ts.p.sortorder;
  1906. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts,index,idxcol,so)=='stop') {ts.p.lastsort = idxcol; return;}}
  1907. if(ts.p.datatype == "local") {
  1908. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  1909. } else {
  1910. ts.p.selrow = null;
  1911. if(ts.p.multiselect){$("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);}
  1912. ts.p.selarrrow =[];
  1913. ts.p.savedRow =[];
  1914. }
  1915. if(ts.p.scroll) {
  1916. var sscroll = ts.grid.bDiv.scrollLeft;
  1917. emptyRows(ts.grid.bDiv,true, false);
  1918. ts.grid.hDiv.scrollLeft = sscroll;
  1919. }
  1920. if(ts.p.subGrid && ts.p.datatype=='local') {
  1921. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  1922. $(this).trigger("click");
  1923. });
  1924. }
  1925. populate();
  1926. ts.p.lastsort = idxcol;
  1927. if(ts.p.sortname != index && idxcol) {ts.p.lastsort = idxcol;}
  1928. },
  1929. setColWidth = function () {
  1930. var initwidth = 0, brd=isSafari? 0: ts.p.cellLayout, vc=0, lvc, scw=ts.p.scrollOffset,cw,hs=false,aw,gw=0,
  1931. cl = 0, cr;
  1932. $.each(ts.p.colModel, function(i) {
  1933. if(typeof this.hidden === 'undefined') {this.hidden=false;}
  1934. this.widthOrg = cw = intNum(this.width,0);
  1935. if(this.hidden===false){
  1936. initwidth += cw+brd;
  1937. if(this.fixed) {
  1938. gw += cw+brd;
  1939. } else {
  1940. vc++;
  1941. }
  1942. cl++;
  1943. }
  1944. });
  1945. if(isNaN(ts.p.width)) {ts.p.width = grid.width = initwidth;}
  1946. else { grid.width = ts.p.width;}
  1947. ts.p.tblwidth = initwidth;
  1948. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  1949. if(ts.p.shrinkToFit===true && vc > 0) {
  1950. aw = grid.width-brd*vc-gw;
  1951. if(isNaN(ts.p.height)) {
  1952. } else {
  1953. aw -= scw;
  1954. hs = true;
  1955. }
  1956. initwidth =0;
  1957. $.each(ts.p.colModel, function(i) {
  1958. if(this.hidden === false && !this.fixed){
  1959. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  1960. this.width =cw;
  1961. initwidth += cw;
  1962. lvc = i;
  1963. }
  1964. });
  1965. cr =0;
  1966. if (hs) {
  1967. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  1968. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  1969. }
  1970. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  1971. cr = grid.width-gw-(initwidth+brd*vc);
  1972. }
  1973. ts.p.colModel[lvc].width += cr;
  1974. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  1975. if(ts.p.tblwidth > ts.p.width) {
  1976. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  1977. ts.p.tblwidth = ts.p.width;
  1978. }
  1979. }
  1980. },
  1981. nextVisible= function(iCol) {
  1982. var ret = iCol, j=iCol, i;
  1983. for (i = iCol+1;i<ts.p.colModel.length;i++){
  1984. if(ts.p.colModel[i].hidden !== true ) {
  1985. j=i; break;
  1986. }
  1987. }
  1988. return j-ret;
  1989. },
  1990. getOffset = function (iCol) {
  1991. var i, ret = {}, brd1 = isSafari ? 0 : ts.p.cellLayout;
  1992. ret[0] = ret[1] = ret[2] = 0;
  1993. for(i=0;i<=iCol;i++){
  1994. if(ts.p.colModel[i].hidden === false ) {
  1995. ret[0] += ts.p.colModel[i].width+brd1;
  1996. }
  1997. }
  1998. if(ts.p.direction=="rtl") { ret[0] = ts.p.width - ret[0]; }
  1999. ret[0] = ret[0] - ts.grid.bDiv.scrollLeft;
  2000. if($(ts.grid.cDiv).is(":visible")) {ret[1] += $(ts.grid.cDiv).height() +parseInt($(ts.grid.cDiv).css("padding-top"),10)+parseInt($(ts.grid.cDiv).css("padding-bottom"),10);}
  2001. if(ts.p.toolbar[0]===true && (ts.p.toolbar[1]=='top' || ts.p.toolbar[1]=='both')) {ret[1] += $(ts.grid.uDiv).height()+parseInt($(ts.grid.uDiv).css("border-top-width"),10)+parseInt($(ts.grid.uDiv).css("border-bottom-width"),10);}
  2002. if(ts.p.toppager) {ret[1] += $(ts.grid.topDiv).height()+parseInt($(ts.grid.topDiv).css("border-bottom-width"),10);}
  2003. ret[2] += $(ts.grid.bDiv).height() + $(ts.grid.hDiv).height();
  2004. return ret;
  2005. },
  2006. getColumnHeaderIndex = function (th) {
  2007. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  2008. for (i = 0; i < headers.length; i++) {
  2009. if (th === headers[i].el) {
  2010. ci = i;
  2011. break;
  2012. }
  2013. }
  2014. return ci;
  2015. };
  2016. this.p.id = this.id;
  2017. if ($.inArray(ts.p.multikey,sortkeys) == -1 ) {ts.p.multikey = false;}
  2018. ts.p.keyIndex=false;
  2019. for (i=0; i<ts.p.colModel.length;i++) {
  2020. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, ts.p.colModel[i].template || {}, ts.p.colModel[i]);
  2021. if (ts.p.keyIndex === false && ts.p.colModel[i].key===true) {
  2022. ts.p.keyIndex = i;
  2023. }
  2024. }
  2025. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  2026. if(ts.p.grouping===true) {
  2027. ts.p.scroll = false;
  2028. ts.p.rownumbers = false;
  2029. ts.p.subGrid = false;
  2030. ts.p.treeGrid = false;
  2031. ts.p.gridview = true;
  2032. }
  2033. if(this.p.treeGrid === true) {
  2034. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  2035. if(ts.p.datatype != "local") { ts.p.localReader = {id: "_id_"}; }
  2036. }
  2037. if(this.p.subGrid) {
  2038. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  2039. }
  2040. if(this.p.multiselect) {
  2041. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  2042. this.p.colModel.unshift({name:'cb',width:isSafari ? ts.p.multiselectWidth+ts.p.cellLayout : ts.p.multiselectWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2043. }
  2044. if(this.p.rownumbers) {
  2045. this.p.colNames.unshift("");
  2046. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2047. }
  2048. ts.p.xmlReader = $.extend(true,{
  2049. root: "rows",
  2050. row: "row",
  2051. page: "rows>page",
  2052. total: "rows>total",
  2053. records : "rows>records",
  2054. repeatitems: true,
  2055. cell: "cell",
  2056. id: "[id]",
  2057. userdata: "userdata",
  2058. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  2059. }, ts.p.xmlReader);
  2060. ts.p.jsonReader = $.extend(true,{
  2061. root: "rows",
  2062. page: "page",
  2063. total: "total",
  2064. records: "records",
  2065. repeatitems: true,
  2066. cell: "cell",
  2067. id: "id",
  2068. userdata: "userdata",
  2069. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2070. },ts.p.jsonReader);
  2071. ts.p.localReader = $.extend(true,{
  2072. root: "rows",
  2073. page: "page",
  2074. total: "total",
  2075. records: "records",
  2076. repeatitems: false,
  2077. cell: "cell",
  2078. id: "id",
  2079. userdata: "userdata",
  2080. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2081. },ts.p.localReader);
  2082. if(ts.p.scroll){
  2083. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  2084. }
  2085. if(ts.p.data.length) { refreshIndex(); }
  2086. var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>",
  2087. tdc, idn, w, res, sort,
  2088. td, ptr, tbody, imgs,iac="",idc="";
  2089. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  2090. for (i=ts.p.colModel.length-1;i>=0;i--){
  2091. if(!ts.p.colModel[i].hidden) {
  2092. ts.p.colModel[i].resizable=false;
  2093. break;
  2094. }
  2095. }
  2096. }
  2097. if(ts.p.viewsortcols[1] == 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
  2098. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  2099. 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>";
  2100. 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>";
  2101. for(i=0;i<this.p.colNames.length;i++){
  2102. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  2103. thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
  2104. idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
  2105. thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
  2106. if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
  2107. else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
  2108. if(typeof(ts.p.colModel[i].title) !== "boolean") { ts.p.colModel[i].title = true; }
  2109. if (idn == ts.p.sortname) {
  2110. ts.p.lastsort = i;
  2111. }
  2112. thead += imgs+"</div></th>";
  2113. }
  2114. thead += "</tr></thead>";
  2115. imgs = null;
  2116. $(this).append(thead);
  2117. $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  2118. if(this.p.multiselect) {
  2119. var emp=[], chk;
  2120. $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
  2121. ts.p.selarrrow = [];
  2122. if (this.checked) {
  2123. $(ts.rows).each(function(i) {
  2124. if (i>0) {
  2125. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){
  2126. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2127. $(this).addClass("ui-state-highlight").attr("aria-selected","true");
  2128. ts.p.selarrrow.push(this.id);
  2129. ts.p.selrow = this.id;
  2130. }
  2131. }
  2132. });
  2133. chk=true;
  2134. emp=[];
  2135. }
  2136. else {
  2137. $(ts.rows).each(function(i) {
  2138. if(i>0) {
  2139. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass('ui-state-disabled')){
  2140. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2141. $(this).removeClass("ui-state-highlight").attr("aria-selected","false");
  2142. emp.push(this.id);
  2143. }
  2144. }
  2145. });
  2146. ts.p.selrow = null;
  2147. chk=false;
  2148. }
  2149. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  2150. });
  2151. }
  2152. if(ts.p.autowidth===true) {
  2153. var pw = $(eg).innerWidth();
  2154. ts.p.width = pw > 0? pw: 'nw';
  2155. }
  2156. setColWidth();
  2157. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  2158. $(gv).css("width",grid.width+"px");
  2159. thead = $("thead:first",ts).get(0);
  2160. var tfoot = "";
  2161. 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+"'>"; }
  2162. var thr = $("tr:first",thead),
  2163. firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
  2164. ts.p.disableClick=false;
  2165. $("th",thr).each(function ( j ) {
  2166. w = ts.p.colModel[j].width;
  2167. if(typeof ts.p.colModel[j].resizable === 'undefined') {ts.p.colModel[j].resizable = true;}
  2168. if(ts.p.colModel[j].resizable){
  2169. res = document.createElement("span");
  2170. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir);
  2171. if(!$.browser.opera) { $(res).css("cursor","col-resize"); }
  2172. $(this).addClass(ts.p.resizeclass);
  2173. } else {
  2174. res = "";
  2175. }
  2176. $(this).css("width",w+"px").prepend(res);
  2177. var hdcol = "";
  2178. if( ts.p.colModel[j].hidden ) {
  2179. $(this).css("display","none");
  2180. hdcol = "display:none;";
  2181. }
  2182. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  2183. grid.headers[j] = { width: w, el: this };
  2184. sort = ts.p.colModel[j].sortable;
  2185. if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
  2186. var nm = ts.p.colModel[j].name;
  2187. if( !(nm == 'cb' || nm=='subgrid' || nm=='rn') ) {
  2188. if(ts.p.viewsortcols[2]){
  2189. $("div",this).addClass('ui-jqgrid-sortable');
  2190. }
  2191. }
  2192. if(sort) {
  2193. 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");}}
  2194. else if( j == ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
  2195. }
  2196. if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>"; }
  2197. }).mousedown(function(e) {
  2198. if ($(e.target).closest("th>span.ui-jqgrid-resize").length != 1) { return; }
  2199. var ci = getColumnHeaderIndex(this);
  2200. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  2201. grid.dragStart(ci, e, getOffset(ci));
  2202. return false;
  2203. }).click(function(e) {
  2204. if (ts.p.disableClick) {
  2205. ts.p.disableClick = false;
  2206. return false;
  2207. }
  2208. var s = "th>div.ui-jqgrid-sortable",r,d;
  2209. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  2210. var t = $(e.target).closest(s);
  2211. if (t.length != 1) { return; }
  2212. var ci = getColumnHeaderIndex(this);
  2213. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  2214. sortData( $('div',this)[0].id, ci, r, d);
  2215. return false;
  2216. });
  2217. if (ts.p.sortable && $.fn.sortable) {
  2218. try {
  2219. $(ts).jqGrid("sortableColumns", thr);
  2220. } catch (e){}
  2221. }
  2222. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  2223. firstr += "</tr>";
  2224. tbody = document.createElement("tbody");
  2225. this.appendChild(tbody);
  2226. $(this).addClass('ui-jqgrid-btable').append(firstr);
  2227. firstr = null;
  2228. 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),
  2229. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  2230. hb = $("<div class='ui-jqgrid-hbox" + (dir=="rtl" ? "-rtl" : "" )+"'></div>");
  2231. thead = null;
  2232. grid.hDiv = document.createElement("div");
  2233. $(grid.hDiv)
  2234. .css({ width: grid.width+"px"})
  2235. .addClass("ui-state-default ui-jqgrid-hdiv")
  2236. .append(hb);
  2237. $(hb).append(hTable);
  2238. hTable = null;
  2239. if(hg) { $(grid.hDiv).hide(); }
  2240. if(ts.p.pager){
  2241. // TBD -- escape ts.p.pager here?
  2242. if(typeof ts.p.pager == "string") {if(ts.p.pager.substr(0,1) !="#") { ts.p.pager = "#"+ts.p.pager;} }
  2243. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  2244. $(ts.p.pager).css({width: grid.width+"px"}).appendTo(eg).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom');
  2245. if(hg) {$(ts.p.pager).hide();}
  2246. setPager(ts.p.pager,'');
  2247. }
  2248. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  2249. $(ts).bind('mouseover',function(e) {
  2250. ptr = $(e.target).closest("tr.jqgrow");
  2251. if($(ptr).attr("class") !== "ui-subgrid") {
  2252. $(ptr).addClass("ui-state-hover");
  2253. }
  2254. }).bind('mouseout',function(e) {
  2255. ptr = $(e.target).closest("tr.jqgrow");
  2256. $(ptr).removeClass("ui-state-hover");
  2257. });
  2258. }
  2259. var ri,ci;
  2260. $(ts).before(grid.hDiv).click(function(e) {
  2261. td = e.target;
  2262. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2263. if($(ptr).length === 0 || ptr[0].className.indexOf( 'ui-state-disabled' ) > -1 ) {
  2264. return this;
  2265. }
  2266. var scb = $(td).hasClass("cbox"),
  2267. cSel = true;
  2268. if($.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); }
  2269. if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT' ) && !scb) ) { return this; }
  2270. if(cSel === true) {
  2271. if(ts.p.cellEdit === true) {
  2272. if(ts.p.multiselect && scb){
  2273. $(ts).jqGrid("setSelection",ptr[0].id,true);
  2274. } else {
  2275. ri = ptr[0].rowIndex;
  2276. ci = $.jgrid.getCellIndex(td);
  2277. try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
  2278. }
  2279. } else if ( !ts.p.multikey ) {
  2280. if(ts.p.multiselect && ts.p.multiboxonly) {
  2281. if(scb){$(ts).jqGrid("setSelection",ptr[0].id,true);}
  2282. else {
  2283. $(ts.p.selarrrow).each(function(i,n){
  2284. var ind = ts.rows.namedItem(n);
  2285. $(ind).removeClass("ui-state-highlight");
  2286. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2287. });
  2288. ts.p.selarrrow = [];
  2289. $("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2290. $(ts).jqGrid("setSelection",ptr[0].id,true);
  2291. }
  2292. } else {
  2293. $(ts).jqGrid("setSelection",ptr[0].id,true);
  2294. }
  2295. } else {
  2296. if(e[ts.p.multikey]) {
  2297. $(ts).jqGrid("setSelection",ptr[0].id,true);
  2298. } else if(ts.p.multiselect && scb) {
  2299. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id).is(":checked");
  2300. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
  2301. }
  2302. }
  2303. if($.isFunction(ts.p.onCellSelect)) {
  2304. ri = ptr[0].id;
  2305. ci = $.jgrid.getCellIndex(td);
  2306. ts.p.onCellSelect.call(ts,ri,ci,$(td).html(),e);
  2307. }
  2308. //e.stopPropagation();
  2309. }
  2310. //else {
  2311. return this;
  2312. //}
  2313. }).bind('reloadGrid', function(e,opts) {
  2314. if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
  2315. if (opts && opts.current) {
  2316. ts.grid.selectionPreserver(ts);
  2317. }
  2318. if(ts.p.datatype=="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} }
  2319. else if(!ts.p.treeGrid) {
  2320. ts.p.selrow=null;
  2321. if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", false);}
  2322. ts.p.savedRow = [];
  2323. }
  2324. if(ts.p.scroll) {emptyRows(ts.grid.bDiv,true, false);}
  2325. if (opts && opts.page) {
  2326. var page = opts.page;
  2327. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  2328. if (page < 1) { page = 1; }
  2329. ts.p.page = page;
  2330. if (ts.grid.prevRowHeight) {
  2331. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  2332. } else {
  2333. ts.grid.bDiv.scrollTop = 0;
  2334. }
  2335. }
  2336. if (ts.grid.prevRowHeight && ts.p.scroll) {
  2337. delete ts.p.lastpage;
  2338. ts.grid.populateVisible();
  2339. } else {
  2340. ts.grid.populate();
  2341. }
  2342. return false;
  2343. });
  2344. if( $.isFunction(this.p.ondblClickRow) ) {
  2345. $(this).dblclick(function(e) {
  2346. td = e.target;
  2347. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2348. if($(ptr).length === 0 ){return false;}
  2349. ri = ptr[0].rowIndex;
  2350. ci = $.jgrid.getCellIndex(td);
  2351. ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  2352. return false;
  2353. });
  2354. }
  2355. if ($.isFunction(this.p.onRightClickRow)) {
  2356. $(this).bind('contextmenu', function(e) {
  2357. td = e.target;
  2358. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2359. if($(ptr).length === 0 ){return false;}
  2360. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true); }
  2361. ri = ptr[0].rowIndex;
  2362. ci = $.jgrid.getCellIndex(td);
  2363. ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  2364. return false;
  2365. });
  2366. }
  2367. grid.bDiv = document.createElement("div");
  2368. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  2369. $(grid.bDiv)
  2370. .append($('<div style="position:relative;'+(isMSIE && $.browser.version < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
  2371. .addClass("ui-jqgrid-bdiv")
  2372. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
  2373. .scroll(grid.scrollGrid);
  2374. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  2375. if( isMSIE ) {
  2376. if( $("tbody",this).size() == 2 ) { $("tbody:gt(0)",this).remove();}
  2377. if( ts.p.multikey) {$(grid.bDiv).bind("selectstart",function(){return false;});}
  2378. } else {
  2379. if( ts.p.multikey) {$(grid.bDiv).bind("mousedown",function(){return false;});}
  2380. }
  2381. if(hg) {$(grid.bDiv).hide();}
  2382. grid.cDiv = document.createElement("div");
  2383. var arf = ts.p.hidegrid===true ? $("<a role='link' href='javascript:void(0)'/>").addClass('ui-jqgrid-titlebar-close HeaderButton').hover(
  2384. function(){ arf.addClass('ui-state-hover');},
  2385. function() {arf.removeClass('ui-state-hover');})
  2386. .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir=="rtl"?"left":"right"),"0px") : "";
  2387. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title"+(dir=="rtl" ? "-rtl" :"" )+"'>"+ts.p.caption+"</span>")
  2388. .addClass("ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix");
  2389. $(grid.cDiv).insertBefore(grid.hDiv);
  2390. if( ts.p.toolbar[0] ) {
  2391. grid.uDiv = document.createElement("div");
  2392. if(ts.p.toolbar[1] == "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  2393. else if (ts.p.toolbar[1]=="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  2394. if(ts.p.toolbar[1]=="both") {
  2395. grid.ubDiv = document.createElement("div");
  2396. $(grid.uDiv).insertBefore(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2397. $(grid.ubDiv).insertAfter(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id);
  2398. if(hg) {$(grid.ubDiv).hide();}
  2399. } else {
  2400. $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2401. }
  2402. if(hg) {$(grid.uDiv).hide();}
  2403. }
  2404. if(ts.p.toppager) {
  2405. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  2406. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  2407. ts.p.toppager = "#"+ts.p.toppager;
  2408. $(grid.topDiv).insertBefore(grid.hDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width);
  2409. setPager(ts.p.toppager,'_t');
  2410. }
  2411. if(ts.p.footerrow) {
  2412. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  2413. hb = $("<div class='ui-jqgrid-hbox"+(dir=="rtl"?"-rtl":"")+"'></div>");
  2414. $(grid.sDiv).append(hb).insertAfter(grid.hDiv).width(grid.width);
  2415. $(hb).append(tfoot);
  2416. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  2417. if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
  2418. if(hg) {$(grid.sDiv).hide();}
  2419. }
  2420. hb = null;
  2421. if(ts.p.caption) {
  2422. var tdt = ts.p.datatype;
  2423. if(ts.p.hidegrid===true) {
  2424. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  2425. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  2426. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  2427. counter, self = this;
  2428. if(ts.p.toolbar[0]===true) {
  2429. if( ts.p.toolbar[1]=='both') {
  2430. elems += ', #' + $(grid.ubDiv).attr('id');
  2431. }
  2432. elems += ', #' + $(grid.uDiv).attr('id');
  2433. }
  2434. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  2435. if(ts.p.gridstate == 'visible') {
  2436. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  2437. counter--;
  2438. if (counter === 0) {
  2439. $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  2440. ts.p.gridstate = 'hidden';
  2441. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  2442. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2443. }
  2444. });
  2445. } else if(ts.p.gridstate == 'hidden'){
  2446. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  2447. counter--;
  2448. if (counter === 0) {
  2449. $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  2450. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  2451. ts.p.gridstate = 'visible';
  2452. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  2453. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2454. }
  2455. });
  2456. }
  2457. return false;
  2458. });
  2459. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  2460. }
  2461. } else {$(grid.cDiv).hide();}
  2462. $(grid.hDiv).after(grid.bDiv)
  2463. .mousemove(function (e) {
  2464. if(grid.resizing){grid.dragMove(e);return false;}
  2465. });
  2466. $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
  2467. $(document).mouseup(function (e) {
  2468. if(grid.resizing) { grid.dragEnd(); return false;}
  2469. return true;
  2470. });
  2471. ts.formatCol = formatCol;
  2472. ts.sortData = sortData;
  2473. ts.updatepager = updatepager;
  2474. ts.refreshIndex = refreshIndex;
  2475. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  2476. $.extend(grid,{populate : populate, emptyRows: emptyRows});
  2477. this.grid = grid;
  2478. ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
  2479. ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
  2480. this.grid.cols = this.rows[0].cells;
  2481. populate();ts.p.hiddengrid=false;
  2482. $(window).unload(function () {
  2483. ts = null;
  2484. });
  2485. });
  2486. };
  2487. $.jgrid.extend({
  2488. getGridParam : function(pName) {
  2489. var $t = this[0];
  2490. if (!$t || !$t.grid) {return;}
  2491. if (!pName) { return $t.p; }
  2492. else {return typeof($t.p[pName]) != "undefined" ? $t.p[pName] : null;}
  2493. },
  2494. setGridParam : function (newParams){
  2495. return this.each(function(){
  2496. if (this.grid && typeof(newParams) === 'object') {$.extend(true,this.p,newParams);}
  2497. });
  2498. },
  2499. getDataIDs : function () {
  2500. var ids=[], i=0, len, j=0;
  2501. this.each(function(){
  2502. len = this.rows.length;
  2503. if(len && len>0){
  2504. while(i<len) {
  2505. if($(this.rows[i]).hasClass('jqgrow')) {
  2506. ids[j] = this.rows[i].id;
  2507. j++;
  2508. }
  2509. i++;
  2510. }
  2511. }
  2512. });
  2513. return ids;
  2514. },
  2515. setSelection : function(selection,onsr) {
  2516. return this.each(function(){
  2517. var $t = this, stat,pt, ner, ia, tpsr;
  2518. if(selection === undefined) { return; }
  2519. onsr = onsr === false ? false : true;
  2520. pt=$t.rows.namedItem(selection+"");
  2521. if(!pt || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }
  2522. function scrGrid(iR){
  2523. var ch = $($t.grid.bDiv)[0].clientHeight,
  2524. st = $($t.grid.bDiv)[0].scrollTop,
  2525. rpos = $t.rows[iR].offsetTop,
  2526. rh = $t.rows[iR].clientHeight;
  2527. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  2528. else if(rpos < ch+st) {
  2529. if(rpos < st) {
  2530. $($t.grid.bDiv)[0].scrollTop = rpos;
  2531. }
  2532. }
  2533. }
  2534. if($t.p.scrollrows===true) {
  2535. ner = $t.rows.namedItem(selection).rowIndex;
  2536. if(ner >=0 ){
  2537. scrGrid(ner);
  2538. }
  2539. }
  2540. if(!$t.p.multiselect) {
  2541. if(pt.className !== "ui-subgrid") {
  2542. if( $t.p.selrow != pt.id) {
  2543. $($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
  2544. $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  2545. stat = true;
  2546. } else {
  2547. stat = false;
  2548. }
  2549. $t.p.selrow = pt.id;
  2550. if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t, pt.id, stat); }
  2551. }
  2552. } else {
  2553. //unselect selectall checkbox when deselecting a specific row
  2554. $("#cb_" + $.jgrid.jqID($t.p.id), $t.grid.hDiv)[$t.p.useProp ? 'prop' : 'attr']("checked", false);
  2555. $t.p.selrow = pt.id;
  2556. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  2557. if ( ia === -1 ){
  2558. if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
  2559. stat = true;
  2560. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID($t.p.selrow))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  2561. $t.p.selarrrow.push($t.p.selrow);
  2562. } else {
  2563. if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
  2564. stat = false;
  2565. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID($t.p.selrow))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  2566. $t.p.selarrrow.splice(ia,1);
  2567. tpsr = $t.p.selarrrow[0];
  2568. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  2569. }
  2570. if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t, pt.id , stat); }
  2571. }
  2572. });
  2573. },
  2574. resetSelection : function( rowid ){
  2575. return this.each(function(){
  2576. var t = this, ind, sr;
  2577. if(typeof(rowid) !== "undefined" ) {
  2578. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  2579. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
  2580. if(t.p.multiselect) {
  2581. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2582. $("#cb_"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false );
  2583. }
  2584. sr = null;
  2585. } else if(!t.p.multiselect) {
  2586. if(t.p.selrow) {
  2587. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
  2588. t.p.selrow = null;
  2589. }
  2590. } else {
  2591. $(t.p.selarrrow).each(function(i,n){
  2592. ind = t.rows.namedItem(n);
  2593. $(ind).removeClass("ui-state-highlight").attr("aria-selected","false");
  2594. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2595. });
  2596. $("#cb_"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2597. t.p.selarrrow = [];
  2598. }
  2599. if(t.p.cellEdit === true) {
  2600. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  2601. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  2602. $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover");
  2603. }
  2604. }
  2605. t.p.savedRow = [];
  2606. });
  2607. },
  2608. getRowData : function( rowid ) {
  2609. var res = {}, resall, getall=false, len, j=0;
  2610. this.each(function(){
  2611. var $t = this,nm,ind;
  2612. if(typeof(rowid) == 'undefined') {
  2613. getall = true;
  2614. resall = [];
  2615. len = $t.rows.length;
  2616. } else {
  2617. ind = $t.rows.namedItem(rowid);
  2618. if(!ind) { return res; }
  2619. len = 2;
  2620. }
  2621. while(j<len){
  2622. if(getall) { ind = $t.rows[j]; }
  2623. if( $(ind).hasClass('jqgrow') ) {
  2624. $('td',ind).each( function(i) {
  2625. nm = $t.p.colModel[i].name;
  2626. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  2627. if($t.p.treeGrid===true && nm == $t.p.ExpandColumn) {
  2628. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  2629. } else {
  2630. try {
  2631. res[nm] = $.unformat(this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  2632. } catch (e){
  2633. res[nm] = $.jgrid.htmlDecode($(this).html());
  2634. }
  2635. }
  2636. }
  2637. });
  2638. if(getall) { resall.push(res); res={}; }
  2639. }
  2640. j++;
  2641. }
  2642. });
  2643. return resall ? resall: res;
  2644. },
  2645. delRowData : function(rowid) {
  2646. var success = false, rowInd, ia, ri;
  2647. this.each(function() {
  2648. var $t = this;
  2649. rowInd = $t.rows.namedItem(rowid);
  2650. if(!rowInd) {return false;}
  2651. else {
  2652. ri = rowInd.rowIndex;
  2653. $(rowInd).remove();
  2654. $t.p.records--;
  2655. $t.p.reccount--;
  2656. $t.updatepager(true,false);
  2657. success=true;
  2658. if($t.p.multiselect) {
  2659. ia = $.inArray(rowid,$t.p.selarrrow);
  2660. if(ia != -1) { $t.p.selarrrow.splice(ia,1);}
  2661. }
  2662. if(rowid == $t.p.selrow) {$t.p.selrow=null;}
  2663. }
  2664. if($t.p.datatype == 'local') {
  2665. var pos = $t.p._index[rowid];
  2666. if(typeof(pos) != 'undefined') {
  2667. $t.p.data.splice(pos,1);
  2668. $t.refreshIndex();
  2669. }
  2670. }
  2671. if( $t.p.altRows === true && success ) {
  2672. var cn = $t.p.altclass;
  2673. $($t.rows).each(function(i){
  2674. if(i % 2 ==1) { $(this).addClass(cn); }
  2675. else { $(this).removeClass(cn); }
  2676. });
  2677. }
  2678. });
  2679. return success;
  2680. },
  2681. setRowData : function(rowid, data, cssp) {
  2682. var nm, success=true, title;
  2683. this.each(function(){
  2684. if(!this.grid) {return false;}
  2685. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  2686. ind = t.rows.namedItem(rowid);
  2687. if(!ind) { return false; }
  2688. if( data ) {
  2689. try {
  2690. $(this.p.colModel).each(function(i){
  2691. nm = this.name;
  2692. if( data[nm] !== undefined) {
  2693. lcdata[nm] = this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date' ? $.unformat.date(data[nm],this) : data[nm];
  2694. vl = t.formatter( rowid, data[nm], i, data, 'edit');
  2695. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  2696. if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
  2697. $("td:eq("+i+") > span:first",ind).html(vl).attr(title);
  2698. } else {
  2699. $("td:eq("+i+")",ind).html(vl).attr(title);
  2700. }
  2701. }
  2702. });
  2703. if(t.p.datatype == 'local') {
  2704. var pos = t.p._index[rowid];
  2705. if(t.p.treeGrid) {
  2706. for(var key in t.p.treeReader ){
  2707. if(lcdata.hasOwnProperty(t.p.treeReader[key])) {
  2708. delete lcdata[t.p.treeReader[key]];
  2709. }
  2710. }
  2711. }
  2712. if(typeof(pos) != 'undefined') {
  2713. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  2714. }
  2715. lcdata = null;
  2716. }
  2717. } catch (e) {
  2718. success = false;
  2719. }
  2720. }
  2721. if(success) {
  2722. if(cp === 'string') {$(ind).addClass(cssp);} else if(cp === 'object') {$(ind).css(cssp);}
  2723. }
  2724. });
  2725. return success;
  2726. },
  2727. addRowData : function(rowid,rdata,pos,src) {
  2728. if(!pos) {pos = "last";}
  2729. var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm;
  2730. if(rdata) {
  2731. if($.isArray(rdata)) {
  2732. aradd=true;
  2733. pos = "last";
  2734. cnm = rowid;
  2735. } else {
  2736. rdata = [rdata];
  2737. aradd = false;
  2738. }
  2739. this.each(function() {
  2740. var t = this, datalen = rdata.length;
  2741. ni = t.p.rownumbers===true ? 1 :0;
  2742. gi = t.p.multiselect ===true ? 1 :0;
  2743. si = t.p.subGrid===true ? 1 :0;
  2744. if(!aradd) {
  2745. if(typeof(rowid) != 'undefined') { rowid = rowid+"";}
  2746. else {
  2747. rowid = $.jgrid.randId();
  2748. if(t.p.keyIndex !== false) {
  2749. cnm = t.p.colModel[t.p.keyIndex+gi+si+ni].name;
  2750. if(typeof rdata[0][cnm] != "undefined") { rowid = rdata[0][cnm]; }
  2751. }
  2752. }
  2753. }
  2754. cn = t.p.altclass;
  2755. var k = 0, cna ="", lcdata = {},
  2756. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  2757. while(k < datalen) {
  2758. data = rdata[k];
  2759. row="";
  2760. if(aradd) {
  2761. try {rowid = data[cnm];}
  2762. catch (e) {rowid = $.jgrid.randId();}
  2763. cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
  2764. }
  2765. rowid = t.p.idPrefix + rowid;
  2766. if(ni){
  2767. prp = t.formatCol(0,1,'',null,rowid, true);
  2768. row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_rn\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
  2769. }
  2770. if(gi) {
  2771. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>";
  2772. prp = t.formatCol(ni,1,'', null, rowid, true);
  2773. row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_cb\" "+prp+">"+v+"</td>";
  2774. }
  2775. if(si) {
  2776. row += $(t).jqGrid("addSubGridCell",gi+ni,1);
  2777. }
  2778. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  2779. cm = t.p.colModel[i];
  2780. nm = cm.name;
  2781. lcdata[nm] = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(data[nm],cm) : data[nm];
  2782. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data, 'edit');
  2783. prp = t.formatCol(i,1,v, data, rowid, true);
  2784. row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_"+nm+"\" "+prp+">"+v+"</td>";
  2785. }
  2786. row = "<tr id=\""+rowid+"\" role=\"row\" tabindex=\"-1\" class=\"ui-widget-content jqgrow ui-row-"+t.p.direction+" "+cna+"\">" + row+"</tr>";
  2787. if(t.rows.length === 0){
  2788. $("table:first",t.grid.bDiv).append(row);
  2789. } else {
  2790. switch (pos) {
  2791. case 'last':
  2792. $(t.rows[t.rows.length-1]).after(row);
  2793. sind = t.rows.length-1;
  2794. break;
  2795. case 'first':
  2796. $(t.rows[0]).after(row);
  2797. sind = 1;
  2798. break;
  2799. case 'after':
  2800. sind = t.rows.namedItem(src);
  2801. if (sind) {
  2802. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  2803. else { $(sind).after(row); }
  2804. }
  2805. sind++;
  2806. break;
  2807. case 'before':
  2808. sind = t.rows.namedItem(src);
  2809. if(sind) {$(sind).before(row);sind=sind.rowIndex;}
  2810. sind--;
  2811. break;
  2812. }
  2813. }
  2814. if(t.p.subGrid===true) {
  2815. $(t).jqGrid("addSubGrid",gi+ni, sind);
  2816. }
  2817. t.p.records++;
  2818. t.p.reccount++;
  2819. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  2820. k++;
  2821. if(t.p.datatype == 'local') {
  2822. lcdata[t.p.localReader.id] = rowid;
  2823. t.p._index[rowid] = t.p.data.length;
  2824. t.p.data.push(lcdata);
  2825. lcdata = {};
  2826. }
  2827. }
  2828. if( t.p.altRows === true && !aradd) {
  2829. if (pos == "last") {
  2830. if ((t.rows.length-1)%2 == 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
  2831. } else {
  2832. $(t.rows).each(function(i){
  2833. if(i % 2 ==1) { $(this).addClass(cn); }
  2834. else { $(this).removeClass(cn); }
  2835. });
  2836. }
  2837. }
  2838. t.updatepager(true,true);
  2839. success = true;
  2840. });
  2841. }
  2842. return success;
  2843. },
  2844. footerData : function(action,data, format) {
  2845. var nm, success=false, res={}, title;
  2846. function isEmpty(obj) {
  2847. for(var i in obj) {
  2848. if (obj.hasOwnProperty(i)) { return false; }
  2849. }
  2850. return true;
  2851. }
  2852. if(typeof(action) == "undefined") { action = "get"; }
  2853. if(typeof(format) != "boolean") { format = true; }
  2854. action = action.toLowerCase();
  2855. this.each(function(){
  2856. var t = this, vl;
  2857. if(!t.grid || !t.p.footerrow) {return false;}
  2858. if(action == "set") { if(isEmpty(data)) { return false; } }
  2859. success=true;
  2860. $(this.p.colModel).each(function(i){
  2861. nm = this.name;
  2862. if(action == "set") {
  2863. if( data[nm] !== undefined) {
  2864. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  2865. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  2866. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  2867. success = true;
  2868. }
  2869. } else if(action == "get") {
  2870. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  2871. }
  2872. });
  2873. });
  2874. return action == "get" ? res : success;
  2875. },
  2876. showHideCol : function(colname,show) {
  2877. return this.each(function() {
  2878. var $t = this, fndh=false, brd=$.browser.webkit||$.browser.safari? 0: $t.p.cellLayout, cw;
  2879. if (!$t.grid ) {return;}
  2880. if( typeof colname === 'string') {colname=[colname];}
  2881. show = show != "none" ? "" : "none";
  2882. var sw = show === "" ? true :false,
  2883. gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) );
  2884. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  2885. $(this.p.colModel).each(function(i) {
  2886. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  2887. $("tr",$t.grid.hDiv).each(function(){
  2888. $(this.cells[i]).css("display", show);
  2889. });
  2890. $($t.rows).each(function(j){
  2891. $(this.cells[i]).css("display", show);
  2892. });
  2893. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  2894. cw = this.widthOrg? this.widthOrg: parseInt(this.width,10);
  2895. if(show === "none") {$t.p.tblwidth -= cw+brd;} else {$t.p.tblwidth += cw+brd;}
  2896. this.hidden = !sw;
  2897. fndh=true;
  2898. }
  2899. });
  2900. if(fndh===true) {
  2901. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  2902. }
  2903. if( gh ) {
  2904. $($t).jqGrid('setGroupHeaders',$t.p.groupHeader);
  2905. }
  2906. });
  2907. },
  2908. hideCol : function (colname) {
  2909. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  2910. },
  2911. showCol : function(colname) {
  2912. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  2913. },
  2914. remapColumns : function(permutation, updateCells, keepHeader)
  2915. {
  2916. function resortArray(a) {
  2917. var ac;
  2918. if (a.length) {
  2919. ac = $.makeArray(a);
  2920. } else {
  2921. ac = $.extend({}, a);
  2922. }
  2923. $.each(permutation, function(i) {
  2924. a[i] = ac[this];
  2925. });
  2926. }
  2927. var ts = this.get(0);
  2928. function resortRows(parent, clobj) {
  2929. $(">tr"+(clobj||""), parent).each(function() {
  2930. var row = this;
  2931. var elems = $.makeArray(row.cells);
  2932. $.each(permutation, function() {
  2933. var e = elems[this];
  2934. if (e) {
  2935. row.appendChild(e);
  2936. }
  2937. });
  2938. });
  2939. }
  2940. resortArray(ts.p.colModel);
  2941. resortArray(ts.p.colNames);
  2942. resortArray(ts.grid.headers);
  2943. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  2944. if (updateCells) {
  2945. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  2946. }
  2947. if (ts.p.footerrow) {
  2948. resortRows($("tbody:first", ts.grid.sDiv));
  2949. }
  2950. if (ts.p.remapColumns) {
  2951. if (!ts.p.remapColumns.length){
  2952. ts.p.remapColumns = $.makeArray(permutation);
  2953. } else {
  2954. resortArray(ts.p.remapColumns);
  2955. }
  2956. }
  2957. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  2958. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  2959. },
  2960. setGridWidth : function(nwidth, shrink) {
  2961. return this.each(function(){
  2962. if (!this.grid ) {return;}
  2963. var $t = this, cw,
  2964. initwidth = 0, brd=$.browser.webkit||$.browser.safari? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0,
  2965. cl = 0,cr;
  2966. if(typeof shrink != 'boolean') {
  2967. shrink=$t.p.shrinkToFit;
  2968. }
  2969. if(isNaN(nwidth)) {return;}
  2970. else { nwidth = parseInt(nwidth,10); $t.grid.width = $t.p.width = nwidth;}
  2971. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  2972. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  2973. $($t.grid.bDiv).css("width",nwidth+"px");
  2974. $($t.grid.hDiv).css("width",nwidth+"px");
  2975. if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
  2976. if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
  2977. if($t.p.toolbar[0] === true){
  2978. $($t.grid.uDiv).css("width",nwidth+"px");
  2979. if($t.p.toolbar[1]=="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
  2980. }
  2981. if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
  2982. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  2983. if(shrink===true) {
  2984. $.each($t.p.colModel, function(i) {
  2985. if(this.hidden===false){
  2986. cw = this.widthOrg? this.widthOrg: parseInt(this.width,10);
  2987. initwidth += cw+brd;
  2988. if(this.fixed) {
  2989. gw += cw+brd;
  2990. } else {
  2991. vc++;
  2992. }
  2993. cl++;
  2994. }
  2995. });
  2996. if(vc === 0) { return; }
  2997. $t.p.tblwidth = initwidth;
  2998. aw = nwidth-brd*vc-gw;
  2999. if(!isNaN($t.p.height)) {
  3000. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  3001. hs = true;
  3002. aw -= scw;
  3003. }
  3004. }
  3005. initwidth =0;
  3006. var cle = $t.grid.cols.length >0;
  3007. $.each($t.p.colModel, function(i) {
  3008. if(this.hidden === false && !this.fixed){
  3009. cw = this.widthOrg? this.widthOrg: parseInt(this.width,10);
  3010. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  3011. if (cw < 0) { return; }
  3012. this.width =cw;
  3013. initwidth += cw;
  3014. $t.grid.headers[i].width=cw;
  3015. $t.grid.headers[i].el.style.width=cw+"px";
  3016. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  3017. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  3018. lvc = i;
  3019. }
  3020. });
  3021. if (!lvc) { return; }
  3022. cr =0;
  3023. if (hs) {
  3024. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  3025. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  3026. }
  3027. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  3028. cr = nwidth-gw-(initwidth+brd*vc);
  3029. }
  3030. $t.p.colModel[lvc].width += cr;
  3031. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  3032. if($t.p.tblwidth > nwidth) {
  3033. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  3034. $t.p.tblwidth = nwidth;
  3035. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  3036. } else {
  3037. cw= $t.p.colModel[lvc].width;
  3038. }
  3039. $t.grid.headers[lvc].width = cw;
  3040. $t.grid.headers[lvc].el.style.width=cw+"px";
  3041. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  3042. if($t.p.footerrow) {
  3043. $t.grid.footers[lvc].style.width = cw+"px";
  3044. }
  3045. }
  3046. if($t.p.tblwidth) {
  3047. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  3048. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  3049. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  3050. if($t.p.footerrow) {
  3051. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  3052. }
  3053. }
  3054. });
  3055. },
  3056. setGridHeight : function (nh) {
  3057. return this.each(function (){
  3058. var $t = this;
  3059. if(!$t.grid) {return;}
  3060. $($t.grid.bDiv).css({height: nh+(isNaN(nh)?"":"px")});
  3061. $t.p.height = nh;
  3062. if ($t.p.scroll) { $t.grid.populateVisible(); }
  3063. });
  3064. },
  3065. setCaption : function (newcap){
  3066. return this.each(function(){
  3067. this.p.caption=newcap;
  3068. $("span.ui-jqgrid-title",this.grid.cDiv).html(newcap);
  3069. $(this.grid.cDiv).show();
  3070. });
  3071. },
  3072. setLabel : function(colname, nData, prop, attrp ){
  3073. return this.each(function(){
  3074. var $t = this, pos=-1;
  3075. if(!$t.grid) {return;}
  3076. if(typeof(colname) != "undefined") {
  3077. $($t.p.colModel).each(function(i){
  3078. if (this.name == colname) {
  3079. pos = i;return false;
  3080. }
  3081. });
  3082. } else { return; }
  3083. if(pos>=0) {
  3084. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  3085. if (nData){
  3086. var ico = $(".s-ico",thecol);
  3087. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  3088. $t.p.colNames[pos] = nData;
  3089. }
  3090. if (prop) {
  3091. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  3092. }
  3093. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  3094. }
  3095. });
  3096. },
  3097. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  3098. return this.each(function(){
  3099. var $t = this, pos =-1,v, title;
  3100. if(!$t.grid) {return;}
  3101. if(isNaN(colname)) {
  3102. $($t.p.colModel).each(function(i){
  3103. if (this.name == colname) {
  3104. pos = i;return false;
  3105. }
  3106. });
  3107. } else {pos = parseInt(colname,10);}
  3108. if(pos>=0) {
  3109. var ind = $t.rows.namedItem(rowid);
  3110. if (ind){
  3111. var tcell = $("td:eq("+pos+")",ind);
  3112. if(nData !== "" || forceupd === true) {
  3113. v = $t.formatter(rowid, nData, pos,ind,'edit');
  3114. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  3115. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  3116. $("span",$(tcell)).html(v).attr(title);
  3117. } else {
  3118. $(tcell).html(v).attr(title);
  3119. }
  3120. if($t.p.datatype == "local") {
  3121. var cm = $t.p.colModel[pos], index;
  3122. nData = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(nData,cm) : nData;
  3123. index = $t.p._index[rowid];
  3124. if(typeof index != "undefined") {
  3125. $t.p.data[index][cm.name] = nData;
  3126. }
  3127. }
  3128. }
  3129. if(typeof cssp === 'string'){
  3130. $(tcell).addClass(cssp);
  3131. } else if(cssp) {
  3132. $(tcell).css(cssp);
  3133. }
  3134. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  3135. }
  3136. }
  3137. });
  3138. },
  3139. getCell : function(rowid,col) {
  3140. var ret = false;
  3141. this.each(function(){
  3142. var $t=this, pos=-1;
  3143. if(!$t.grid) {return;}
  3144. if(isNaN(col)) {
  3145. $($t.p.colModel).each(function(i){
  3146. if (this.name === col) {
  3147. pos = i;return false;
  3148. }
  3149. });
  3150. } else {pos = parseInt(col,10);}
  3151. if(pos>=0) {
  3152. var ind = $t.rows.namedItem(rowid);
  3153. if(ind) {
  3154. try {
  3155. ret = $.unformat($("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  3156. } catch (e){
  3157. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  3158. }
  3159. }
  3160. }
  3161. });
  3162. return ret;
  3163. },
  3164. getCol : function (col, obj, mathopr) {
  3165. var ret = [], val, sum=0, min=0, max=0, v;
  3166. obj = typeof (obj) != 'boolean' ? false : obj;
  3167. if(typeof mathopr == 'undefined') { mathopr = false; }
  3168. this.each(function(){
  3169. var $t=this, pos=-1;
  3170. if(!$t.grid) {return;}
  3171. if(isNaN(col)) {
  3172. $($t.p.colModel).each(function(i){
  3173. if (this.name === col) {
  3174. pos = i;return false;
  3175. }
  3176. });
  3177. } else {pos = parseInt(col,10);}
  3178. if(pos>=0) {
  3179. var ln = $t.rows.length, i =0;
  3180. if (ln && ln>0){
  3181. while(i<ln){
  3182. if($($t.rows[i]).hasClass('jqgrow')) {
  3183. try {
  3184. val = $.unformat($($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  3185. } catch (e) {
  3186. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  3187. }
  3188. if(mathopr) {
  3189. v = parseFloat(val);
  3190. sum += v;
  3191. min = Math.min(min, v);
  3192. max = Math.max(max, v);
  3193. }
  3194. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  3195. else { ret.push( val ); }
  3196. }
  3197. i++;
  3198. }
  3199. if(mathopr) {
  3200. switch(mathopr.toLowerCase()){
  3201. case 'sum': ret =sum; break;
  3202. case 'avg': ret = sum/ln; break;
  3203. case 'count': ret = ln; break;
  3204. case 'min': ret = min; break;
  3205. case 'max': ret = max; break;
  3206. }
  3207. }
  3208. }
  3209. }
  3210. });
  3211. return ret;
  3212. },
  3213. clearGridData : function(clearfooter) {
  3214. return this.each(function(){
  3215. var $t = this;
  3216. if(!$t.grid) {return;}
  3217. if(typeof clearfooter != 'boolean') { clearfooter = false; }
  3218. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  3219. else {
  3220. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  3221. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  3222. }
  3223. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  3224. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  3225. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  3226. $t.p.data = []; $t.p._index = {};
  3227. $t.updatepager(true,false);
  3228. });
  3229. },
  3230. getInd : function(rowid,rc){
  3231. var ret =false,rw;
  3232. this.each(function(){
  3233. rw = this.rows.namedItem(rowid);
  3234. if(rw) {
  3235. ret = rc===true ? rw: rw.rowIndex;
  3236. }
  3237. });
  3238. return ret;
  3239. },
  3240. bindKeys : function( settings ){
  3241. var o = $.extend({
  3242. onEnter: null,
  3243. onSpace: null,
  3244. onLeftKey: null,
  3245. onRightKey: null,
  3246. scrollingRows : true
  3247. },settings || {});
  3248. return this.each(function(){
  3249. var $t = this;
  3250. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  3251. $t.p.scrollrows = o.scrollingRows;
  3252. $($t).keydown(function(event){
  3253. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  3254. expanded = $t.p.treeReader.expanded_field;
  3255. //check for arrow keys
  3256. if(target) {
  3257. mind = $t.p._index[target.id];
  3258. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  3259. // up key
  3260. if(event.keyCode === 38 ){
  3261. r = target.previousSibling;
  3262. id = "";
  3263. if(r) {
  3264. if($(r).is(":hidden")) {
  3265. while(r) {
  3266. r = r.previousSibling;
  3267. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  3268. }
  3269. } else {
  3270. id = r.id;
  3271. }
  3272. }
  3273. $($t).jqGrid('setSelection', id);
  3274. }
  3275. //if key is down arrow
  3276. if(event.keyCode === 40){
  3277. r = target.nextSibling;
  3278. id ="";
  3279. if(r) {
  3280. if($(r).is(":hidden")) {
  3281. while(r) {
  3282. r = r.nextSibling;
  3283. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  3284. }
  3285. } else {
  3286. id = r.id;
  3287. }
  3288. }
  3289. $($t).jqGrid('setSelection', id);
  3290. }
  3291. // left
  3292. if(event.keyCode === 37 ){
  3293. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  3294. $(target).find("div.treeclick").trigger('click');
  3295. }
  3296. if($.isFunction(o.onLeftKey)) {
  3297. o.onLeftKey.call($t, $t.p.selrow);
  3298. }
  3299. }
  3300. // right
  3301. if(event.keyCode === 39 ){
  3302. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  3303. $(target).find("div.treeclick").trigger('click');
  3304. }
  3305. if($.isFunction(o.onRightKey)) {
  3306. o.onRightKey.call($t, $t.p.selrow);
  3307. }
  3308. }
  3309. //return false;
  3310. }
  3311. //check if enter was pressed on a grid or treegrid node
  3312. else if( event.keyCode === 13 ){
  3313. if($.isFunction(o.onEnter)) {
  3314. o.onEnter.call($t, $t.p.selrow);
  3315. }
  3316. //return false;
  3317. } else if(event.keyCode === 32) {
  3318. if($.isFunction(o.onSpace)) {
  3319. o.onSpace.call($t, $t.p.selrow);
  3320. }
  3321. //return false;
  3322. }
  3323. }
  3324. });
  3325. });
  3326. },
  3327. unbindKeys : function(){
  3328. return this.each(function(){
  3329. var $t = this;
  3330. $($t).unbind('keydown');
  3331. });
  3332. },
  3333. getLocalRow : function (rowid) {
  3334. var ret = false, ind;
  3335. this.each(function(){
  3336. if(typeof(rowid) !== "undefined") {
  3337. ind = this.p._index[rowid];
  3338. if(ind >= 0 ) {
  3339. ret = this.p.data[ind];
  3340. }
  3341. }
  3342. });
  3343. return ret;
  3344. }
  3345. });
  3346. })(jQuery);
  3347. (function($){
  3348. /**
  3349. * jqGrid extension for custom methods
  3350. * Tony Tomov tony@trirand.com
  3351. * http://trirand.com/blog/
  3352. *
  3353. * Wildraid wildraid@mail.ru
  3354. * Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com
  3355. * Dual licensed under the MIT and GPL licenses:
  3356. * http://www.opensource.org/licenses/mit-license.php
  3357. * http://www.gnu.org/licenses/gpl-2.0.html
  3358. **/
  3359. /*global jQuery, $ */
  3360. $.jgrid.extend({
  3361. getColProp : function(colname){
  3362. var ret ={}, $t = this[0];
  3363. if ( !$t.grid ) { return false; }
  3364. var cM = $t.p.colModel;
  3365. for ( var i =0;i<cM.length;i++ ) {
  3366. if ( cM[i].name == colname ) {
  3367. ret = cM[i];
  3368. break;
  3369. }
  3370. }
  3371. return ret;
  3372. },
  3373. setColProp : function(colname, obj){
  3374. //do not set width will not work
  3375. return this.each(function(){
  3376. if ( this.grid ) {
  3377. if ( obj ) {
  3378. var cM = this.p.colModel;
  3379. for ( var i =0;i<cM.length;i++ ) {
  3380. if ( cM[i].name == colname ) {
  3381. $.extend(this.p.colModel[i],obj);
  3382. break;
  3383. }
  3384. }
  3385. }
  3386. }
  3387. });
  3388. },
  3389. sortGrid : function(colname,reload, sor){
  3390. return this.each(function(){
  3391. var $t=this,idx=-1;
  3392. if ( !$t.grid ) { return;}
  3393. if ( !colname ) { colname = $t.p.sortname; }
  3394. for ( var i=0;i<$t.p.colModel.length;i++ ) {
  3395. if ( $t.p.colModel[i].index == colname || $t.p.colModel[i].name==colname ) {
  3396. idx = i;
  3397. break;
  3398. }
  3399. }
  3400. if ( idx!=-1 ){
  3401. var sort = $t.p.colModel[idx].sortable;
  3402. if ( typeof sort !== 'boolean' ) { sort = true; }
  3403. if ( typeof reload !=='boolean' ) { reload = false; }
  3404. if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor); }
  3405. }
  3406. });
  3407. },
  3408. GridDestroy : function () {
  3409. return this.each(function(){
  3410. if ( this.grid ) {
  3411. if ( this.p.pager ) { // if not part of grid
  3412. $(this.p.pager).remove();
  3413. }
  3414. var gid = this.id;
  3415. try {
  3416. $("#gbox_"+gid).remove();
  3417. } catch (_) {}
  3418. }
  3419. });
  3420. },
  3421. GridUnload : function(){
  3422. return this.each(function(){
  3423. if ( !this.grid ) {return;}
  3424. var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
  3425. if (this.p.pager) {
  3426. $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager corner-bottom");
  3427. }
  3428. var newtable = document.createElement('table');
  3429. $(newtable).attr({id:defgrid.id});
  3430. newtable.className = defgrid.cl;
  3431. var gid = this.id;
  3432. $(newtable).removeClass("ui-jqgrid-btable");
  3433. if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
  3434. $(newtable).insertBefore("#gbox_"+gid).show();
  3435. $(this.p.pager).insertBefore("#gbox_"+gid);
  3436. } else {
  3437. $(newtable).insertBefore("#gbox_"+gid).show();
  3438. }
  3439. $("#gbox_"+gid).remove();
  3440. });
  3441. },
  3442. setGridState : function(state) {
  3443. return this.each(function(){
  3444. if ( !this.grid ) {return;}
  3445. var $t = this;
  3446. if(state == 'hidden'){
  3447. $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$t.p.id).slideUp("fast");
  3448. if($t.p.pager) {$($t.p.pager).slideUp("fast");}
  3449. if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
  3450. if($t.p.toolbar[0]===true) {
  3451. if( $t.p.toolbar[1]=='both') {
  3452. $($t.grid.ubDiv).slideUp("fast");
  3453. }
  3454. $($t.grid.uDiv).slideUp("fast");
  3455. }
  3456. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$t.p.id).slideUp("fast"); }
  3457. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  3458. $t.p.gridstate = 'hidden';
  3459. } else if(state=='visible') {
  3460. $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$t.p.id).slideDown("fast");
  3461. if($t.p.pager) {$($t.p.pager).slideDown("fast");}
  3462. if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
  3463. if($t.p.toolbar[0]===true) {
  3464. if( $t.p.toolbar[1]=='both') {
  3465. $($t.grid.ubDiv).slideDown("fast");
  3466. }
  3467. $($t.grid.uDiv).slideDown("fast");
  3468. }
  3469. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$t.p.id).slideDown("fast"); }
  3470. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  3471. $t.p.gridstate = 'visible';
  3472. }
  3473. });
  3474. },
  3475. filterToolbar : function(p){
  3476. p = $.extend({
  3477. autosearch: true,
  3478. searchOnEnter : true,
  3479. beforeSearch: null,
  3480. afterSearch: null,
  3481. beforeClear: null,
  3482. afterClear: null,
  3483. searchurl : '',
  3484. stringResult: false,
  3485. groupOp: 'AND',
  3486. defaultSearch : "bw"
  3487. },p || {});
  3488. return this.each(function(){
  3489. var $t = this;
  3490. if(this.ftoolbar) { return; }
  3491. var triggerToolbar = function() {
  3492. var sdata={}, j=0, v, nm, sopt={},so;
  3493. $.each($t.p.colModel,function(i,n){
  3494. nm = this.index || this.name;
  3495. switch (this.stype) {
  3496. case 'select' :
  3497. so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : 'eq';
  3498. v = $("#gs_"+$.jgrid.jqID(this.name),$t.grid.hDiv).val();
  3499. if(v) {
  3500. sdata[nm] = v;
  3501. sopt[nm] = so;
  3502. j++;
  3503. } else {
  3504. try {
  3505. delete $t.p.postData[nm];
  3506. } catch (e) {}
  3507. }
  3508. break;
  3509. case 'text':
  3510. so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : p.defaultSearch;
  3511. v = $("#gs_"+$.jgrid.jqID(this.name), $t.grid.hDiv).val();
  3512. if(v) {
  3513. sdata[nm] = v;
  3514. sopt[nm] = so;
  3515. j++;
  3516. } else {
  3517. try {
  3518. delete $t.p.postData[nm];
  3519. } catch (z) {}
  3520. }
  3521. break;
  3522. }
  3523. });
  3524. var sd = j>0 ? true : false;
  3525. if(p.stringResult === true || $t.p.datatype == "local") {
  3526. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  3527. var gi=0;
  3528. $.each(sdata,function(i,n){
  3529. if (gi > 0) {ruleGroup += ",";}
  3530. ruleGroup += "{\"field\":\"" + i + "\",";
  3531. ruleGroup += "\"op\":\"" + sopt[i] + "\",";
  3532. n+="";
  3533. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  3534. gi++;
  3535. });
  3536. ruleGroup += "]}";
  3537. $.extend($t.p.postData,{filters:ruleGroup});
  3538. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  3539. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  3540. });
  3541. } else {
  3542. $.extend($t.p.postData,sdata);
  3543. }
  3544. var saveurl;
  3545. if($t.p.searchurl) {
  3546. saveurl = $t.p.url;
  3547. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  3548. }
  3549. var bsr = false;
  3550. if($.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  3551. if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
  3552. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  3553. if($.isFunction(p.afterSearch)){p.afterSearch();}
  3554. };
  3555. var clearToolbar = function(trigger){
  3556. var sdata={}, v, j=0, nm;
  3557. trigger = (typeof trigger != 'boolean') ? true : trigger;
  3558. $.each($t.p.colModel,function(i,n){
  3559. v = (this.searchoptions && this.searchoptions.defaultValue) ? this.searchoptions.defaultValue : "";
  3560. nm = this.index || this.name;
  3561. switch (this.stype) {
  3562. case 'select' :
  3563. var v1;
  3564. $("#gs_"+$.jgrid.jqID(nm)+" option",$t.grid.hDiv).each(function (i){
  3565. if(i===0) { this.selected = true; }
  3566. if ($(this).text() == v) {
  3567. this.selected = true;
  3568. v1 = $(this).val();
  3569. return false;
  3570. }
  3571. });
  3572. if (v1) {
  3573. // post the key and not the text
  3574. sdata[nm] = v1;
  3575. j++;
  3576. } else {
  3577. try {
  3578. delete $t.p.postData[nm];
  3579. } catch(e) {}
  3580. }
  3581. break;
  3582. case 'text':
  3583. $("#gs_"+$.jgrid.jqID(nm),$t.grid.hDiv).val(v);
  3584. if(v) {
  3585. sdata[nm] = v;
  3586. j++;
  3587. } else {
  3588. try {
  3589. delete $t.p.postData[nm];
  3590. } catch (y){}
  3591. }
  3592. break;
  3593. }
  3594. });
  3595. var sd = j>0 ? true : false;
  3596. if(p.stringResult === true || $t.p.datatype == "local") {
  3597. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  3598. var gi=0;
  3599. $.each(sdata,function(i,n){
  3600. if (gi > 0) {ruleGroup += ",";}
  3601. ruleGroup += "{\"field\":\"" + i + "\",";
  3602. ruleGroup += "\"op\":\"" + "eq" + "\",";
  3603. n+="";
  3604. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  3605. gi++;
  3606. });
  3607. ruleGroup += "]}";
  3608. $.extend($t.p.postData,{filters:ruleGroup});
  3609. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  3610. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  3611. });
  3612. } else {
  3613. $.extend($t.p.postData,sdata);
  3614. }
  3615. var saveurl;
  3616. if($t.p.searchurl) {
  3617. saveurl = $t.p.url;
  3618. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  3619. }
  3620. var bcv = false;
  3621. if($.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
  3622. if(!bcv) {
  3623. if(trigger) {
  3624. $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
  3625. }
  3626. }
  3627. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  3628. if($.isFunction(p.afterClear)){p.afterClear();}
  3629. };
  3630. var toggleToolbar = function(){
  3631. var trow = $("tr.ui-search-toolbar",$t.grid.hDiv);
  3632. if(trow.css("display")=='none') { trow.show(); }
  3633. else { trow.hide(); }
  3634. };
  3635. // create the row
  3636. function bindEvents(selector, events) {
  3637. var jElem = $(selector);
  3638. if (jElem[0]) {
  3639. jQuery.each(events, function() {
  3640. if (this.data !== undefined) {
  3641. jElem.bind(this.type, this.data, this.fn);
  3642. } else {
  3643. jElem.bind(this.type, this.fn);
  3644. }
  3645. });
  3646. }
  3647. }
  3648. var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
  3649. var timeoutHnd;
  3650. $.each($t.p.colModel,function(i,n){
  3651. var cm=this, thd , th, soptions,surl,self;
  3652. th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>");
  3653. thd = $("<div style='width:100%;position:relative;height:100%;padding-right:0.3em;'></div>");
  3654. if(this.hidden===true) { $(th).css("display","none");}
  3655. this.search = this.search === false ? false : true;
  3656. if(typeof this.stype == 'undefined' ) {this.stype='text';}
  3657. soptions = $.extend({},this.searchoptions || {});
  3658. if(this.search){
  3659. switch (this.stype)
  3660. {
  3661. case "select":
  3662. surl = this.surl || soptions.dataUrl;
  3663. if(surl) {
  3664. // data returned should have already constructed html select
  3665. // primitive jQuery load
  3666. self = thd;
  3667. $.ajax($.extend({
  3668. url: surl,
  3669. dataType: "html",
  3670. success: function(res,status) {
  3671. if(soptions.buildSelect !== undefined) {
  3672. var d = soptions.buildSelect(res);
  3673. if (d) { $(self).append(d); }
  3674. } else {
  3675. $(self).append(res);
  3676. }
  3677. if(soptions.defaultValue) { $("select",self).val(soptions.defaultValue); }
  3678. $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  3679. if(soptions.attr) {$("select",self).attr(soptions.attr);}
  3680. $("select",self).css({width: "100%"});
  3681. // preserve autoserch
  3682. if(soptions.dataInit !== undefined) { soptions.dataInit($("select",self)[0]); }
  3683. if(soptions.dataEvents !== undefined) { bindEvents($("select",self)[0],soptions.dataEvents); }
  3684. if(p.autosearch===true){
  3685. $("select",self).change(function(e){
  3686. triggerToolbar();
  3687. return false;
  3688. });
  3689. }
  3690. res=null;
  3691. }
  3692. }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
  3693. } else {
  3694. var oSv;
  3695. if(cm.searchoptions && cm.searchoptions.value) {
  3696. oSv = cm.searchoptions.value;
  3697. } else if(cm.editoptions && cm.editoptions.value) {
  3698. oSv = cm.editoptions.value;
  3699. }
  3700. if (oSv) {
  3701. var elem = document.createElement("select");
  3702. elem.style.width = "100%";
  3703. $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  3704. var so, sv, ov;
  3705. if(typeof oSv === "string") {
  3706. so = oSv.split(";");
  3707. for(var k=0; k<so.length;k++){
  3708. sv = so[k].split(":");
  3709. ov = document.createElement("option");
  3710. ov.value = sv[0]; ov.innerHTML = sv[1];
  3711. elem.appendChild(ov);
  3712. }
  3713. } else if(typeof oSv === "object" ) {
  3714. for ( var key in oSv) {
  3715. if(oSv.hasOwnProperty(key)) {
  3716. ov = document.createElement("option");
  3717. ov.value = key; ov.innerHTML = oSv[key];
  3718. elem.appendChild(ov);
  3719. }
  3720. }
  3721. }
  3722. if(soptions.defaultValue) { $(elem).val(soptions.defaultValue); }
  3723. if(soptions.attr) {$(elem).attr(soptions.attr);}
  3724. if(soptions.dataInit !== undefined) { soptions.dataInit(elem); }
  3725. if(soptions.dataEvents !== undefined) { bindEvents(elem, soptions.dataEvents); }
  3726. $(thd).append(elem);
  3727. if(p.autosearch===true){
  3728. $(elem).change(function(e){
  3729. triggerToolbar();
  3730. return false;
  3731. });
  3732. }
  3733. }
  3734. }
  3735. break;
  3736. case 'text':
  3737. var df = soptions.defaultValue ? soptions.defaultValue: "";
  3738. $(thd).append("<input type='text' style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
  3739. if(soptions.attr) {$("input",thd).attr(soptions.attr);}
  3740. if(soptions.dataInit !== undefined) { soptions.dataInit($("input",thd)[0]); }
  3741. if(soptions.dataEvents !== undefined) { bindEvents($("input",thd)[0], soptions.dataEvents); }
  3742. if(p.autosearch===true){
  3743. if(p.searchOnEnter) {
  3744. $("input",thd).keypress(function(e){
  3745. var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
  3746. if(key == 13){
  3747. triggerToolbar();
  3748. return false;
  3749. }
  3750. return this;
  3751. });
  3752. } else {
  3753. $("input",thd).keydown(function(e){
  3754. var key = e.which;
  3755. switch (key) {
  3756. case 13:
  3757. return false;
  3758. case 9 :
  3759. case 16:
  3760. case 37:
  3761. case 38:
  3762. case 39:
  3763. case 40:
  3764. case 27:
  3765. break;
  3766. default :
  3767. if(timeoutHnd) { clearTimeout(timeoutHnd); }
  3768. timeoutHnd = setTimeout(function(){triggerToolbar();},500);
  3769. }
  3770. });
  3771. }
  3772. }
  3773. break;
  3774. }
  3775. }
  3776. $(th).append(thd);
  3777. $(tr).append(th);
  3778. });
  3779. $("table thead",$t.grid.hDiv).append(tr);
  3780. this.ftoolbar = true;
  3781. this.triggerToolbar = triggerToolbar;
  3782. this.clearToolbar = clearToolbar;
  3783. this.toggleToolbar = toggleToolbar;
  3784. });
  3785. },
  3786. destroyGroupHeader : function(nullHeader)
  3787. {
  3788. if(typeof(nullHeader) == 'undefined') {
  3789. nullHeader = true;
  3790. }
  3791. return this.each(function()
  3792. {
  3793. var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid,
  3794. thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc;
  3795. if(!grid) return;
  3796. $tr = $("<tr>", {role: "rowheader"}).addClass("ui-jqgrid-labels");
  3797. headers = grid.headers;
  3798. for (i = 0, l = headers.length; i < l; i++) {
  3799. hc = cm[i].hidden ? "none" : "";
  3800. $th = $(headers[i].el)
  3801. .width(headers[i].width)
  3802. .removeAttr("rowSpan")
  3803. .css('display',hc);
  3804. $tr.append($th);
  3805. $resizing = $th.children("span.ui-jqgrid-resize");
  3806. if ($resizing.length>0) {// resizable column
  3807. $resizing[0].style.height = "";
  3808. }
  3809. $th.children("div")[0].style.top = "";
  3810. }
  3811. $(thead).children('tr.ui-jqgrid-labels').remove();
  3812. $(thead).prepend($tr);
  3813. if(nullHeader === true) {
  3814. $($t).jqGrid('setGridParam',{ 'groupHeader': null});
  3815. }
  3816. });
  3817. },
  3818. setGroupHeaders : function ( o ) {
  3819. o = $.extend({
  3820. useColSpanStyle : false,
  3821. groupHeaders: []
  3822. },o || {});
  3823. return this.each(function(){
  3824. this.p.groupHeader = o;
  3825. var ts = this,
  3826. i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle,
  3827. iCol,
  3828. cghi,
  3829. //startColumnName,
  3830. numberOfColumns,
  3831. titleText,
  3832. cVisibleColumns,
  3833. colModel = ts.p.colModel,
  3834. cml = colModel.length,
  3835. ths = ts.grid.headers,
  3836. $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),
  3837. $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),
  3838. $thead = $htable.children("thead"),
  3839. $theadInTable,
  3840. originalResizeStop,
  3841. $firstHeaderRow = $htable.find(".jqg-first-row-header");
  3842. if($firstHeaderRow.html() === null) {
  3843. $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
  3844. } else {
  3845. $firstHeaderRow.empty();
  3846. }
  3847. var $firstRow,
  3848. inColumnHeader = function (text, columnHeaders) {
  3849. var i = 0, length = columnHeaders.length;
  3850. for (; i < length; i++) {
  3851. if (columnHeaders[i].startColumnName === text) {
  3852. return i;
  3853. }
  3854. }
  3855. return -1;
  3856. };
  3857. $(ts).prepend($thead);
  3858. $tr = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header");
  3859. for (i = 0; i < cml; i++) {
  3860. th = ths[i].el;
  3861. $th = $(th);
  3862. cmi = colModel[i];
  3863. // build the next cell for the first header row
  3864. thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
  3865. $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);
  3866. th.style.width = ""; // remove unneeded style
  3867. iCol = inColumnHeader(cmi.name, o.groupHeaders);
  3868. if (iCol >= 0) {
  3869. cghi = o.groupHeaders[iCol];
  3870. numberOfColumns = cghi.numberOfColumns;
  3871. titleText = cghi.titleText;
  3872. // caclulate the number of visible columns from the next numberOfColumns columns
  3873. for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
  3874. if (!colModel[i + iCol].hidden) {
  3875. cVisibleColumns++;
  3876. }
  3877. }
  3878. // The next numberOfColumns headers will be moved in the next row
  3879. // in the current row will be placed the new column header with the titleText.
  3880. // The text will be over the cVisibleColumns columns
  3881. $colHeader = $('<th>', {colspan: String(cVisibleColumns), role: "columnheader"})
  3882. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  3883. .css({'height':'22px', 'border-top': '0px none'})
  3884. .html(titleText);
  3885. if (ts.p.headertitles) {
  3886. $colHeader.attr("title", $colHeader.text());
  3887. }
  3888. // hide if not a visible cols
  3889. if( cVisibleColumns === 0) {
  3890. $colHeader.hide();
  3891. }
  3892. $th.before($colHeader); // insert new column header before the current
  3893. $tr.append(th); // move the current header in the next row
  3894. // set the coumter of headers which will be moved in the next row
  3895. skip = numberOfColumns - 1;
  3896. } else {
  3897. if (skip === 0) {
  3898. if (o.useColSpanStyle) {
  3899. // expand the header height to two rows
  3900. $th.attr("rowspan", "2");
  3901. } else {
  3902. $('<th>', {role: "columnheader"})
  3903. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  3904. .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0px none'})
  3905. .insertBefore($th);
  3906. $tr.append(th);
  3907. }
  3908. } else {
  3909. // move the header to the next row
  3910. //$th.css({"padding-top": "2px", height: "19px"});
  3911. $tr.append(th);
  3912. skip--;
  3913. }
  3914. }
  3915. }
  3916. $theadInTable = $(ts).children("thead");
  3917. $theadInTable.prepend($firstHeaderRow);
  3918. $tr.insertAfter($trLabels);
  3919. $htable.append($theadInTable);
  3920. if (o.useColSpanStyle) {
  3921. // Increase the height of resizing span of visible headers
  3922. $htable.find("span.ui-jqgrid-resize").each(function () {
  3923. var $parent = $(this).parent();
  3924. if ($parent.is(":visible")) {
  3925. this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
  3926. }
  3927. });
  3928. // Set position of the sortable div (the main lable)
  3929. // with the column header text to the middle of the cell.
  3930. // One should not do this for hidden headers.
  3931. $htable.find("div.ui-jqgrid-sortable").each(function () {
  3932. var $ts = $(this), $parent = $ts.parent();
  3933. if ($parent.is(":visible")) {
  3934. $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');
  3935. }
  3936. });
  3937. }
  3938. // Preserve original resizeStop event if any defined
  3939. if ($.isFunction(ts.p.resizeStop)) {
  3940. originalResizeStop = ts.p.resizeStop;
  3941. }
  3942. $firstRow = $theadInTable.find("tr.jqg-first-row-header");
  3943. ts.p.resizeStop = function (nw, idx) {
  3944. $firstRow.find('th').eq(idx).width(nw);
  3945. if ($.isFunction(originalResizeStop)) {
  3946. originalResizeStop.call(ts, nw, idx);
  3947. }
  3948. };
  3949. });
  3950. }
  3951. });
  3952. })(jQuery);/*
  3953. * jqModal - Minimalist Modaling with jQuery
  3954. * (http://dev.iceburg.net/jquery/jqmodal/)
  3955. *
  3956. * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
  3957. * Dual licensed under the MIT and GPL licenses:
  3958. * http://www.opensource.org/licenses/mit-license.php
  3959. * http://www.gnu.org/licenses/gpl.html
  3960. *
  3961. * $Version: 07/06/2008 +r13
  3962. */
  3963. (function($) {
  3964. $.fn.jqm=function(o){
  3965. var p={
  3966. overlay: 50,
  3967. closeoverlay : true,
  3968. overlayClass: 'jqmOverlay',
  3969. closeClass: 'jqmClose',
  3970. trigger: '.jqModal',
  3971. ajax: F,
  3972. ajaxText: '',
  3973. target: F,
  3974. modal: F,
  3975. toTop: F,
  3976. onShow: F,
  3977. onHide: F,
  3978. onLoad: F
  3979. };
  3980. return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
  3981. H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
  3982. if(p.trigger)$(this).jqmAddTrigger(p.trigger);
  3983. });};
  3984. $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
  3985. $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
  3986. $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
  3987. $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};
  3988. $.jqm = {
  3989. hash:{},
  3990. open: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);
  3991. if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);}
  3992. else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);}
  3993. else o=F;
  3994. h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
  3995. if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}
  3996. 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;
  3997. 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);});}
  3998. else if(cc)h.w.jqmAddClose($(cc,h.w));
  3999. if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
  4000. (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
  4001. },
  4002. close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
  4003. if(A[0]){A.pop();if(!A[0])L('unbind');}
  4004. if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
  4005. if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
  4006. },
  4007. params:{}};
  4008. var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
  4009. e=function(h){var i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0});if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
  4010. f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
  4011. L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
  4012. m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
  4013. hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
  4014. 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);});});};
  4015. })(jQuery);/*
  4016. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  4017. *
  4018. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  4019. * Licensed under the MIT License:
  4020. * http://www.opensource.org/licenses/mit-license.php
  4021. *
  4022. * $Version: 2007.08.19 +r2
  4023. */
  4024. (function($){
  4025. $.fn.jqDrag=function(h){return i(this,h,'d');};
  4026. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  4027. $.jqDnR={
  4028. dnr:{},
  4029. e:0,
  4030. drag:function(v){
  4031. if(M.k == 'd')E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});
  4032. else {
  4033. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  4034. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  4035. }
  4036. return false;
  4037. },
  4038. stop:function(){
  4039. //E.css('opacity',M.o);
  4040. $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
  4041. }
  4042. };
  4043. var J=$.jqDnR,M=J.dnr,E=J.e,E1,
  4044. i=function(e,h,k,aR){
  4045. return e.each(function(){
  4046. h=(h)?$(h,e):e;
  4047. h.bind('mousedown',{e:e,k:k},function(v){
  4048. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  4049. // attempt utilization of dimensions plugin to fix IE issues
  4050. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  4051. M={
  4052. X:p.left||f('left')||0,
  4053. Y:p.top||f('top')||0,
  4054. W:f('width')||E[0].scrollWidth||0,
  4055. H:f('height')||E[0].scrollHeight||0,
  4056. pX:v.pageX,
  4057. pY:v.pageY,
  4058. k:d.k
  4059. //o:E.css('opacity')
  4060. };
  4061. // also resize
  4062. if(E1 && d.k != 'd'){
  4063. M1={
  4064. X:p.left||f1('left')||0,
  4065. Y:p.top||f1('top')||0,
  4066. W:E1[0].offsetWidth||f1('width')||0,
  4067. H:E1[0].offsetHeight||f1('height')||0,
  4068. pX:v.pageX,
  4069. pY:v.pageY,
  4070. k:d.k
  4071. };
  4072. } else {M1 = false;}
  4073. //E.css({opacity:0.8});
  4074. if($("input.hasDatepicker",E[0])[0]) {
  4075. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  4076. }
  4077. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  4078. return false;
  4079. });
  4080. });
  4081. },
  4082. f=function(k){return parseInt(E.css(k))||false;};
  4083. f1=function(k){ return parseInt(E1.css(k))||false;};
  4084. })(jQuery);/*
  4085. The below work is licensed under Creative Commons GNU LGPL License.
  4086. Original work:
  4087. License: http://creativecommons.org/licenses/LGPL/2.1/
  4088. Author: Stefan Goessner/2006
  4089. Web: http://goessner.net/
  4090. Modifications made:
  4091. Version: 0.9-p5
  4092. Description: Restructured code, JSLint validated (no strict whitespaces),
  4093. added handling of empty arrays, empty strings, and int/floats values.
  4094. Author: Michael Schøler/2008-01-29
  4095. Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
  4096. Description: json2xml added support to convert functions as CDATA
  4097. so it will be easy to write characters that cause some problems when convert
  4098. Author: Tony Tomov
  4099. */
  4100. /*global alert */
  4101. var xmlJsonClass = {
  4102. // Param "xml": Element or document DOM node.
  4103. // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4104. // Returns: JSON string
  4105. xml2json: function(xml, tab) {
  4106. if (xml.nodeType === 9) {
  4107. // document node
  4108. xml = xml.documentElement;
  4109. }
  4110. var nws = this.removeWhite(xml);
  4111. var obj = this.toObj(nws);
  4112. var json = this.toJson(obj, xml.nodeName, "\t");
  4113. return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
  4114. },
  4115. // Param "o": JavaScript object
  4116. // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4117. // Returns: XML string
  4118. json2xml: function(o, tab) {
  4119. var toXml = function(v, name, ind) {
  4120. var xml = "";
  4121. var i, n;
  4122. if (v instanceof Array) {
  4123. if (v.length === 0) {
  4124. xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
  4125. }
  4126. else {
  4127. for (i = 0, n = v.length; i < n; i += 1) {
  4128. var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
  4129. xml += sXml;
  4130. }
  4131. }
  4132. }
  4133. else if (typeof(v) === "object") {
  4134. var hasChild = false;
  4135. xml += ind + "<" + name;
  4136. var m;
  4137. for (m in v) if (v.hasOwnProperty(m)) {
  4138. if (m.charAt(0) === "@") {
  4139. xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
  4140. }
  4141. else {
  4142. hasChild = true;
  4143. }
  4144. }
  4145. xml += hasChild ? ">" : "/>";
  4146. if (hasChild) {
  4147. for (m in v) if (v.hasOwnProperty(m)) {
  4148. if (m === "#text") {
  4149. xml += v[m];
  4150. }
  4151. else if (m === "#cdata") {
  4152. xml += "<![CDATA[" + v[m] + "]]>";
  4153. }
  4154. else if (m.charAt(0) !== "@") {
  4155. xml += toXml(v[m], m, ind+"\t");
  4156. }
  4157. }
  4158. xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
  4159. }
  4160. }
  4161. else if (typeof(v) === "function") {
  4162. xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
  4163. }
  4164. else {
  4165. if (v === undefined ) { v = ""; }
  4166. if (v.toString() === "\"\"" || v.toString().length === 0) {
  4167. xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
  4168. }
  4169. else {
  4170. xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
  4171. }
  4172. }
  4173. return xml;
  4174. };
  4175. var xml = "";
  4176. var m;
  4177. for (m in o) if (o.hasOwnProperty(m)) {
  4178. xml += toXml(o[m], m, "");
  4179. }
  4180. return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
  4181. },
  4182. // Internal methods
  4183. toObj: function(xml) {
  4184. var o = {};
  4185. var FuncTest = /function/i;
  4186. if (xml.nodeType === 1) {
  4187. // element node ..
  4188. if (xml.attributes.length) {
  4189. // element with attributes ..
  4190. var i;
  4191. for (i = 0; i < xml.attributes.length; i += 1) {
  4192. o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
  4193. }
  4194. }
  4195. if (xml.firstChild) {
  4196. // element has child nodes ..
  4197. var textChild = 0, cdataChild = 0, hasElementChild = false;
  4198. var n;
  4199. for (n = xml.firstChild; n; n = n.nextSibling) {
  4200. if (n.nodeType === 1) {
  4201. hasElementChild = true;
  4202. }
  4203. else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  4204. // non-whitespace text
  4205. textChild += 1;
  4206. }
  4207. else if (n.nodeType === 4) {
  4208. // cdata section node
  4209. cdataChild += 1;
  4210. }
  4211. }
  4212. if (hasElementChild) {
  4213. if (textChild < 2 && cdataChild < 2) {
  4214. // structured element with evtl. a single text or/and cdata node ..
  4215. this.removeWhite(xml);
  4216. for (n = xml.firstChild; n; n = n.nextSibling) {
  4217. if (n.nodeType === 3) {
  4218. // text node
  4219. o["#text"] = this.escape(n.nodeValue);
  4220. }
  4221. else if (n.nodeType === 4) {
  4222. // cdata node
  4223. if (FuncTest.test(n.nodeValue)) {
  4224. o[n.nodeName] = [o[n.nodeName], n.nodeValue];
  4225. } else {
  4226. o["#cdata"] = this.escape(n.nodeValue);
  4227. }
  4228. }
  4229. else if (o[n.nodeName]) {
  4230. // multiple occurence of element ..
  4231. if (o[n.nodeName] instanceof Array) {
  4232. o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
  4233. }
  4234. else {
  4235. o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
  4236. }
  4237. }
  4238. else {
  4239. // first occurence of element ..
  4240. o[n.nodeName] = this.toObj(n);
  4241. }
  4242. }
  4243. }
  4244. else {
  4245. // mixed content
  4246. if (!xml.attributes.length) {
  4247. o = this.escape(this.innerXml(xml));
  4248. }
  4249. else {
  4250. o["#text"] = this.escape(this.innerXml(xml));
  4251. }
  4252. }
  4253. }
  4254. else if (textChild) {
  4255. // pure text
  4256. if (!xml.attributes.length) {
  4257. o = this.escape(this.innerXml(xml));
  4258. if (o === "__EMPTY_ARRAY_") {
  4259. o = "[]";
  4260. } else if (o === "__EMPTY_STRING_") {
  4261. o = "";
  4262. }
  4263. }
  4264. else {
  4265. o["#text"] = this.escape(this.innerXml(xml));
  4266. }
  4267. }
  4268. else if (cdataChild) {
  4269. // cdata
  4270. if (cdataChild > 1) {
  4271. o = this.escape(this.innerXml(xml));
  4272. }
  4273. else {
  4274. for (n = xml.firstChild; n; n = n.nextSibling) {
  4275. if(FuncTest.test(xml.firstChild.nodeValue)) {
  4276. o = xml.firstChild.nodeValue;
  4277. break;
  4278. } else {
  4279. o["#cdata"] = this.escape(n.nodeValue);
  4280. }
  4281. }
  4282. }
  4283. }
  4284. }
  4285. if (!xml.attributes.length && !xml.firstChild) {
  4286. o = null;
  4287. }
  4288. }
  4289. else if (xml.nodeType === 9) {
  4290. // document.node
  4291. o = this.toObj(xml.documentElement);
  4292. }
  4293. else {
  4294. alert("unhandled node type: " + xml.nodeType);
  4295. }
  4296. return o;
  4297. },
  4298. toJson: function(o, name, ind, wellform) {
  4299. if(wellform === undefined) wellform = true;
  4300. var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
  4301. if(!wellform) {
  4302. tab= ""; newline= "";
  4303. }
  4304. if (o === "[]") {
  4305. json += (name ? ":[]" : "[]");
  4306. }
  4307. else if (o instanceof Array) {
  4308. var n, i, ar=[];
  4309. for (i = 0, n = o.length; i < n; i += 1) {
  4310. ar[i] = this.toJson(o[i], "", ind + tab, wellform);
  4311. }
  4312. json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
  4313. }
  4314. else if (o === null) {
  4315. json += (name && ":") + "null";
  4316. }
  4317. else if (typeof(o) === "object") {
  4318. var arr = [], m;
  4319. for (m in o) {
  4320. if (o.hasOwnProperty(m)) {
  4321. arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
  4322. }
  4323. }
  4324. json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
  4325. }
  4326. else if (typeof(o) === "string") {
  4327. /*
  4328. var objRegExp = /(^-?\d+\.?\d*$)/;
  4329. var FuncTest = /function/i;
  4330. var os = o.toString();
  4331. if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
  4332. // int or float
  4333. json += (name && ":") + "\"" +os + "\"";
  4334. }
  4335. else {
  4336. */
  4337. json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
  4338. //}
  4339. }
  4340. else {
  4341. json += (name && ":") + "\"" + o.toString()+ "\"";
  4342. }
  4343. return json;
  4344. },
  4345. innerXml: function(node) {
  4346. var s = "";
  4347. if ("innerHTML" in node) {
  4348. s = node.innerHTML;
  4349. }
  4350. else {
  4351. var asXml = function(n) {
  4352. var s = "", i;
  4353. if (n.nodeType === 1) {
  4354. s += "<" + n.nodeName;
  4355. for (i = 0; i < n.attributes.length; i += 1) {
  4356. s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
  4357. }
  4358. if (n.firstChild) {
  4359. s += ">";
  4360. for (var c = n.firstChild; c; c = c.nextSibling) {
  4361. s += asXml(c);
  4362. }
  4363. s += "</" + n.nodeName + ">";
  4364. }
  4365. else {
  4366. s += "/>";
  4367. }
  4368. }
  4369. else if (n.nodeType === 3) {
  4370. s += n.nodeValue;
  4371. }
  4372. else if (n.nodeType === 4) {
  4373. s += "<![CDATA[" + n.nodeValue + "]]>";
  4374. }
  4375. return s;
  4376. };
  4377. for (var c = node.firstChild; c; c = c.nextSibling) {
  4378. s += asXml(c);
  4379. }
  4380. }
  4381. return s;
  4382. },
  4383. escape: function(txt) {
  4384. return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
  4385. },
  4386. removeWhite: function(e) {
  4387. e.normalize();
  4388. var n;
  4389. for (n = e.firstChild; n; ) {
  4390. if (n.nodeType === 3) {
  4391. // text node
  4392. if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  4393. // pure whitespace text node
  4394. var nxt = n.nextSibling;
  4395. e.removeChild(n);
  4396. n = nxt;
  4397. }
  4398. else {
  4399. n = n.nextSibling;
  4400. }
  4401. }
  4402. else if (n.nodeType === 1) {
  4403. // element node
  4404. this.removeWhite(n);
  4405. n = n.nextSibling;
  4406. }
  4407. else {
  4408. // any other node
  4409. n = n.nextSibling;
  4410. }
  4411. }
  4412. return e;
  4413. }
  4414. };/*
  4415. **
  4416. * formatter for values but most of the values if for jqGrid
  4417. * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
  4418. * we are trying to keep it as light as possible
  4419. * Joshua Burnett josh@9ci.com
  4420. * http://www.greenbill.com
  4421. *
  4422. * Changes from Tony Tomov tony@trirand.com
  4423. * Dual licensed under the MIT and GPL licenses:
  4424. * http://www.opensource.org/licenses/mit-license.php
  4425. * http://www.gnu.org/licenses/gpl-2.0.html
  4426. *
  4427. **/
  4428. ;(function($) {
  4429. $.fmatter = {};
  4430. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  4431. //example {id:1234,}
  4432. $.extend($.fmatter,{
  4433. isBoolean : function(o) {
  4434. return typeof o === 'boolean';
  4435. },
  4436. isObject : function(o) {
  4437. return (o && (typeof o === 'object' || $.isFunction(o))) || false;
  4438. },
  4439. isString : function(o) {
  4440. return typeof o === 'string';
  4441. },
  4442. isNumber : function(o) {
  4443. return typeof o === 'number' && isFinite(o);
  4444. },
  4445. isNull : function(o) {
  4446. return o === null;
  4447. },
  4448. isUndefined : function(o) {
  4449. return typeof o === 'undefined';
  4450. },
  4451. isValue : function (o) {
  4452. return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
  4453. },
  4454. isEmpty : function(o) {
  4455. if(!this.isString(o) && this.isValue(o)) {
  4456. return false;
  4457. }else if (!this.isValue(o)){
  4458. return true;
  4459. }
  4460. o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
  4461. return o==="";
  4462. }
  4463. });
  4464. $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
  4465. // build main options before element iteration
  4466. var v=cellval;
  4467. opts = $.extend({}, $.jgrid.formatter, opts);
  4468. if ($.fn.fmatter[formatType]){
  4469. v = $.fn.fmatter[formatType](cellval, opts, rwd, act);
  4470. }
  4471. return v;
  4472. };
  4473. $.fmatter.util = {
  4474. // Taken from YAHOO utils
  4475. NumberFormat : function(nData,opts) {
  4476. if(!$.fmatter.isNumber(nData)) {
  4477. nData *= 1;
  4478. }
  4479. if($.fmatter.isNumber(nData)) {
  4480. var bNegative = (nData < 0);
  4481. var sOutput = nData + "";
  4482. var sDecimalSeparator = (opts.decimalSeparator) ? opts.decimalSeparator : ".";
  4483. var nDotIndex;
  4484. if($.fmatter.isNumber(opts.decimalPlaces)) {
  4485. // Round to the correct decimal place
  4486. var nDecimalPlaces = opts.decimalPlaces;
  4487. var nDecimal = Math.pow(10, nDecimalPlaces);
  4488. sOutput = Math.round(nData*nDecimal)/nDecimal + "";
  4489. nDotIndex = sOutput.lastIndexOf(".");
  4490. if(nDecimalPlaces > 0) {
  4491. // Add the decimal separator
  4492. if(nDotIndex < 0) {
  4493. sOutput += sDecimalSeparator;
  4494. nDotIndex = sOutput.length-1;
  4495. }
  4496. // Replace the "."
  4497. else if(sDecimalSeparator !== "."){
  4498. sOutput = sOutput.replace(".",sDecimalSeparator);
  4499. }
  4500. // Add missing zeros
  4501. while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  4502. sOutput += "0";
  4503. }
  4504. }
  4505. }
  4506. if(opts.thousandsSeparator) {
  4507. var sThousandsSeparator = opts.thousandsSeparator;
  4508. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  4509. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  4510. var sNewOutput = sOutput.substring(nDotIndex);
  4511. var nCount = -1;
  4512. for (var i=nDotIndex; i>0; i--) {
  4513. nCount++;
  4514. if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  4515. sNewOutput = sThousandsSeparator + sNewOutput;
  4516. }
  4517. sNewOutput = sOutput.charAt(i-1) + sNewOutput;
  4518. }
  4519. sOutput = sNewOutput;
  4520. }
  4521. // Prepend prefix
  4522. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  4523. // Append suffix
  4524. sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
  4525. return sOutput;
  4526. } else {
  4527. return nData;
  4528. }
  4529. },
  4530. // Tony Tomov
  4531. // PHP implementation. Sorry not all options are supported.
  4532. // Feel free to add them if you want
  4533. DateFormat : function (format, date, newformat, opts) {
  4534. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  4535. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  4536. timezoneClip = /[^-+\dA-Z]/g,
  4537. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  4538. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  4539. pad = function (value, length) {
  4540. value = String(value);
  4541. length = parseInt(length,10) || 2;
  4542. while (value.length < length) { value = '0' + value; }
  4543. return value;
  4544. },
  4545. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  4546. timestamp=0, dM, k,hl,
  4547. dateFormat=["i18n"];
  4548. // Internationalization strings
  4549. dateFormat.i18n = {
  4550. dayNames: opts.dayNames,
  4551. monthNames: opts.monthNames
  4552. };
  4553. if( format in opts.masks ) { format = opts.masks[format]; }
  4554. if( !isNaN( date - 0 ) && String(format).toLowerCase() == "u") {
  4555. //Unix timestamp
  4556. timestamp = new Date( parseFloat(date)*1000 );
  4557. } else if(date.constructor === Date) {
  4558. timestamp = date;
  4559. // Microsoft date format support
  4560. } else if( msMatch !== null ) {
  4561. timestamp = new Date(parseInt(msMatch[1], 10));
  4562. if (msMatch[3]) {
  4563. var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  4564. offset *= ((msMatch[4] == '-') ? 1 : -1);
  4565. offset -= timestamp.getTimezoneOffset();
  4566. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  4567. }
  4568. } else {
  4569. date = String(date).split(/[\\\/:_;.,\t\T\s-]/);
  4570. format = format.split(/[\\\/:_;.,\t\T\s-]/);
  4571. // parsing for month names
  4572. for(k=0,hl=format.length;k<hl;k++){
  4573. if(format[k] == 'M') {
  4574. dM = $.inArray(date[k],dateFormat.i18n.monthNames);
  4575. if(dM !== -1 && dM < 12){date[k] = dM+1;}
  4576. }
  4577. if(format[k] == 'F') {
  4578. dM = $.inArray(date[k],dateFormat.i18n.monthNames);
  4579. if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
  4580. }
  4581. if(date[k]) {
  4582. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  4583. }
  4584. }
  4585. if(ts.f) {ts.m = ts.f;}
  4586. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  4587. return "&#160;" ;
  4588. }
  4589. ts.m = parseInt(ts.m,10)-1;
  4590. var ty = ts.y;
  4591. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  4592. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  4593. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  4594. }
  4595. if( newformat in opts.masks ) {
  4596. newformat = opts.masks[newformat];
  4597. } else if ( !newformat ) {
  4598. newformat = 'Y-m-d';
  4599. }
  4600. var
  4601. G = timestamp.getHours(),
  4602. i = timestamp.getMinutes(),
  4603. j = timestamp.getDate(),
  4604. n = timestamp.getMonth() + 1,
  4605. o = timestamp.getTimezoneOffset(),
  4606. s = timestamp.getSeconds(),
  4607. u = timestamp.getMilliseconds(),
  4608. w = timestamp.getDay(),
  4609. Y = timestamp.getFullYear(),
  4610. N = (w + 6) % 7 + 1,
  4611. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  4612. flags = {
  4613. // Day
  4614. d: pad(j),
  4615. D: dateFormat.i18n.dayNames[w],
  4616. j: j,
  4617. l: dateFormat.i18n.dayNames[w + 7],
  4618. N: N,
  4619. S: opts.S(j),
  4620. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  4621. w: w,
  4622. z: z,
  4623. // Week
  4624. 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),
  4625. // Month
  4626. F: dateFormat.i18n.monthNames[n - 1 + 12],
  4627. m: pad(n),
  4628. M: dateFormat.i18n.monthNames[n - 1],
  4629. n: n,
  4630. t: '?',
  4631. // Year
  4632. L: '?',
  4633. o: '?',
  4634. Y: Y,
  4635. y: String(Y).substring(2),
  4636. // Time
  4637. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  4638. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  4639. B: '?',
  4640. g: G % 12 || 12,
  4641. G: G,
  4642. h: pad(G % 12 || 12),
  4643. H: pad(G),
  4644. i: pad(i),
  4645. s: pad(s),
  4646. u: u,
  4647. // Timezone
  4648. e: '?',
  4649. I: '?',
  4650. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  4651. P: '?',
  4652. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  4653. Z: '?',
  4654. // Full Date/Time
  4655. c: '?',
  4656. r: '?',
  4657. U: Math.floor(timestamp / 1000)
  4658. };
  4659. return newformat.replace(token, function ($0) {
  4660. return $0 in flags ? flags[$0] : $0.substring(1);
  4661. });
  4662. }
  4663. };
  4664. $.fn.fmatter.defaultFormat = function(cellval, opts) {
  4665. return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue ? opts.defaultValue : "&#160;";
  4666. };
  4667. $.fn.fmatter.email = function(cellval, opts) {
  4668. if(!$.fmatter.isEmpty(cellval)) {
  4669. return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
  4670. }else {
  4671. return $.fn.fmatter.defaultFormat(cellval,opts );
  4672. }
  4673. };
  4674. $.fn.fmatter.checkbox =function(cval, opts) {
  4675. var op = $.extend({},opts.checkbox), ds;
  4676. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4677. op = $.extend({},op,opts.colModel.formatoptions);
  4678. }
  4679. if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
  4680. if($.fmatter.isEmpty(cval) || $.fmatter.isUndefined(cval) ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
  4681. cval=cval+"";cval=cval.toLowerCase();
  4682. var bchk = cval.search(/(false|0|no|off)/i)<0 ? " checked='checked' " : "";
  4683. return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
  4684. };
  4685. $.fn.fmatter.link = function(cellval, opts) {
  4686. var op = {target:opts.target};
  4687. var target = "";
  4688. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4689. op = $.extend({},op,opts.colModel.formatoptions);
  4690. }
  4691. if(op.target) {target = 'target=' + op.target;}
  4692. if(!$.fmatter.isEmpty(cellval)) {
  4693. return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
  4694. }else {
  4695. return $.fn.fmatter.defaultFormat(cellval,opts);
  4696. }
  4697. };
  4698. $.fn.fmatter.showlink = function(cellval, opts) {
  4699. var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
  4700. target = "", idUrl;
  4701. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4702. op = $.extend({},op,opts.colModel.formatoptions);
  4703. }
  4704. if(op.target) {target = 'target=' + op.target;}
  4705. idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
  4706. if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
  4707. return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
  4708. }else {
  4709. return $.fn.fmatter.defaultFormat(cellval,opts);
  4710. }
  4711. };
  4712. $.fn.fmatter.integer = function(cellval, opts) {
  4713. var op = $.extend({},opts.integer);
  4714. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4715. op = $.extend({},op,opts.colModel.formatoptions);
  4716. }
  4717. if($.fmatter.isEmpty(cellval)) {
  4718. return op.defaultValue;
  4719. }
  4720. return $.fmatter.util.NumberFormat(cellval,op);
  4721. };
  4722. $.fn.fmatter.number = function (cellval, opts) {
  4723. var op = $.extend({},opts.number);
  4724. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4725. op = $.extend({},op,opts.colModel.formatoptions);
  4726. }
  4727. if($.fmatter.isEmpty(cellval)) {
  4728. return op.defaultValue;
  4729. }
  4730. return $.fmatter.util.NumberFormat(cellval,op);
  4731. };
  4732. $.fn.fmatter.currency = function (cellval, opts) {
  4733. var op = $.extend({},opts.currency);
  4734. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4735. op = $.extend({},op,opts.colModel.formatoptions);
  4736. }
  4737. if($.fmatter.isEmpty(cellval)) {
  4738. return op.defaultValue;
  4739. }
  4740. return $.fmatter.util.NumberFormat(cellval,op);
  4741. };
  4742. $.fn.fmatter.date = function (cellval, opts, rwd, act) {
  4743. var op = $.extend({},opts.date);
  4744. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4745. op = $.extend({},op,opts.colModel.formatoptions);
  4746. }
  4747. if(!op.reformatAfterEdit && act=='edit'){
  4748. return $.fn.fmatter.defaultFormat(cellval, opts);
  4749. } else if(!$.fmatter.isEmpty(cellval)) {
  4750. return $.fmatter.util.DateFormat(op.srcformat,cellval,op.newformat,op);
  4751. } else {
  4752. return $.fn.fmatter.defaultFormat(cellval, opts);
  4753. }
  4754. };
  4755. $.fn.fmatter.select = function (cellval,opts, rwd, act) {
  4756. // jqGrid specific
  4757. cellval = cellval + "";
  4758. var oSelect = false, ret=[];
  4759. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)){
  4760. oSelect= opts.colModel.formatoptions.value;
  4761. } else if(!$.fmatter.isUndefined(opts.colModel.editoptions)){
  4762. oSelect= opts.colModel.editoptions.value;
  4763. }
  4764. if (oSelect) {
  4765. var msl = opts.colModel.editoptions.multiple === true ? true : false,
  4766. scell = [], sv;
  4767. if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  4768. if ($.fmatter.isString(oSelect)) {
  4769. // mybe here we can use some caching with care ????
  4770. var so = oSelect.split(";"), j=0;
  4771. for(var i=0; i<so.length;i++){
  4772. sv = so[i].split(":");
  4773. if(sv.length > 2 ) {
  4774. sv[1] = jQuery.map(sv,function(n,i){if(i>0) {return n;}}).join(":");
  4775. }
  4776. if(msl) {
  4777. if(jQuery.inArray(sv[0],scell)>-1) {
  4778. ret[j] = sv[1];
  4779. j++;
  4780. }
  4781. } else if($.trim(sv[0])==$.trim(cellval)) {
  4782. ret[0] = sv[1];
  4783. break;
  4784. }
  4785. }
  4786. } else if($.fmatter.isObject(oSelect)) {
  4787. // this is quicker
  4788. if(msl) {
  4789. ret = jQuery.map(scell, function(n, i){
  4790. return oSelect[n];
  4791. });
  4792. } else {
  4793. ret[0] = oSelect[cellval] || "";
  4794. }
  4795. }
  4796. }
  4797. cellval = ret.join(", ");
  4798. return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
  4799. };
  4800. $.fn.fmatter.rowactions = function(rid,gid,act,pos) {
  4801. var op ={
  4802. keys:false,
  4803. onEdit : null,
  4804. onSuccess: null,
  4805. afterSave:null,
  4806. onError: null,
  4807. afterRestore: null,
  4808. extraparam: {oper:'edit'},
  4809. url: null,
  4810. delOptions: {},
  4811. editOptions : {}
  4812. };
  4813. rid = $.jgrid.jqID( rid );
  4814. gid = $.jgrid.jqID( gid );
  4815. var cm = $('#'+gid)[0].p.colModel[pos];
  4816. if(!$.fmatter.isUndefined(cm.formatoptions)) {
  4817. op = $.extend(op,cm.formatoptions);
  4818. }
  4819. if( !$.fmatter.isUndefined($('#'+gid)[0].p.editOptions) ) {
  4820. op.editOptions = $('#'+gid)[0].p.editOptions;
  4821. }
  4822. if( !$.fmatter.isUndefined($('#'+gid)[0].p.delOptions) ) {
  4823. op.delOptions = $('#'+gid)[0].p.delOptions;
  4824. }
  4825. var saverow = function( rowid) {
  4826. if(op.afterSave) op.afterSave(rowid);
  4827. $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid + ".ui-jqgrid-btable:first").show();
  4828. $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid+ ".ui-jqgrid-btable:first").hide();
  4829. },
  4830. restorerow = function( rowid) {
  4831. if(op.afterRestore) op.afterRestore(rowid);
  4832. $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid+ ".ui-jqgrid-btable:first").show();
  4833. $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid+ ".ui-jqgrid-btable:first").hide();
  4834. };
  4835. switch(act)
  4836. {
  4837. case 'edit':
  4838. $('#'+gid).jqGrid('editRow',rid, op.keys, op.onEdit, op.onSuccess, op.url, op.extraparam, saverow, op.onError,restorerow);
  4839. $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid+ ".ui-jqgrid-btable:first").hide();
  4840. $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid+ ".ui-jqgrid-btable:first").show();
  4841. break;
  4842. case 'save':
  4843. if ( $('#'+gid).jqGrid('saveRow',rid, op.onSuccess,op.url, op.extraparam, saverow, op.onError,restorerow) ) {
  4844. $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid+ ".ui-jqgrid-btable:first").show();
  4845. $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid+ ".ui-jqgrid-btable:first").hide();
  4846. }
  4847. break;
  4848. case 'cancel' :
  4849. $('#'+gid).jqGrid('restoreRow',rid, restorerow);
  4850. $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid+ ".ui-jqgrid-btable:first").show();
  4851. $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid+ ".ui-jqgrid-btable:first").hide();
  4852. break;
  4853. case 'del':
  4854. $('#'+gid).jqGrid('delGridRow',rid, op.delOptions);
  4855. break;
  4856. case 'formedit':
  4857. $('#'+gid).jqGrid('setSelection',rid);
  4858. $('#'+gid).jqGrid('editGridRow',rid, op.editOptions);
  4859. break;
  4860. }
  4861. };
  4862. $.fn.fmatter.actions = function(cellval,opts, rwd) {
  4863. var op ={keys:false, editbutton:true, delbutton:true, editformbutton: false};
  4864. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  4865. op = $.extend(op,opts.colModel.formatoptions);
  4866. }
  4867. var rowid = opts.rowId, str="",ocl;
  4868. if(typeof(rowid) =='undefined' || $.fmatter.isEmpty(rowid)) {return "";}
  4869. if(op.editformbutton){
  4870. ocl = "onclick=jQuery.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','formedit',"+opts.pos+"); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "
  4871. str =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>";
  4872. } else if(op.editbutton){
  4873. ocl = "onclick=jQuery.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','edit',"+opts.pos+"); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover') ";
  4874. str =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>";
  4875. }
  4876. if(op.delbutton) {
  4877. ocl = "onclick=jQuery.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','del',"+opts.pos+"); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  4878. str = 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>";
  4879. }
  4880. ocl = "onclick=jQuery.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','save',"+opts.pos+"); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  4881. str = 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>";
  4882. ocl = "onclick=jQuery.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','cancel',"+opts.pos+"); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  4883. str = 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>";
  4884. return "<div style='margin-left:8px;'>" + str + "</div>";
  4885. };
  4886. $.unformat = function (cellval,options,pos,cnt) {
  4887. // specific for jqGrid only
  4888. var ret, formatType = options.colModel.formatter,
  4889. op =options.colModel.formatoptions || {}, sep,
  4890. re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  4891. unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
  4892. if(typeof unformatFunc !== 'undefined' && $.isFunction(unformatFunc) ) {
  4893. ret = unformatFunc($(cellval).text(), options, cellval);
  4894. } else if(!$.fmatter.isUndefined(formatType) && $.fmatter.isString(formatType) ) {
  4895. var opts = $.jgrid.formatter || {}, stripTag;
  4896. switch(formatType) {
  4897. case 'integer' :
  4898. op = $.extend({},opts.integer,op);
  4899. sep = op.thousandsSeparator.replace(re,"\\$1");
  4900. stripTag = new RegExp(sep, "g");
  4901. ret = $(cellval).text().replace(stripTag,'');
  4902. break;
  4903. case 'number' :
  4904. op = $.extend({},opts.number,op);
  4905. sep = op.thousandsSeparator.replace(re,"\\$1");
  4906. stripTag = new RegExp(sep, "g");
  4907. ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
  4908. break;
  4909. case 'currency':
  4910. op = $.extend({},opts.currency,op);
  4911. sep = op.thousandsSeparator.replace(re,"\\$1");
  4912. stripTag = new RegExp(sep, "g");
  4913. ret = $(cellval).text().replace(stripTag,'').replace(op.decimalSeparator,'.').replace(op.prefix,'').replace(op.suffix,'');
  4914. break;
  4915. case 'checkbox':
  4916. var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
  4917. ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
  4918. break;
  4919. case 'select' :
  4920. ret = $.unformat.select(cellval,options,pos,cnt);
  4921. break;
  4922. case 'actions':
  4923. return "";
  4924. default:
  4925. ret= $(cellval).text();
  4926. }
  4927. }
  4928. return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
  4929. };
  4930. $.unformat.select = function (cellval,options,pos,cnt) {
  4931. // Spacial case when we have local data and perform a sort
  4932. // cnt is set to true only in sortDataArray
  4933. var ret = [];
  4934. var cell = $(cellval).text();
  4935. if(cnt===true) {return cell;}
  4936. var op = $.extend({},options.colModel.editoptions);
  4937. if(op.value){
  4938. var oSelect = op.value,
  4939. msl = op.multiple === true ? true : false,
  4940. scell = [], sv;
  4941. if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  4942. if ($.fmatter.isString(oSelect)) {
  4943. var so = oSelect.split(";"), j=0;
  4944. for(var i=0; i<so.length;i++){
  4945. sv = so[i].split(":");
  4946. if(sv.length > 2 ) {
  4947. sv[1] = jQuery.map(sv,function(n,i){if(i>0) {return n;}}).join(":");
  4948. }
  4949. if(msl) {
  4950. if(jQuery.inArray(sv[1],scell)>-1) {
  4951. ret[j] = sv[0];
  4952. j++;
  4953. }
  4954. } else if($.trim(sv[1])==$.trim(cell)) {
  4955. ret[0] = sv[0];
  4956. break;
  4957. }
  4958. }
  4959. } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
  4960. if(!msl) {scell[0] = cell;}
  4961. ret = jQuery.map(scell, function(n){
  4962. var rv;
  4963. $.each(oSelect, function(i,val){
  4964. if (val == n) {
  4965. rv = i;
  4966. return false;
  4967. }
  4968. });
  4969. if( typeof(rv) != 'undefined' ) {return rv;}
  4970. });
  4971. }
  4972. return ret.join(", ");
  4973. } else {
  4974. return cell || "";
  4975. }
  4976. };
  4977. $.unformat.date = function (cellval, opts) {
  4978. var op = $.jgrid.formatter.date || {};
  4979. if(!$.fmatter.isUndefined(opts.formatoptions)) {
  4980. op = $.extend({},op,opts.formatoptions);
  4981. }
  4982. if(!$.fmatter.isEmpty(cellval)) {
  4983. return $.fmatter.util.DateFormat(op.newformat,cellval,op.srcformat,op);
  4984. } else {
  4985. return $.fn.fmatter.defaultFormat(cellval, opts);
  4986. }
  4987. };
  4988. })(jQuery);
  4989. ;(function($){
  4990. /*
  4991. * jqGrid common function
  4992. * Tony Tomov tony@trirand.com
  4993. * http://trirand.com/blog/
  4994. * Dual licensed under the MIT and GPL licenses:
  4995. * http://www.opensource.org/licenses/mit-license.php
  4996. * http://www.gnu.org/licenses/gpl-2.0.html
  4997. */
  4998. /*global jQuery, $ */
  4999. $.extend($.jgrid,{
  5000. // Modal functions
  5001. showModal : function(h) {
  5002. h.w.show();
  5003. },
  5004. closeModal : function(h) {
  5005. h.w.hide().attr("aria-hidden","true");
  5006. if(h.o) {h.o.remove();}
  5007. },
  5008. hideModal : function (selector,o) {
  5009. o = $.extend({jqm : true, gb :''}, o || {});
  5010. if(o.onClose) {
  5011. var oncret = o.onClose(selector);
  5012. if (typeof oncret == 'boolean' && !oncret ) { return; }
  5013. }
  5014. if ($.fn.jqm && o.jqm === true) {
  5015. $(selector).attr("aria-hidden","true").jqmHide();
  5016. } else {
  5017. if(o.gb !== '') {
  5018. try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){}
  5019. }
  5020. $(selector).hide().attr("aria-hidden","true");
  5021. }
  5022. },
  5023. //Helper functions
  5024. findPos : function(obj) {
  5025. var curleft = 0, curtop = 0;
  5026. if (obj.offsetParent) {
  5027. do {
  5028. curleft += obj.offsetLeft;
  5029. curtop += obj.offsetTop;
  5030. } while (obj = obj.offsetParent);
  5031. //do not change obj == obj.offsetParent
  5032. }
  5033. return [curleft,curtop];
  5034. },
  5035. createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) {
  5036. var mw = document.createElement('div'), rtlsup, self = this;
  5037. css = $.extend({}, css || {});
  5038. rtlsup = $(p.gbox).attr("dir") == "rtl" ? true : false;
  5039. mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog";
  5040. mw.id = aIDs.themodal;
  5041. var mh = document.createElement('div');
  5042. mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";
  5043. mh.id = aIDs.modalhead;
  5044. $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>");
  5045. var ahr= $("<a href='javascript:void(0)' class='ui-jqdialog-titlebar-close ui-corner-all'></a>")
  5046. .hover(function(){ahr.addClass('ui-state-hover');},
  5047. function(){ahr.removeClass('ui-state-hover');})
  5048. .append("<span class='ui-icon ui-icon-closethick'></span>");
  5049. $(mh).append(ahr);
  5050. if(rtlsup) {
  5051. mw.dir = "rtl";
  5052. $(".ui-jqdialog-title",mh).css("float","right");
  5053. $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em");
  5054. } else {
  5055. mw.dir = "ltr";
  5056. $(".ui-jqdialog-title",mh).css("float","left");
  5057. $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em");
  5058. }
  5059. var mc = document.createElement('div');
  5060. $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent);
  5061. $(mc).append(content);
  5062. mw.appendChild(mc);
  5063. $(mw).prepend(mh);
  5064. if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog
  5065. else if (typeof appendsel == "string")
  5066. $(appendsel).append(mw);
  5067. else {$(mw).insertBefore(insertSelector);}
  5068. $(mw).css(css);
  5069. if(typeof p.jqModal === 'undefined') {p.jqModal = true;} // internal use
  5070. var coord = {};
  5071. if ( $.fn.jqm && p.jqModal === true) {
  5072. if(p.left ===0 && p.top===0 && p.overlay) {
  5073. var pos = [];
  5074. pos = this.findPos(posSelector);
  5075. p.left = pos[0] + 4;
  5076. p.top = pos[1] + 4;
  5077. }
  5078. coord.top = p.top+"px";
  5079. coord.left = p.left;
  5080. } else if(p.left !==0 || p.top!==0) {
  5081. coord.left = p.left;
  5082. coord.top = p.top+"px";
  5083. }
  5084. $("a.ui-jqdialog-titlebar-close",mh).click(function(e){
  5085. var oncm = $("#"+aIDs.themodal).data("onClose") || p.onClose;
  5086. var gboxclose = $("#"+aIDs.themodal).data("gbox") || p.gbox;
  5087. self.hideModal("#"+aIDs.themodal,{gb:gboxclose,jqm:p.jqModal,onClose:oncm});
  5088. return false;
  5089. });
  5090. if (p.width === 0 || !p.width) {p.width = 300;}
  5091. if(p.height === 0 || !p.height) {p.height =200;}
  5092. if(!p.zIndex) {
  5093. var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index");
  5094. if(parentZ) {
  5095. p.zIndex = parseInt(parentZ,10)+1;
  5096. } else {
  5097. p.zIndex = 950;
  5098. }
  5099. }
  5100. var rtlt = 0;
  5101. if( rtlsup && coord.left && !appendsel) {
  5102. rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do
  5103. // just in case
  5104. coord.left = parseInt(coord.left,10) + parseInt(rtlt,10);
  5105. }
  5106. if(coord.left) { coord.left += "px"; }
  5107. $(mw).css($.extend({
  5108. width: isNaN(p.width) ? "auto": p.width+"px",
  5109. height:isNaN(p.height) ? "auto" : p.height + "px",
  5110. zIndex:p.zIndex,
  5111. overflow: 'hidden'
  5112. },coord))
  5113. .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"});
  5114. if(typeof p.drag == 'undefined') { p.drag=true;}
  5115. if(typeof p.resize == 'undefined') {p.resize=true;}
  5116. if (p.drag) {
  5117. $(mh).css('cursor','move');
  5118. if($.fn.jqDrag) {
  5119. $(mw).jqDrag(mh);
  5120. } else {
  5121. try {
  5122. $(mw).draggable({handle: $("#"+mh.id)});
  5123. } catch (e) {}
  5124. }
  5125. }
  5126. if(p.resize) {
  5127. if($.fn.jqResize) {
  5128. $(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se ui-icon-grip-diagonal-se'></div>");
  5129. $("#"+aIDs.themodal).jqResize(".jqResize",aIDs.scrollelm ? "#"+aIDs.scrollelm : false);
  5130. } else {
  5131. try {
  5132. $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+aIDs.scrollelm : false});
  5133. } catch (r) {}
  5134. }
  5135. }
  5136. if(p.closeOnEscape === true){
  5137. $(mw).keydown( function( e ) {
  5138. if( e.which == 27 ) {
  5139. var cone = $("#"+aIDs.themodal).data("onClose") || p.onClose;
  5140. self.hideModal(this,{gb:p.gbox,jqm:p.jqModal,onClose: cone});
  5141. }
  5142. });
  5143. }
  5144. },
  5145. viewModal : function (selector,o){
  5146. o = $.extend({
  5147. toTop: true,
  5148. overlay: 10,
  5149. modal: false,
  5150. overlayClass : 'ui-widget-overlay',
  5151. onShow: this.showModal,
  5152. onHide: this.closeModal,
  5153. gbox: '',
  5154. jqm : true,
  5155. jqM : true
  5156. }, o || {});
  5157. if ($.fn.jqm && o.jqm === true) {
  5158. if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); }
  5159. else {$(selector).attr("aria-hidden","false").jqmShow();}
  5160. } else {
  5161. if(o.gbox !== '') {
  5162. $(".jqgrid-overlay:first",o.gbox).show();
  5163. $(selector).data("gbox",o.gbox);
  5164. }
  5165. $(selector).show().attr("aria-hidden","false");
  5166. try{$(':input:visible',selector)[0].focus();}catch(_){}
  5167. }
  5168. },
  5169. info_dialog : function(caption, content,c_b, modalopt) {
  5170. var mopt = {
  5171. width:290,
  5172. height:'auto',
  5173. dataheight: 'auto',
  5174. drag: true,
  5175. resize: false,
  5176. caption:"<b>"+caption+"</b>",
  5177. left:250,
  5178. top:170,
  5179. zIndex : 1000,
  5180. jqModal : true,
  5181. modal : false,
  5182. closeOnEscape : true,
  5183. align: 'center',
  5184. buttonalign : 'center',
  5185. buttons : []
  5186. // {text:'textbutt', id:"buttid", onClick : function(){...}}
  5187. // 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...
  5188. };
  5189. $.extend(mopt,modalopt || {});
  5190. var jm = mopt.jqModal, self = this;
  5191. if($.fn.jqm && !jm) { jm = false; }
  5192. // in case there is no jqModal
  5193. var buttstr ="";
  5194. if(mopt.buttons.length > 0) {
  5195. for(var i=0;i<mopt.buttons.length;i++) {
  5196. if(typeof mopt.buttons[i].id == "undefined") { mopt.buttons[i].id = "info_button_"+i; }
  5197. buttstr += "<a href='javascript:void(0)' id='"+mopt.buttons[i].id+"' class='fm-button ui-state-default ui-corner-all'>"+mopt.buttons[i].text+"</a>";
  5198. }
  5199. }
  5200. var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px",
  5201. cn = "text-align:"+mopt.align+";";
  5202. var cnt = "<div id='info_id'>";
  5203. cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>";
  5204. 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 href='javascript:void(0)' id='closedialog' class='fm-button ui-state-default ui-corner-all'>"+c_b+"</a>"+buttstr+"</div>" :
  5205. 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>" : "";
  5206. cnt += "</div>";
  5207. try {
  5208. if($("#info_dialog").attr("aria-hidden") == "false") {
  5209. this.hideModal("#info_dialog",{jqm:jm});
  5210. }
  5211. $("#info_dialog").remove();
  5212. } catch (e){}
  5213. this.createModal({
  5214. themodal:'info_dialog',
  5215. modalhead:'info_head',
  5216. modalcontent:'info_content',
  5217. scrollelm: 'infocnt'},
  5218. cnt,
  5219. mopt,
  5220. '','',true
  5221. );
  5222. // attach onclick after inserting into the dom
  5223. if(buttstr) {
  5224. $.each(mopt.buttons,function(i){
  5225. $("#"+this.id,"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;});
  5226. });
  5227. }
  5228. $("#closedialog", "#info_id").click(function(e){
  5229. self.hideModal("#info_dialog",{jqm:jm});
  5230. return false;
  5231. });
  5232. $(".fm-button","#info_dialog").hover(
  5233. function(){$(this).addClass('ui-state-hover');},
  5234. function(){$(this).removeClass('ui-state-hover');}
  5235. );
  5236. if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); }
  5237. this.viewModal("#info_dialog",{
  5238. onHide: function(h) {
  5239. h.w.hide().remove();
  5240. if(h.o) { h.o.remove(); }
  5241. },
  5242. modal :mopt.modal,
  5243. jqm:jm
  5244. });
  5245. if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); }
  5246. try{ $("#info_dialog").focus();} catch (m){}
  5247. },
  5248. // Form Functions
  5249. createEl : function(eltype,options,vl,autowidth, ajaxso) {
  5250. var elem = "";
  5251. function bindEv (el, opt) {
  5252. if($.isFunction(opt.dataInit)) {
  5253. opt.dataInit(el);
  5254. }
  5255. if(opt.dataEvents) {
  5256. $.each(opt.dataEvents, function() {
  5257. if (this.data !== undefined) {
  5258. $(el).bind(this.type, this.data, this.fn);
  5259. } else {
  5260. $(el).bind(this.type, this.fn);
  5261. }
  5262. });
  5263. }
  5264. return opt;
  5265. }
  5266. function setAttributes(elm, atr, exl ) {
  5267. var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr'];
  5268. if(typeof(exl) != "undefined" && $.isArray(exl)) {
  5269. exclude = $.extend(exclude, exl);
  5270. }
  5271. $.each(atr, function(key, value){
  5272. if($.inArray(key, exclude) === -1) {
  5273. $(elm).attr(key,value);
  5274. }
  5275. });
  5276. if(!atr.hasOwnProperty('id')) {
  5277. $(elm).attr('id', $.jgrid.randId());
  5278. }
  5279. }
  5280. switch (eltype)
  5281. {
  5282. case "textarea" :
  5283. elem = document.createElement("textarea");
  5284. if(autowidth) {
  5285. if(!options.cols) { $(elem).css({width:"98%"});}
  5286. } else if (!options.cols) { options.cols = 20; }
  5287. if(!options.rows) { options.rows = 2; }
  5288. if(vl=='&nbsp;' || vl=='&#160;' || (vl.length==1 && vl.charCodeAt(0)==160)) {vl="";}
  5289. elem.value = vl;
  5290. setAttributes(elem, options);
  5291. options = bindEv(elem,options);
  5292. $(elem).attr({"role":"textbox","multiline":"true"});
  5293. break;
  5294. case "checkbox" : //what code for simple checkbox
  5295. elem = document.createElement("input");
  5296. elem.type = "checkbox";
  5297. if( !options.value ) {
  5298. var vl1 = vl.toLowerCase();
  5299. if(vl1.search(/(false|0|no|off|undefined)/i)<0 && vl1!=="") {
  5300. elem.checked=true;
  5301. elem.defaultChecked=true;
  5302. elem.value = vl;
  5303. } else {
  5304. elem.value = "on";
  5305. }
  5306. $(elem).attr("offval","off");
  5307. } else {
  5308. var cbval = options.value.split(":");
  5309. if(vl === cbval[0]) {
  5310. elem.checked=true;
  5311. elem.defaultChecked=true;
  5312. }
  5313. elem.value = cbval[0];
  5314. $(elem).attr("offval",cbval[1]);
  5315. }
  5316. setAttributes(elem, options, ['value']);
  5317. options = bindEv(elem,options);
  5318. $(elem).attr("role","checkbox");
  5319. break;
  5320. case "select" :
  5321. elem = document.createElement("select");
  5322. elem.setAttribute("role","select");
  5323. var msl, ovm = [];
  5324. if(options.multiple===true) {
  5325. msl = true;
  5326. elem.multiple="multiple";
  5327. $(elem).attr("aria-multiselectable","true");
  5328. } else { msl = false; }
  5329. if(typeof(options.dataUrl) != "undefined") {
  5330. $.ajax($.extend({
  5331. url: options.dataUrl,
  5332. type : "GET",
  5333. dataType: "html",
  5334. context: {elem:elem, options:options, vl:vl},
  5335. success: function(data,status){
  5336. var a, ovm = [], elem = this.elem, vl = this.vl,
  5337. options = $.extend({},this.options),
  5338. msl = options.multiple===true;
  5339. if(typeof(options.buildSelect) != "undefined") {
  5340. var b = options.buildSelect(data);
  5341. a = $(b).html();
  5342. } else {
  5343. a = $(data).html();
  5344. }
  5345. if(a) {
  5346. $(elem).append(a);
  5347. setAttributes(elem, options);
  5348. options = bindEv(elem,options);
  5349. if(typeof options.size === 'undefined') { options.size = msl ? 3 : 1;}
  5350. if(msl) {
  5351. ovm = vl.split(",");
  5352. ovm = $.map(ovm,function(n){return $.trim(n);});
  5353. } else {
  5354. ovm[0] = $.trim(vl);
  5355. }
  5356. //$(elem).attr(options);
  5357. setTimeout(function(){
  5358. $("option",elem).each(function(i){
  5359. //if(i===0) { this.selected = ""; }
  5360. $(this).attr("role","option");
  5361. if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) {
  5362. this.selected= "selected";
  5363. }
  5364. });
  5365. },0);
  5366. }
  5367. }
  5368. },ajaxso || {}));
  5369. } else if(options.value) {
  5370. var i;
  5371. if(typeof options.size === 'undefined') {
  5372. options.size = msl ? 3 : 1;
  5373. }
  5374. if(msl) {
  5375. ovm = vl.split(",");
  5376. ovm = $.map(ovm,function(n){return $.trim(n);});
  5377. }
  5378. if(typeof options.value === 'function') { options.value = options.value(); }
  5379. var so,sv, ov;
  5380. if(typeof options.value === 'string') {
  5381. so = options.value.split(";");
  5382. for(i=0; i<so.length;i++){
  5383. sv = so[i].split(":");
  5384. if(sv.length > 2 ) {
  5385. sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(":");
  5386. }
  5387. ov = document.createElement("option");
  5388. ov.setAttribute("role","option");
  5389. ov.value = sv[0]; ov.innerHTML = sv[1];
  5390. elem.appendChild(ov);
  5391. if (!msl && ($.trim(sv[0]) == $.trim(vl) || $.trim(sv[1]) == $.trim(vl))) { ov.selected ="selected"; }
  5392. if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";}
  5393. }
  5394. } else if (typeof options.value === 'object') {
  5395. var oSv = options.value;
  5396. for ( var key in oSv) {
  5397. if (oSv.hasOwnProperty(key ) ){
  5398. ov = document.createElement("option");
  5399. ov.setAttribute("role","option");
  5400. ov.value = key; ov.innerHTML = oSv[key];
  5401. elem.appendChild(ov);
  5402. if (!msl && ( $.trim(key) == $.trim(vl) || $.trim(oSv[key]) == $.trim(vl)) ) { ov.selected ="selected"; }
  5403. if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  5404. }
  5405. }
  5406. }
  5407. setAttributes(elem, options, ['value']);
  5408. options = bindEv(elem,options);
  5409. }
  5410. break;
  5411. case "text" :
  5412. case "password" :
  5413. case "button" :
  5414. var role;
  5415. if(eltype=="button") { role = "button"; }
  5416. else { role = "textbox"; }
  5417. elem = document.createElement("input");
  5418. elem.type = eltype;
  5419. elem.value = vl;
  5420. setAttributes(elem, options);
  5421. options = bindEv(elem,options);
  5422. if(eltype != "button"){
  5423. if(autowidth) {
  5424. if(!options.size) { $(elem).css({width:"98%"}); }
  5425. } else if (!options.size) { options.size = 20; }
  5426. }
  5427. $(elem).attr("role",role);
  5428. break;
  5429. case "image" :
  5430. case "file" :
  5431. elem = document.createElement("input");
  5432. elem.type = eltype;
  5433. setAttributes(elem, options);
  5434. options = bindEv(elem,options);
  5435. break;
  5436. case "custom" :
  5437. elem = document.createElement("span");
  5438. try {
  5439. if($.isFunction(options.custom_element)) {
  5440. var celm = options.custom_element.call(this,vl,options);
  5441. if(celm) {
  5442. celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
  5443. $(elem).empty().append(celm);
  5444. } else {
  5445. throw "e2";
  5446. }
  5447. } else {
  5448. throw "e1";
  5449. }
  5450. } catch (e) {
  5451. if (e=="e1") { this.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);}
  5452. if (e=="e2") { this.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  5453. else { this.info_dialog($.jgrid.errors.errcap,typeof(e)==="string"?e:e.message,$.jgrid.edit.bClose); }
  5454. }
  5455. break;
  5456. }
  5457. return elem;
  5458. },
  5459. // Date Validation Javascript
  5460. checkDate : function (format, date) {
  5461. var daysInFebruary = function(year){
  5462. // February has 29 days in any year evenly divisible by four,
  5463. // EXCEPT for centurial years which are not also divisible by 400.
  5464. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
  5465. },
  5466. DaysArray = function(n) {
  5467. for (var i = 1; i <= n; i++) {
  5468. this[i] = 31;
  5469. if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
  5470. if (i==2) {this[i] = 29;}
  5471. }
  5472. return this;
  5473. };
  5474. var tsp = {}, sep;
  5475. format = format.toLowerCase();
  5476. //we search for /,-,. for the date separator
  5477. if(format.indexOf("/") != -1) {
  5478. sep = "/";
  5479. } else if(format.indexOf("-") != -1) {
  5480. sep = "-";
  5481. } else if(format.indexOf(".") != -1) {
  5482. sep = ".";
  5483. } else {
  5484. sep = "/";
  5485. }
  5486. format = format.split(sep);
  5487. date = date.split(sep);
  5488. if (date.length != 3) { return false; }
  5489. var j=-1,yln, dln=-1, mln=-1;
  5490. for(var i=0;i<format.length;i++){
  5491. var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10);
  5492. tsp[format[i]] = dv;
  5493. yln = format[i];
  5494. if(yln.indexOf("y") != -1) { j=i; }
  5495. if(yln.indexOf("m") != -1) { mln=i; }
  5496. if(yln.indexOf("d") != -1) { dln=i; }
  5497. }
  5498. if (format[j] == "y" || format[j] == "yyyy") {
  5499. yln=4;
  5500. } else if(format[j] =="yy"){
  5501. yln = 2;
  5502. } else {
  5503. yln = -1;
  5504. }
  5505. var daysInMonth = DaysArray(12),
  5506. strDate;
  5507. if (j === -1) {
  5508. return false;
  5509. } else {
  5510. strDate = tsp[format[j]].toString();
  5511. if(yln == 2 && strDate.length == 1) {yln = 1;}
  5512. if (strDate.length != yln || (tsp[format[j]]===0 && date[j]!="00")){
  5513. return false;
  5514. }
  5515. }
  5516. if(mln === -1) {
  5517. return false;
  5518. } else {
  5519. strDate = tsp[format[mln]].toString();
  5520. if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){
  5521. return false;
  5522. }
  5523. }
  5524. if(dln === -1) {
  5525. return false;
  5526. } else {
  5527. strDate = tsp[format[dln]].toString();
  5528. 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]]]){
  5529. return false;
  5530. }
  5531. }
  5532. return true;
  5533. },
  5534. isEmpty : function(val)
  5535. {
  5536. if (val.match(/^\s+$/) || val === "") {
  5537. return true;
  5538. } else {
  5539. return false;
  5540. }
  5541. },
  5542. checkTime : function(time){
  5543. // checks only hh:ss (and optional am/pm)
  5544. var re = /^(\d{1,2}):(\d{2})([ap]m)?$/,regs;
  5545. if(!this.isEmpty(time))
  5546. {
  5547. regs = time.match(re);
  5548. if(regs) {
  5549. if(regs[3]) {
  5550. if(regs[1] < 1 || regs[1] > 12) { return false; }
  5551. } else {
  5552. if(regs[1] > 23) { return false; }
  5553. }
  5554. if(regs[2] > 59) {
  5555. return false;
  5556. }
  5557. } else {
  5558. return false;
  5559. }
  5560. }
  5561. return true;
  5562. },
  5563. checkValues : function(val, valref,g, customobject, nam) {
  5564. var edtrul,i, nm, dft, len;
  5565. if(typeof(customobject) === "undefined") {
  5566. if(typeof(valref)=='string'){
  5567. for( i =0, len=g.p.colModel.length;i<len; i++){
  5568. if(g.p.colModel[i].name==valref) {
  5569. edtrul = g.p.colModel[i].editrules;
  5570. valref = i;
  5571. try { nm = g.p.colModel[i].formoptions.label; } catch (e) {}
  5572. break;
  5573. }
  5574. }
  5575. } else if(valref >=0) {
  5576. edtrul = g.p.colModel[valref].editrules;
  5577. }
  5578. } else {
  5579. edtrul = customobject;
  5580. nm = nam===undefined ? "_" : nam;
  5581. }
  5582. if(edtrul) {
  5583. if(!nm) { nm = g.p.colNames[valref]; }
  5584. if(edtrul.required === true) {
  5585. if( this.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; }
  5586. }
  5587. // force required
  5588. var rqfield = edtrul.required === false ? false : true;
  5589. if(edtrul.number === true) {
  5590. if( !(rqfield === false && this.isEmpty(val)) ) {
  5591. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; }
  5592. }
  5593. }
  5594. if(typeof edtrul.minValue != 'undefined' && !isNaN(edtrul.minValue)) {
  5595. if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];}
  5596. }
  5597. if(typeof edtrul.maxValue != 'undefined' && !isNaN(edtrul.maxValue)) {
  5598. if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];}
  5599. }
  5600. var filter;
  5601. if(edtrul.email === true) {
  5602. if( !(rqfield === false && this.isEmpty(val)) ) {
  5603. // taken from $ Validate plugin
  5604. 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;
  5605. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];}
  5606. }
  5607. }
  5608. if(edtrul.integer === true) {
  5609. if( !(rqfield === false && this.isEmpty(val)) ) {
  5610. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; }
  5611. if ((val % 1 !== 0) || (val.indexOf('.') != -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];}
  5612. }
  5613. }
  5614. if(edtrul.date === true) {
  5615. if( !(rqfield === false && this.isEmpty(val)) ) {
  5616. if(g.p.colModel[valref].formatoptions && g.p.colModel[valref].formatoptions.newformat) {
  5617. dft = g.p.colModel[valref].formatoptions.newformat;
  5618. } else {
  5619. dft = g.p.colModel[valref].datefmt || "Y-m-d";
  5620. }
  5621. if(!this.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; }
  5622. }
  5623. }
  5624. if(edtrul.time === true) {
  5625. if( !(rqfield === false && this.isEmpty(val)) ) {
  5626. if(!this.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; }
  5627. }
  5628. }
  5629. if(edtrul.url === true) {
  5630. if( !(rqfield === false && this.isEmpty(val)) ) {
  5631. filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  5632. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];}
  5633. }
  5634. }
  5635. if(edtrul.custom === true) {
  5636. if( !(rqfield === false && this.isEmpty(val)) ) {
  5637. if($.isFunction(edtrul.custom_func)) {
  5638. var ret = edtrul.custom_func.call(g,val,nm);
  5639. if($.isArray(ret)) {
  5640. return ret;
  5641. } else {
  5642. return [false,$.jgrid.edit.msg.customarray,""];
  5643. }
  5644. } else {
  5645. return [false,$.jgrid.edit.msg.customfcheck,""];
  5646. }
  5647. }
  5648. }
  5649. }
  5650. return [true,"",""];
  5651. }
  5652. });
  5653. })(jQuery);/*
  5654. * jqFilter jQuery jqGrid filter addon.
  5655. * Copyright (c) 2011, Tony Tomov, tony@trirand.com
  5656. * Dual licensed under the MIT and GPL licenses
  5657. * http://www.opensource.org/licenses/mit-license.php
  5658. * http://www.gnu.org/licenses/gpl-2.0.html
  5659. *
  5660. * The work is inspired from this Stefan Pirvu
  5661. * http://www.codeproject.com/KB/scripting/json-filtering.aspx
  5662. *
  5663. * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter:
  5664. { "groupOp": "AND",
  5665. "groups" : [
  5666. { "groupOp": "OR",
  5667. "rules": [
  5668. { "field": "name", "op": "eq", "data": "England" },
  5669. { "field": "id", "op": "le", "data": "5"}
  5670. ]
  5671. }
  5672. ],
  5673. "rules": [
  5674. { "field": "name", "op": "eq", "data": "Romania" },
  5675. { "field": "id", "op": "le", "data": "1"}
  5676. ]
  5677. }
  5678. */
  5679. /*global jQuery, $, window, navigator */
  5680. (function ($) {
  5681. $.fn.jqFilter = function( arg ) {
  5682. if (typeof arg === 'string') {
  5683. var fn = $.fn.jqFilter[arg];
  5684. if (!fn) {
  5685. throw ("jqFilter - No such method: " + arg);
  5686. }
  5687. var args = $.makeArray(arguments).slice(1);
  5688. return fn.apply(this,args);
  5689. }
  5690. var p = $.extend(true,{
  5691. filter: null,
  5692. columns: [],
  5693. onChange : null,
  5694. afterRedraw : null,
  5695. checkValues : null,
  5696. error: false,
  5697. errmsg : "",
  5698. errorcheck : true,
  5699. showQuery : true,
  5700. sopt : null,
  5701. ops : [
  5702. {"name": "eq", "description": "equal", "operator":"="},
  5703. {"name": "ne", "description": "not equal", "operator":"<>"},
  5704. {"name": "lt", "description": "less", "operator":"<"},
  5705. {"name": "le", "description": "less or equal","operator":"<="},
  5706. {"name": "gt", "description": "greater", "operator":">"},
  5707. {"name": "ge", "description": "greater or equal", "operator":">="},
  5708. {"name": "bw", "description": "begins with", "operator":"LIKE"},
  5709. {"name": "bn", "description": "does not begin with", "operator":"NOT LIKE"},
  5710. {"name": "in", "description": "in", "operator":"IN"},
  5711. {"name": "ni", "description": "not in", "operator":"NOT IN"},
  5712. {"name": "ew", "description": "ends with", "operator":"LIKE"},
  5713. {"name": "en", "description": "does not end with", "operator":"NOT LIKE"},
  5714. {"name": "cn", "description": "contains", "operator":"LIKE"},
  5715. {"name": "nc", "description": "does not contain", "operator":"NOT LIKE"},
  5716. {"name": "nu", "description": "is null", "operator":"IS NULL"},
  5717. {"name": "nn", "description": "is not null", "operator":"IS NOT NULL"}
  5718. ],
  5719. numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  5720. stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  5721. _gridsopt : [], // grid translated strings, do not tuch
  5722. groupOps : ["AND", "OR"],
  5723. groupButton : true,
  5724. ruleButtons : true,
  5725. direction : "ltr"
  5726. }, arg || {});
  5727. return this.each( function() {
  5728. if (this.filter) {return;}
  5729. this.p = p;
  5730. // setup filter in case if they is not defined
  5731. if (this.p.filter === null || this.p.filter === undefined) {
  5732. this.p.filter = {
  5733. groupOp: this.p.groupOps[0],
  5734. rules: [],
  5735. groups: []
  5736. };
  5737. }
  5738. var i, len = this.p.columns.length, cl,
  5739. isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  5740. // translating the options
  5741. if(this.p._gridsopt.length) {
  5742. // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
  5743. for(i=0;i<this.p._gridsopt.length;i++) {
  5744. this.p.ops[i].description = this.p._gridsopt[i];
  5745. }
  5746. }
  5747. this.p.initFilter = $.extend(true,{},this.p.filter);
  5748. // set default values for the columns if they are not set
  5749. if( !len ) {return;}
  5750. for(i=0; i < len; i++) {
  5751. cl = this.p.columns[i];
  5752. if( cl.stype ) {
  5753. // grid compatibility
  5754. cl.inputtype = cl.stype;
  5755. } else if(!cl.inputtype) {
  5756. cl.inputtype = 'text';
  5757. }
  5758. if( cl.sorttype ) {
  5759. // grid compatibility
  5760. cl.searchtype = cl.sorttype;
  5761. } else if (!cl.searchtype) {
  5762. cl.searchtype = 'string';
  5763. }
  5764. if(cl.hidden === undefined) {
  5765. // jqGrid compatibility
  5766. cl.hidden = false;
  5767. }
  5768. if(!cl.label) {
  5769. cl.label = cl.name;
  5770. }
  5771. if(cl.index) {
  5772. cl.name = cl.index;
  5773. }
  5774. if(!cl.hasOwnProperty('searchoptions')) {
  5775. cl.searchoptions = {};
  5776. }
  5777. if(!cl.hasOwnProperty('searchrules')) {
  5778. cl.searchrules = {};
  5779. }
  5780. }
  5781. if(this.p.showQuery) {
  5782. $(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>");
  5783. }
  5784. /*
  5785. *Perform checking.
  5786. *
  5787. */
  5788. var checkData = function(val, colModelItem) {
  5789. var ret = [true,""];
  5790. if($.isFunction(colModelItem.searchrules)) {
  5791. ret = colModelItem.searchrules(val, colModelItem);
  5792. } else if($.jgrid && $.jgrid.checkValues) {
  5793. try {
  5794. ret = $.jgrid.checkValues(val, -1, null, colModelItem.searchrules, colModelItem.label);
  5795. } catch (e) {}
  5796. }
  5797. if(ret && ret.length && ret[0] === false) {
  5798. p.error = !ret[0];
  5799. p.errmsg = ret[1];
  5800. }
  5801. };
  5802. /* moving to common
  5803. randId = function() {
  5804. return Math.floor(Math.random()*10000).toString();
  5805. };
  5806. */
  5807. this.onchange = function ( ){
  5808. // clear any error
  5809. this.p.error = false;
  5810. this.p.errmsg="";
  5811. return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false;
  5812. };
  5813. /*
  5814. * Redraw the filter every time when new field is added/deleted
  5815. * and field is changed
  5816. */
  5817. this.reDraw = function() {
  5818. $("table.group:first",this).remove();
  5819. var t = this.createTableForGroup(p.filter, null);
  5820. $(this).append(t);
  5821. if($.isFunction(this.p.afterRedraw) ) {
  5822. this.p.afterRedraw.call(this, this.p);
  5823. }
  5824. };
  5825. /*
  5826. * Creates a grouping data for the filter
  5827. * @param group - object
  5828. * @param parentgroup - object
  5829. */
  5830. this.createTableForGroup = function(group, parentgroup) {
  5831. var that = this, i;
  5832. // this table will hold all the group (tables) and rules (rows)
  5833. var table = $("<table class='group ui-widget ui-widget-content' style='border:0px none;'><tbody></tbody></table>"),
  5834. // create error message row
  5835. align = "left";
  5836. if(this.p.direction == "rtl") {
  5837. align = "right";
  5838. table.attr("dir","rtl");
  5839. }
  5840. if(parentgroup === null) {
  5841. table.append("<tr class='error' style='display:none;'><th colspan='5' class='ui-state-error' align='"+align+"'></th></tr>");
  5842. }
  5843. var tr = $("<tr></tr>");
  5844. table.append(tr);
  5845. // this header will hold the group operator type and group action buttons for
  5846. // creating subgroup "+ {}", creating rule "+" or deleting the group "-"
  5847. var th = $("<th colspan='5' align='"+align+"'></th>");
  5848. tr.append(th);
  5849. if(this.p.ruleButtons === true) {
  5850. // dropdown for: choosing group operator type
  5851. var groupOpSelect = $("<select class='opsel'></select>");
  5852. th.append(groupOpSelect);
  5853. // populate dropdown with all posible group operators: or, and
  5854. var str= "", selected;
  5855. for (i = 0; i < p.groupOps.length; i++) {
  5856. selected = group.groupOp === that.p.groupOps[i] ? " selected='selected'" :"";
  5857. str += "<option value='"+that.p.groupOps[i]+"'" + selected+">"+that.p.groupOps[i]+"</option>";
  5858. }
  5859. groupOpSelect
  5860. .append(str)
  5861. .bind('change',function() {
  5862. group.groupOp = $(groupOpSelect).val();
  5863. that.onchange(); // signals that the filter has changed
  5864. });
  5865. }
  5866. // button for adding a new subgroup
  5867. var inputAddSubgroup ="<span></span>";
  5868. if(this.p.groupButton) {
  5869. inputAddSubgroup = $("<input type='button' value='+ {}' title='Add subgroup' class='add-group'/>");
  5870. inputAddSubgroup.bind('click',function() {
  5871. if (group.groups === undefined ) {
  5872. group.groups = [];
  5873. }
  5874. group.groups.push({
  5875. groupOp: p.groupOps[0],
  5876. rules: [],
  5877. groups: []
  5878. }); // adding a new group
  5879. that.reDraw(); // the html has changed, force reDraw
  5880. that.onchange(); // signals that the filter has changed
  5881. return false;
  5882. });
  5883. }
  5884. th.append(inputAddSubgroup);
  5885. if(this.p.ruleButtons === true) {
  5886. // button for adding a new rule
  5887. var inputAddRule = $("<input type='button' value='+' title='Add rule' class='add-rule ui-add'/>"), cm;
  5888. inputAddRule.bind('click',function() {
  5889. //if(!group) { group = {};}
  5890. if (group.rules === undefined) {
  5891. group.rules = [];
  5892. }
  5893. for (i = 0; i < that.p.columns.length; i++) {
  5894. // but show only serchable and serchhidden = true fields
  5895. var searchable = (typeof that.p.columns[i].search === 'undefined') ? true: that.p.columns[i].search ,
  5896. hidden = (that.p.columns[i].hidden === true),
  5897. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  5898. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  5899. cm = that.p.columns[i];
  5900. break;
  5901. }
  5902. }
  5903. var opr;
  5904. if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;}
  5905. else if(that.p.sopt) { opr= that.p.sopt; }
  5906. else if (cm.searchtype === 'string') {opr = that.p.stropts;}
  5907. else {opr = that.p.numopts;}
  5908. group.rules.push({
  5909. field: cm.name,
  5910. op: opr[0],
  5911. data: ""
  5912. }); // adding a new rule
  5913. that.reDraw(); // the html has changed, force reDraw
  5914. // for the moment no change have been made to the rule, so
  5915. // this will not trigger onchange event
  5916. return false;
  5917. });
  5918. th.append(inputAddRule);
  5919. }
  5920. // button for delete the group
  5921. if (parentgroup !== null) { // ignore the first group
  5922. var inputDeleteGroup = $("<input type='button' value='-' title='Delete group' class='delete-group'/>");
  5923. th.append(inputDeleteGroup);
  5924. inputDeleteGroup.bind('click',function() {
  5925. // remove group from parent
  5926. for (i = 0; i < parentgroup.groups.length; i++) {
  5927. if (parentgroup.groups[i] === group) {
  5928. parentgroup.groups.splice(i, 1);
  5929. break;
  5930. }
  5931. }
  5932. that.reDraw(); // the html has changed, force reDraw
  5933. that.onchange(); // signals that the filter has changed
  5934. return false;
  5935. });
  5936. }
  5937. // append subgroup rows
  5938. if (group.groups !== undefined) {
  5939. for (i = 0; i < group.groups.length; i++) {
  5940. var trHolderForSubgroup = $("<tr></tr>");
  5941. table.append(trHolderForSubgroup);
  5942. var tdFirstHolderForSubgroup = $("<td class='first'></td>");
  5943. trHolderForSubgroup.append(tdFirstHolderForSubgroup);
  5944. var tdMainHolderForSubgroup = $("<td colspan='4'></td>");
  5945. tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group));
  5946. trHolderForSubgroup.append(tdMainHolderForSubgroup);
  5947. }
  5948. }
  5949. if(group.groupOp === undefined) {
  5950. group.groupOp = that.p.groupOps[0];
  5951. }
  5952. // append rules rows
  5953. if (group.rules !== undefined) {
  5954. for (i = 0; i < group.rules.length; i++) {
  5955. table.append(
  5956. this.createTableRowForRule(group.rules[i], group)
  5957. );
  5958. }
  5959. }
  5960. return table;
  5961. };
  5962. /*
  5963. * Create the rule data for the filter
  5964. */
  5965. this.createTableRowForRule = function(rule, group ) {
  5966. // save current entity in a variable so that it could
  5967. // be referenced in anonimous method calls
  5968. var that=this, tr = $("<tr></tr>"),
  5969. //document.createElement("tr"),
  5970. // first column used for padding
  5971. //tdFirstHolderForRule = document.createElement("td"),
  5972. i, op, trpar, cm, str="", selected;
  5973. //tdFirstHolderForRule.setAttribute("class", "first");
  5974. tr.append("<td class='first'></td>");
  5975. // create field container
  5976. var ruleFieldTd = $("<td class='columns'></td>");
  5977. tr.append(ruleFieldTd);
  5978. // dropdown for: choosing field
  5979. var ruleFieldSelect = $("<select></select>"), ina, aoprs = [];
  5980. ruleFieldTd.append(ruleFieldSelect);
  5981. ruleFieldSelect.bind('change',function() {
  5982. rule.field = $(ruleFieldSelect).val();
  5983. trpar = $(this).parents("tr:first");
  5984. for (i=0;i<that.p.columns.length;i++) {
  5985. if(that.p.columns[i].name === rule.field) {
  5986. cm = that.p.columns[i];
  5987. break;
  5988. }
  5989. }
  5990. if(!cm) {return;}
  5991. cm.searchoptions.id = $.jgrid.randId();
  5992. if(isIE && cm.inputtype === "text") {
  5993. if(!cm.searchoptions.size) {
  5994. cm.searchoptions.size = 10;
  5995. }
  5996. }
  5997. var elm = $.jgrid.createEl(cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions, true);
  5998. $(elm).addClass("input-elm");
  5999. //that.createElement(rule, "");
  6000. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6001. else if(that.p.sopt) { op= that.p.sopt; }
  6002. else if (cm.searchtype === 'string') {op = that.p.stropts;}
  6003. else {op = that.p.numopts;}
  6004. // operators
  6005. var s ="", so = 0;
  6006. aoprs = [];
  6007. $.each(that.p.ops, function() { aoprs.push(this.name) });
  6008. for ( i = 0 ; i < op.length; i++) {
  6009. ina = $.inArray(op[i],aoprs);
  6010. if(ina !== -1) {
  6011. if(so===0) {
  6012. rule.op = that.p.ops[ina].name;
  6013. }
  6014. s += "<option value='"+that.p.ops[ina].name+"'>"+that.p.ops[ina].description+"</option>";
  6015. so++;
  6016. }
  6017. }
  6018. $(".selectopts",trpar).empty().append( s );
  6019. $(".selectopts",trpar)[0].selectedIndex = 0;
  6020. if( $.browser.msie && $.browser.version < 9) {
  6021. var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth) + 1;
  6022. $(".selectopts",trpar).width( sw );
  6023. $(".selectopts",trpar).css("width","auto");
  6024. }
  6025. // data
  6026. $(".data",trpar).empty().append( elm );
  6027. $(".input-elm",trpar).bind('change',function() {
  6028. rule.data = $(this).val();
  6029. that.onchange(); // signals that the filter has changed
  6030. });
  6031. setTimeout(function(){ //IE, Opera, Chrome
  6032. rule.data = $(elm).val();
  6033. that.onchange(); // signals that the filter has changed
  6034. }, 0);
  6035. });
  6036. // populate drop down with user provided column definitions
  6037. var j=0;
  6038. for (i = 0; i < that.p.columns.length; i++) {
  6039. // but show only serchable and serchhidden = true fields
  6040. var searchable = (typeof that.p.columns[i].search === 'undefined') ? true: that.p.columns[i].search ,
  6041. hidden = (that.p.columns[i].hidden === true),
  6042. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6043. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6044. selected = "";
  6045. if(rule.field === that.p.columns[i].name) {
  6046. selected = " selected='selected'";
  6047. j=i;
  6048. }
  6049. str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>";
  6050. }
  6051. }
  6052. ruleFieldSelect.append( str );
  6053. // create operator container
  6054. var ruleOperatorTd = $("<td class='operators'></td>");
  6055. tr.append(ruleOperatorTd);
  6056. cm = p.columns[j];
  6057. // create it here so it can be referentiated in the onchange event
  6058. //var RD = that.createElement(rule, rule.data);
  6059. cm.searchoptions.id = $.jgrid.randId();
  6060. if(isIE && cm.inputtype === "text") {
  6061. if(!cm.searchoptions.size) {
  6062. cm.searchoptions.size = 10;
  6063. }
  6064. }
  6065. var ruleDataInput = $.jgrid.createEl(cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions, true);
  6066. // dropdown for: choosing operator
  6067. var ruleOperatorSelect = $("<select class='selectopts'></select>");
  6068. ruleOperatorTd.append(ruleOperatorSelect);
  6069. ruleOperatorSelect.bind('change',function() {
  6070. rule.op = $(ruleOperatorSelect).val();
  6071. trpar = $(this).parents("tr:first");
  6072. var rd = $(".input-elm",trpar)[0];
  6073. if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null"
  6074. rule.data = "";
  6075. rd.value = "";
  6076. rd.setAttribute("readonly", "true");
  6077. rd.setAttribute("disabled", "true");
  6078. } else {
  6079. rd.removeAttribute("readonly");
  6080. rd.removeAttribute("disabled");
  6081. }
  6082. that.onchange(); // signals that the filter has changed
  6083. });
  6084. // populate drop down with all available operators
  6085. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6086. else if(that.p.sopt) { op= that.p.sopt; }
  6087. else if (cm.searchtype === 'string') {op = p.stropts;}
  6088. else {op = that.p.numopts;}
  6089. str="";
  6090. $.each(that.p.ops, function() { aoprs.push(this.name) });
  6091. for ( i = 0; i < op.length; i++) {
  6092. ina = $.inArray(op[i],aoprs);
  6093. if(ina !== -1) {
  6094. selected = rule.op === that.p.ops[ina].name ? " selected='selected'" : "";
  6095. str += "<option value='"+that.p.ops[ina].name+"'"+selected+">"+that.p.ops[ina].description+"</option>";
  6096. }
  6097. }
  6098. ruleOperatorSelect.append( str );
  6099. // create data container
  6100. var ruleDataTd = $("<td class='data'></td>");
  6101. tr.append(ruleDataTd);
  6102. // textbox for: data
  6103. // is created previously
  6104. //ruleDataInput.setAttribute("type", "text");
  6105. ruleDataTd.append(ruleDataInput);
  6106. $(ruleDataInput)
  6107. .addClass("input-elm")
  6108. .bind('change', function() {
  6109. rule.data = $(this).val();
  6110. that.onchange(); // signals that the filter has changed
  6111. });
  6112. // create action container
  6113. var ruleDeleteTd = $("<td></td>");
  6114. tr.append(ruleDeleteTd);
  6115. // create button for: delete rule
  6116. if(this.p.ruleButtons === true) {
  6117. var ruleDeleteInput = $("<input type='button' value='-' title='Delete rule' class='delete-rule ui-del'/>");
  6118. ruleDeleteTd.append(ruleDeleteInput);
  6119. //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}});
  6120. ruleDeleteInput.bind('click',function() {
  6121. // remove rule from group
  6122. for (i = 0; i < group.rules.length; i++) {
  6123. if (group.rules[i] === rule) {
  6124. group.rules.splice(i, 1);
  6125. break;
  6126. }
  6127. }
  6128. that.reDraw(); // the html has changed, force reDraw
  6129. that.onchange(); // signals that the filter has changed
  6130. return false;
  6131. });
  6132. }
  6133. return tr;
  6134. };
  6135. this.getStringForGroup = function(group) {
  6136. var s = "(", index;
  6137. if (group.groups !== undefined) {
  6138. for (index = 0; index < group.groups.length; index++) {
  6139. if (s.length > 1) {
  6140. s += " " + group.groupOp + " ";
  6141. }
  6142. try {
  6143. s += this.getStringForGroup(group.groups[index]);
  6144. } catch (eg) {alert(eg);}
  6145. }
  6146. }
  6147. if (group.rules !== undefined) {
  6148. try{
  6149. for (index = 0; index < group.rules.length; index++) {
  6150. if (s.length > 1) {
  6151. s += " " + group.groupOp + " ";
  6152. }
  6153. s += this.getStringForRule(group.rules[index]);
  6154. }
  6155. } catch (e) {alert(e);}
  6156. }
  6157. s += ")";
  6158. if (s === "()") {
  6159. return ""; // ignore groups that don't have rules
  6160. } else {
  6161. return s;
  6162. }
  6163. };
  6164. this.getStringForRule = function(rule) {
  6165. var opUF = "",opC="", i, cm, ret, val,
  6166. numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid
  6167. for (i = 0; i < this.p.ops.length; i++) {
  6168. if (this.p.ops[i].name === rule.op) {
  6169. opUF = this.p.ops[i].operator;
  6170. opC = this.p.ops[i].name;
  6171. break;
  6172. }
  6173. }
  6174. for (i=0; i<this.p.columns.length; i++) {
  6175. if(this.p.columns[i].name === rule.field) {
  6176. cm = this.p.columns[i];
  6177. break;
  6178. }
  6179. }
  6180. val = rule.data;
  6181. if(opC === 'bw' || opC === 'bn') { val = val+"%"; }
  6182. if(opC === 'ew' || opC === 'en') { val = "%"+val; }
  6183. if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; }
  6184. if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; }
  6185. if(p.errorcheck) { checkData(rule.data, cm); }
  6186. if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; }
  6187. else { ret = rule.field + " " + opUF + " \"" + val + "\""; }
  6188. return ret;
  6189. };
  6190. this.resetFilter = function () {
  6191. this.p.filter = $.extend(true,{},this.p.initFilter);
  6192. this.reDraw();
  6193. this.onchange();
  6194. };
  6195. this.hideError = function() {
  6196. $("th.ui-state-error", this).html("");
  6197. $("tr.error", this).hide();
  6198. };
  6199. this.showError = function() {
  6200. $("th.ui-state-error", this).html(this.p.errmsg);
  6201. $("tr.error", this).show();
  6202. };
  6203. this.toUserFriendlyString = function() {
  6204. return this.getStringForGroup(p.filter);
  6205. };
  6206. this.toString = function() {
  6207. // this will obtain a string that can be used to match an item.
  6208. var that = this;
  6209. function getStringRule(rule) {
  6210. if(that.p.errorcheck) {
  6211. var i, cm;
  6212. for (i=0; i<that.p.columns.length; i++) {
  6213. if(that.p.columns[i].name === rule.field) {
  6214. cm = that.p.columns[i];
  6215. break;
  6216. }
  6217. }
  6218. if(cm) {checkData(rule.data, cm);}
  6219. }
  6220. return rule.op + "(item." + rule.field + ",'" + rule.data + "')";
  6221. }
  6222. function getStringForGroup(group) {
  6223. var s = "(", index;
  6224. if (group.groups !== undefined) {
  6225. for (index = 0; index < group.groups.length; index++) {
  6226. if (s.length > 1) {
  6227. if (group.groupOp === "OR") {
  6228. s += " || ";
  6229. }
  6230. else {
  6231. s += " && ";
  6232. }
  6233. }
  6234. s += getStringForGroup(group.groups[index]);
  6235. }
  6236. }
  6237. if (group.rules !== undefined) {
  6238. for (index = 0; index < group.rules.length; index++) {
  6239. if (s.length > 1) {
  6240. if (group.groupOp === "OR") {
  6241. s += " || ";
  6242. }
  6243. else {
  6244. s += " && ";
  6245. }
  6246. }
  6247. s += getStringRule(group.rules[index]);
  6248. }
  6249. }
  6250. s += ")";
  6251. if (s === "()") {
  6252. return ""; // ignore groups that don't have rules
  6253. } else {
  6254. return s;
  6255. }
  6256. }
  6257. return getStringForGroup(this.p.filter);
  6258. };
  6259. // Here we init the filter
  6260. this.reDraw();
  6261. if(this.p.showQuery) {
  6262. this.onchange();
  6263. }
  6264. // mark is as created so that it will not be created twice on this element
  6265. this.filter = true;
  6266. });
  6267. };
  6268. $.extend($.fn.jqFilter,{
  6269. /*
  6270. * Return SQL like string. Can be used directly
  6271. */
  6272. toSQLString : function()
  6273. {
  6274. var s ="";
  6275. this.each(function(){
  6276. s = this.toUserFriendlyString();
  6277. });
  6278. return s;
  6279. },
  6280. /*
  6281. * Return filter data as object.
  6282. */
  6283. filterData : function()
  6284. {
  6285. var s;
  6286. this.each(function(){
  6287. s = this.p.filter;
  6288. });
  6289. return s;
  6290. },
  6291. getParameter : function (param) {
  6292. if(param !== undefined) {
  6293. if (this.p.hasOwnProperty(param) ) {
  6294. return this.p[param];
  6295. }
  6296. }
  6297. return this.p;
  6298. },
  6299. resetFilter: function() {
  6300. return this.each(function(){
  6301. this.resetFilter();
  6302. });
  6303. },
  6304. addFilter: function (pfilter) {
  6305. if (typeof pfilter === "string") {
  6306. pfilter = jQuery.jgrid.parse( pfilter );
  6307. }
  6308. this.each(function(){
  6309. this.p.filter = pfilter;
  6310. this.reDraw();
  6311. this.onchange();
  6312. });
  6313. }
  6314. });
  6315. })(jQuery);
  6316. (function($){
  6317. /**
  6318. * jqGrid extension for form editing Grid Data
  6319. * Tony Tomov tony@trirand.com
  6320. * http://trirand.com/blog/
  6321. * Dual licensed under the MIT and GPL licenses:
  6322. * http://www.opensource.org/licenses/mit-license.php
  6323. * http://www.gnu.org/licenses/gpl-2.0.html
  6324. **/
  6325. /*global xmlJsonClass, jQuery, $ */
  6326. var rp_ge = {};
  6327. $.jgrid.extend({
  6328. searchGrid : function (p) {
  6329. p = $.extend({
  6330. recreateFilter: false,
  6331. drag: true,
  6332. sField:'searchField',
  6333. sValue:'searchString',
  6334. sOper: 'searchOper',
  6335. sFilter: 'filters',
  6336. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  6337. beforeShowSearch: null,
  6338. afterShowSearch : null,
  6339. onInitializeSearch: null,
  6340. afterRedraw : null,
  6341. closeAfterSearch : false,
  6342. closeAfterReset: false,
  6343. closeOnEscape : false,
  6344. multipleSearch : false,
  6345. multipleGroup : false,
  6346. //cloneSearchRowOnAdd: true,
  6347. top : 0,
  6348. left: 0,
  6349. jqModal : true,
  6350. modal: false,
  6351. resize : true,
  6352. width: 450,
  6353. height: 'auto',
  6354. dataheight: 'auto',
  6355. showQuery: false,
  6356. errorcheck : true,
  6357. // translation
  6358. // if you want to change or remove the order change it in sopt
  6359. // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'],
  6360. sopt: null,
  6361. stringResult: undefined,
  6362. onClose : null,
  6363. onSearch : null,
  6364. onReset : null,
  6365. toTop : true,
  6366. overlay : 30,
  6367. columns : [],
  6368. tmplNames : null,
  6369. tmplFilters : null,
  6370. // translations - later in lang file
  6371. tmplLabel : ' Template: ',
  6372. showOnLoad: false,
  6373. layer: null
  6374. }, $.jgrid.search, p || {});
  6375. return this.each(function() {
  6376. var $t = this;
  6377. if(!$t.grid) {return;}
  6378. var fid = "fbox_"+$t.p.id,
  6379. showFrm = true,
  6380. IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid},
  6381. defaultFilters = $t.p.postData[p.sFilter];
  6382. if(typeof(defaultFilters) === "string") {
  6383. defaultFilters = $.jgrid.parse( defaultFilters );
  6384. }
  6385. if(p.recreateFilter === true) {
  6386. $("#"+IDs.themodal).remove();
  6387. }
  6388. function showFilter() {
  6389. if($.isFunction(p.beforeShowSearch)) {
  6390. showFrm = p.beforeShowSearch($("#"+fid));
  6391. if(typeof(showFrm) === "undefined") {
  6392. showFrm = true;
  6393. }
  6394. }
  6395. if(showFrm) {
  6396. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+fid,jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop});
  6397. if($.isFunction(p.afterShowSearch)) {
  6398. p.afterShowSearch($("#"+fid));
  6399. }
  6400. }
  6401. }
  6402. if ( $("#"+IDs.themodal).html() !== null ) {
  6403. showFilter();
  6404. } else {
  6405. var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$t.p.id),
  6406. align = "left", butleft ="";
  6407. if($t.p.direction == "rtl") {
  6408. align = "right";
  6409. butleft = " style='text-align:left'";
  6410. fil.attr("dir","rtl");
  6411. }
  6412. if($.isFunction(p.onInitializeSearch) ) {
  6413. p.onInitializeSearch($("#"+fid));
  6414. }
  6415. var columns = $.extend([],$t.p.colModel),
  6416. bS ="<a href='javascript:void(0)' 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>",
  6417. bC ="<a href='javascript:void(0)' 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>",
  6418. bQ = "", tmpl="", colnm, found = false, bt, cmi=-1;
  6419. if(p.showQuery) {
  6420. bQ ="<a href='javascript:void(0)' 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>";
  6421. }
  6422. if(!p.columns.length) {
  6423. $.each(columns, function(i,n){
  6424. if(!n.label) {
  6425. n.label = $t.p.colNames[i];
  6426. }
  6427. // find first searchable column and set it if no default filter
  6428. if(!found) {
  6429. var searchable = (typeof n.search === 'undefined') ? true: n.search ,
  6430. hidden = (n.hidden === true),
  6431. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  6432. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6433. found = true;
  6434. colnm = n.index || n.name;
  6435. cmi =i;
  6436. }
  6437. }
  6438. });
  6439. } else {
  6440. columns = p.columns;
  6441. }
  6442. // old behaviour
  6443. if( (!defaultFilters && colnm) || p.multipleSearch === false ) {
  6444. var cmop = "eq";
  6445. if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  6446. cmop = columns[cmi].searchoptions.sopt[0];
  6447. } else if(p.sopt && p.sopt.length) {
  6448. cmop = p.sopt[0];
  6449. }
  6450. defaultFilters = {"groupOp": "AND",rules:[{"field":colnm,"op":cmop,"data":""}]};
  6451. }
  6452. found = false;
  6453. if(p.tmplNames && p.tmplNames.length) {
  6454. found = true;
  6455. tmpl = p.tmplLabel;
  6456. tmpl += "<select class='ui-template'>";
  6457. tmpl += "<option value='default'>Default</option>";
  6458. $.each(p.tmplNames, function(i,n){
  6459. tmpl += "<option value='"+i+"'>"+n+"</option>";
  6460. });
  6461. tmpl += "</select>";
  6462. }
  6463. 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>";
  6464. $("#"+fid).jqFilter({
  6465. columns : columns,
  6466. filter: p.loadDefaults ? defaultFilters : null,
  6467. showQuery: p.showQuery,
  6468. errorcheck : p.errorcheck,
  6469. sopt: p.sopt,
  6470. groupButton : p.multipleGroup,
  6471. ruleButtons : p.multipleSearch,
  6472. afterRedraw : p.afterRedraw,
  6473. _gridsopt : $.jgrid.search.odata,
  6474. onChange : function( sp ) {
  6475. if(this.p.showQuery) {
  6476. $('.query',this).html(this.toUserFriendlyString());
  6477. }
  6478. },
  6479. direction : $t.p.direction
  6480. });
  6481. fil.append( bt );
  6482. if(found && p.tmplFilters && p.tmplFilters.length) {
  6483. $(".ui-template", fil).bind('change', function(e){
  6484. var curtempl = $(this).val();
  6485. if(curtempl=="default") {
  6486. $("#"+fid).jqFilter('addFilter', defaultFilters);
  6487. } else {
  6488. $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]);
  6489. }
  6490. return false;
  6491. });
  6492. }
  6493. if(p.multipleGroup === true) p.multipleSearch = true;
  6494. if($.isFunction(p.onInitializeSearch) ) {
  6495. p.onInitializeSearch($("#"+fid));
  6496. }
  6497. p.gbox = "#gbox_"+fid;
  6498. if (p.layer)
  6499. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$t.p.id,$("#gbox_"+$t.p.id)[0], "#"+p.layer, {position: "relative"});
  6500. else
  6501. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$t.p.id,$("#gbox_"+$t.p.id)[0]);
  6502. if(bQ) {
  6503. $("#"+fid+"_query").bind('click', function(e){
  6504. $(".queryresult", fil).toggle();
  6505. return false;
  6506. });
  6507. }
  6508. if (p.stringResult===undefined) {
  6509. // to provide backward compatibility, inferring stringResult value from multipleSearch
  6510. p.stringResult = p.multipleSearch;
  6511. }
  6512. $("#"+fid+"_search").bind('click', function(){
  6513. var fl = $("#"+fid),
  6514. sdata={}, res ,
  6515. filters = fl.jqFilter('filterData');
  6516. if(p.errorcheck) {
  6517. fl[0].hideError();
  6518. if(!p.showQuery) {fl.jqFilter('toSQLString');}
  6519. if(fl[0].p.error) {
  6520. fl[0].showError();
  6521. return false;
  6522. }
  6523. }
  6524. if(p.stringResult) {
  6525. try {
  6526. // xmlJsonClass or JSON.stringify
  6527. res = xmlJsonClass.toJson(filters, '', '', false);
  6528. } catch (e) {
  6529. try {
  6530. res = JSON.stringify(filters);
  6531. } catch (e2) { }
  6532. }
  6533. if(typeof(res)==="string") {
  6534. sdata[p.sFilter] = res;
  6535. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  6536. }
  6537. } else {
  6538. if(p.multipleSearch) {
  6539. sdata[p.sFilter] = filters;
  6540. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  6541. } else {
  6542. sdata[p.sField] = filters.rules[0].field;
  6543. sdata[p.sValue] = filters.rules[0].data;
  6544. sdata[p.sOper] = filters.rules[0].op;
  6545. sdata[p.sFilter] = "";
  6546. }
  6547. }
  6548. $t.p.search = true;
  6549. $.extend($t.p.postData,sdata);
  6550. if($.isFunction(p.onSearch) ) {
  6551. p.onSearch();
  6552. }
  6553. $($t).trigger("reloadGrid",[{page:1}]);
  6554. if(p.closeAfterSearch) {
  6555. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+$t.p.id,jqm:p.jqModal,onClose: p.onClose});
  6556. }
  6557. return false;
  6558. });
  6559. $("#"+fid+"_reset").bind('click', function(){
  6560. var sdata={},
  6561. fl = $("#"+fid);
  6562. $t.p.search = false;
  6563. if(p.multipleSearch===false) {
  6564. sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
  6565. } else {
  6566. sdata[p.sFilter] = "";
  6567. }
  6568. fl[0].resetFilter();
  6569. if(found) {
  6570. $(".ui-template", fil).val("default");
  6571. }
  6572. $.extend($t.p.postData,sdata);
  6573. if($.isFunction(p.onReset) ) {
  6574. p.onReset();
  6575. }
  6576. $($t).trigger("reloadGrid",[{page:1}]);
  6577. return false;
  6578. });
  6579. showFilter();
  6580. $(".fm-button:not(.ui-state-disabled)",fil).hover(
  6581. function(){$(this).addClass('ui-state-hover');},
  6582. function(){$(this).removeClass('ui-state-hover');}
  6583. );
  6584. }
  6585. });
  6586. },
  6587. editGridRow : function(rowid, p){
  6588. p = $.extend({
  6589. top : 0,
  6590. left: 0,
  6591. width: 300,
  6592. height: 'auto',
  6593. dataheight: 'auto',
  6594. modal: false,
  6595. overlay : 30,
  6596. drag: true,
  6597. resize: true,
  6598. url: null,
  6599. mtype : "POST",
  6600. clearAfterAdd :true,
  6601. closeAfterEdit : false,
  6602. reloadAfterSubmit : true,
  6603. onInitializeForm: null,
  6604. beforeInitData: null,
  6605. beforeShowForm: null,
  6606. afterShowForm: null,
  6607. beforeSubmit: null,
  6608. afterSubmit: null,
  6609. onclickSubmit: null,
  6610. afterComplete: null,
  6611. onclickPgButtons : null,
  6612. afterclickPgButtons: null,
  6613. editData : {},
  6614. recreateForm : false,
  6615. jqModal : true,
  6616. closeOnEscape : false,
  6617. addedrow : "first",
  6618. topinfo : '',
  6619. bottominfo: '',
  6620. saveicon : [],
  6621. closeicon : [],
  6622. savekey: [false,13],
  6623. navkeys: [false,38,40],
  6624. checkOnSubmit : false,
  6625. checkOnUpdate : false,
  6626. _savedData : {},
  6627. processing : false,
  6628. onClose : null,
  6629. ajaxEditOptions : {},
  6630. serializeEditData : null,
  6631. viewPagerButtons : true
  6632. }, $.jgrid.edit, p || {});
  6633. rp_ge[$(this)[0].p.id] = p;
  6634. return this.each(function(){
  6635. var $t = this;
  6636. if (!$t.grid || !rowid) {return;}
  6637. var gID = $t.p.id,
  6638. frmgr = "FrmGrid_"+gID,frmtb = "TblGrid_"+gID,
  6639. IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
  6640. onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false,
  6641. onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false,
  6642. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  6643. onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false,
  6644. copydata = null,
  6645. showFrm = true,
  6646. maxCols = 1, maxRows=0, postdata, extpost, newData, diff;
  6647. if (rowid === "new") {
  6648. rowid = "_empty";
  6649. p.caption=rp_ge[$t.p.id].addCaption;
  6650. } else {
  6651. p.caption=rp_ge[$t.p.id].editCaption;
  6652. }
  6653. if(p.recreateForm===true && $("#"+IDs.themodal).html() !== null) {
  6654. $("#"+IDs.themodal).remove();
  6655. }
  6656. var closeovrl = true;
  6657. if(p.checkOnUpdate && p.jqModal && !p.modal) {
  6658. closeovrl = false;
  6659. }
  6660. function getFormData(){
  6661. $("#"+frmtb+" > tbody > tr > td > .FormElement").each(function(i) {
  6662. var celm = $(".customelement", this);
  6663. if (celm.length) {
  6664. var elem = celm[0], nm = $(elem).attr('name');
  6665. $.each($t.p.colModel, function(i,n){
  6666. if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
  6667. try {
  6668. postdata[nm] = this.editoptions.custom_value($("#"+$.jgrid.jqID(nm),"#"+frmtb),'get');
  6669. if (postdata[nm] === undefined) {throw "e1";}
  6670. } catch (e) {
  6671. if (e==="e1") {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose);}
  6672. else {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose);}
  6673. }
  6674. return true;
  6675. }
  6676. });
  6677. } else {
  6678. switch ($(this).get(0).type) {
  6679. case "checkbox":
  6680. if($(this).is(":checked")) {
  6681. postdata[this.name]= $(this).val();
  6682. }else {
  6683. var ofv = $(this).attr("offval");
  6684. postdata[this.name]= ofv;
  6685. }
  6686. break;
  6687. case "select-one":
  6688. postdata[this.name]= $("option:selected",this).val();
  6689. extpost[this.name]= $("option:selected",this).text();
  6690. break;
  6691. case "select-multiple":
  6692. postdata[this.name]= $(this).val();
  6693. if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");}
  6694. else {postdata[this.name] ="";}
  6695. var selectedText = [];
  6696. $("option:selected",this).each(
  6697. function(i,selected){
  6698. selectedText[i] = $(selected).text();
  6699. }
  6700. );
  6701. extpost[this.name]= selectedText.join(",");
  6702. break;
  6703. case "password":
  6704. case "text":
  6705. case "textarea":
  6706. case "button":
  6707. postdata[this.name] = $(this).val();
  6708. break;
  6709. }
  6710. if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);}
  6711. }
  6712. });
  6713. return true;
  6714. }
  6715. function createData(rowid,obj,tb,maxcols){
  6716. var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
  6717. tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl="", i; //*2
  6718. for (i =1; i<=maxcols;i++) {
  6719. tmpl += tdtmpl;
  6720. }
  6721. if(rowid != '_empty') {
  6722. ind = $(obj).jqGrid("getInd",rowid);
  6723. }
  6724. $(obj.p.colModel).each( function(i) {
  6725. nm = this.name;
  6726. // hidden fields are included in the form
  6727. if(this.editrules && this.editrules.edithidden === true) {
  6728. hc = false;
  6729. } else {
  6730. hc = this.hidden === true ? true : false;
  6731. }
  6732. dc = hc ? "style='display:none'" : "";
  6733. if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
  6734. if(ind === false) {
  6735. tmp = "";
  6736. } else {
  6737. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  6738. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  6739. } else {
  6740. try {
  6741. tmp = $.unformat($("td:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
  6742. } catch (_) {
  6743. tmp = (this.edittype && this.edittype == "textarea") ? $("td:eq("+i+")",obj.rows[ind]).text() : $("td:eq("+i+")",obj.rows[ind]).html();
  6744. }
  6745. if(!tmp || tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
  6746. }
  6747. }
  6748. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
  6749. frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
  6750. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  6751. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  6752. if(rowid == "_empty" && opt.defaultValue ) {
  6753. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
  6754. }
  6755. if(!this.edittype) {this.edittype = "text";}
  6756. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  6757. elc = $.jgrid.createEl(this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
  6758. if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
  6759. if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  6760. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  6761. $(elc).addClass("FormElement");
  6762. if(this.edittype == 'text' || this.edittype == 'textarea') {
  6763. $(elc).addClass("ui-widget-content ui-corner-all");
  6764. }
  6765. trdata = $(tb).find("tr[rowpos="+rp+"]");
  6766. if(frmopt.rowabove) {
  6767. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  6768. $(tb).append(newdata);
  6769. newdata[0].rp = rp;
  6770. }
  6771. if ( trdata.length===0 ) {
  6772. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
  6773. $(trdata).append(tmpl);
  6774. $(tb).append(trdata);
  6775. trdata[0].rp = rp;
  6776. }
  6777. $("td:eq("+(cp-2)+")",trdata[0]).html( typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label);
  6778. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
  6779. retpos[cnt] = i;
  6780. cnt++;
  6781. }
  6782. });
  6783. if( cnt > 0) {
  6784. 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>");
  6785. idrow[0].rp = cnt+999;
  6786. $(tb).append(idrow);
  6787. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;}
  6788. }
  6789. return retpos;
  6790. }
  6791. function fillData(rowid,obj,fmid){
  6792. var nm,cnt=0,tmp, fld,opt,vl,vlc;
  6793. 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;}
  6794. var cm = obj.p.colModel;
  6795. if(rowid == '_empty') {
  6796. $(cm).each(function(i){
  6797. nm = this.name;
  6798. opt = $.extend({}, this.editoptions || {} );
  6799. fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
  6800. if(fld && fld.length && fld[0] !== null) {
  6801. vl = "";
  6802. if(opt.defaultValue ) {
  6803. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
  6804. if(fld[0].type=='checkbox') {
  6805. vlc = vl.toLowerCase();
  6806. if(vlc.search(/(false|0|no|off|undefined)/i)<0 && vlc!=="") {
  6807. fld[0].checked = true;
  6808. fld[0].defaultChecked = true;
  6809. fld[0].value = vl;
  6810. } else {
  6811. fld[0].checked = false;
  6812. fld[0].defaultChecked = false;
  6813. }
  6814. } else {fld.val(vl);}
  6815. } else {
  6816. if( fld[0].type=='checkbox' ) {
  6817. fld[0].checked = false;
  6818. fld[0].defaultChecked = false;
  6819. vl = $(fld).attr("offval");
  6820. } else if (fld[0].type && fld[0].type.substr(0,6)=='select') {
  6821. fld[0].selectedIndex = 0;
  6822. } else {
  6823. fld.val(vl);
  6824. }
  6825. }
  6826. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;}
  6827. }
  6828. });
  6829. $("#id_g","#"+fmid).val(rowid);
  6830. return;
  6831. }
  6832. var tre = $(obj).jqGrid("getInd",rowid,true);
  6833. if(!tre) {return;}
  6834. $('td',tre).each( function(i) {
  6835. nm = cm[i].name;
  6836. // hidden fields are included in the form
  6837. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
  6838. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  6839. tmp = $(this).text();
  6840. } else {
  6841. try {
  6842. tmp = $.unformat($(this),{rowId:rowid, colModel:cm[i]},i);
  6843. } catch (_) {
  6844. tmp = cm[i].edittype=="textarea" ? $(this).text() : $(this).html();
  6845. }
  6846. }
  6847. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  6848. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  6849. nm = $.jgrid.jqID(nm);
  6850. switch (cm[i].edittype) {
  6851. case "password":
  6852. case "text":
  6853. case "button" :
  6854. case "image":
  6855. case "textarea":
  6856. if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
  6857. $("#"+nm,"#"+fmid).val(tmp);
  6858. break;
  6859. case "select":
  6860. var opv = tmp.split(",");
  6861. opv = $.map(opv,function(n){return $.trim(n);});
  6862. $("#"+nm+" option","#"+fmid).each(function(j){
  6863. if (!cm[i].editoptions.multiple && ($.trim(tmp) == $.trim($(this).text()) || opv[0] == $.trim($(this).text()) || opv[0] == $.trim($(this).val())) ){
  6864. this.selected= true;
  6865. } else if (cm[i].editoptions.multiple){
  6866. if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
  6867. this.selected = true;
  6868. }else{
  6869. this.selected = false;
  6870. }
  6871. } else {
  6872. this.selected = false;
  6873. }
  6874. });
  6875. break;
  6876. case "checkbox":
  6877. tmp = tmp+"";
  6878. if(cm[i].editoptions && cm[i].editoptions.value) {
  6879. var cb = cm[i].editoptions.value.split(":");
  6880. if(cb[0] == tmp) {
  6881. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  6882. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  6883. } else {
  6884. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  6885. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  6886. }
  6887. } else {
  6888. tmp = tmp.toLowerCase();
  6889. if(tmp.search(/(false|0|no|off|undefined)/i)<0 && tmp!=="") {
  6890. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  6891. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  6892. } else {
  6893. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  6894. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  6895. }
  6896. }
  6897. break;
  6898. case 'custom' :
  6899. try {
  6900. if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  6901. cm[i].editoptions.custom_value($("#"+nm,"#"+fmid),'set',tmp);
  6902. } else {throw "e1";}
  6903. } catch (e) {
  6904. if (e=="e1") {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose);}
  6905. else {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose);}
  6906. }
  6907. break;
  6908. }
  6909. cnt++;
  6910. }
  6911. });
  6912. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  6913. }
  6914. function postIt() {
  6915. var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr;
  6916. if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) {
  6917. var retvals = rp_ge[$t.p.id].beforeCheckValues(postdata,$("#"+frmgr),postdata[$t.p.id+"_id"] == "_empty" ? opers.addoper : opers.editoper);
  6918. if(retvals && typeof(retvals) === 'object') {postdata = retvals;}
  6919. }
  6920. for( key in postdata ){
  6921. if(postdata.hasOwnProperty(key)) {
  6922. ret = $.jgrid.checkValues(postdata[key],key,$t);
  6923. if(ret[0] === false) {break;}
  6924. }
  6925. }
  6926. setNulls();
  6927. if(ret[0]) {
  6928. if( $.isFunction( rp_ge[$t.p.id].onclickSubmit)) { onCS = rp_ge[$t.p.id].onclickSubmit(rp_ge[$t.p.id],postdata) || {} }
  6929. if( $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {ret = rp_ge[$t.p.id].beforeSubmit(postdata,$("#"+frmgr));}
  6930. }
  6931. if(ret[0] && !rp_ge[$t.p.id].processing) {
  6932. rp_ge[$t.p.id].processing = true;
  6933. $("#sData", "#"+frmtb+"_2").addClass('ui-state-active');
  6934. oper = opers.oper;
  6935. idname = opers.id;
  6936. // we add to pos data array the action - the name is oper
  6937. postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) == "_empty") ? opers.addoper : opers.editoper;
  6938. if(postdata[oper] != opers.addoper) {
  6939. postdata[idname] = postdata[$t.p.id+"_id"];
  6940. } else {
  6941. // check to see if we have allredy this field in the form and if yes lieve it
  6942. if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];}
  6943. }
  6944. delete postdata[$t.p.id+"_id"];
  6945. postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS);
  6946. if($t.p.treeGrid === true) {
  6947. if(postdata[oper] == opers.addoper) {
  6948. selr = $($t).jqGrid("getGridParam", 'selrow');
  6949. var tr_par_id = $t.p.treeGridModel == 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id';
  6950. postdata[tr_par_id] = selr;
  6951. }
  6952. for(i in $t.p.treeReader){
  6953. var itm = $t.p.treeReader[i];
  6954. if(postdata.hasOwnProperty(itm)) {
  6955. if(postdata[oper] == opers.addoper && i === 'parent_id_field') {continue;}
  6956. delete postdata[itm];
  6957. }
  6958. }
  6959. }
  6960. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]);
  6961. var ajaxOptions = $.extend({
  6962. url: rp_ge[$t.p.id].url ? rp_ge[$t.p.id].url : $($t).jqGrid('getGridParam','editurl'),
  6963. type: rp_ge[$t.p.id].mtype,
  6964. data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData(postdata) : postdata,
  6965. complete:function(data,Status){
  6966. postdata[idname] = $t.p.idPrefix + postdata[idname];
  6967. if(Status != "success") {
  6968. ret[0] = false;
  6969. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  6970. ret[1] = rp_ge[$t.p.id].errorTextFormat(data);
  6971. } else {
  6972. ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  6973. }
  6974. } else {
  6975. // data is posted successful
  6976. // execute aftersubmit with the returned data from server
  6977. if( $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  6978. ret = rp_ge[$t.p.id].afterSubmit(data,postdata);
  6979. }
  6980. }
  6981. if(ret[0] === false) {
  6982. $("#FormError>td","#"+frmtb).html(ret[1]);
  6983. $("#FormError","#"+frmtb).show();
  6984. } else {
  6985. // remove some values if formattaer select or checkbox
  6986. $.each($t.p.colModel, function(i,n){
  6987. if(extpost[this.name] && this.formatter && this.formatter=='select') {
  6988. try {delete extpost[this.name];} catch (e) {}
  6989. }
  6990. });
  6991. postdata = $.extend(postdata,extpost);
  6992. if($t.p.autoencode) {
  6993. $.each(postdata,function(n,v){
  6994. postdata[n] = $.jgrid.htmlDecode(v);
  6995. });
  6996. }
  6997. //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local";
  6998. // the action is add
  6999. if(postdata[oper] == opers.addoper ) {
  7000. //id processing
  7001. // user not set the id ret[2]
  7002. if(!ret[2]) {ret[2] = $.jgrid.randId();}
  7003. postdata[idname] = ret[2];
  7004. if(rp_ge[$t.p.id].closeAfterAdd) {
  7005. if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");}
  7006. else {
  7007. if($t.p.treeGrid === true){
  7008. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7009. } else {
  7010. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7011. $($t).jqGrid("setSelection",ret[2]);
  7012. }
  7013. }
  7014. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7015. } else if (rp_ge[$t.p.id].clearAfterAdd) {
  7016. if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");}
  7017. else {
  7018. if($t.p.treeGrid === true){
  7019. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7020. } else {
  7021. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7022. }
  7023. }
  7024. fillData("_empty",$t,frmgr);
  7025. } else {
  7026. if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");}
  7027. else {
  7028. if($t.p.treeGrid === true){
  7029. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7030. } else {
  7031. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7032. }
  7033. }
  7034. }
  7035. } else {
  7036. // the action is update
  7037. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7038. $($t).trigger("reloadGrid");
  7039. if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);}
  7040. } else {
  7041. if($t.p.treeGrid === true) {
  7042. $($t).jqGrid("setTreeRow", postdata[idname],postdata);
  7043. } else {
  7044. $($t).jqGrid("setRowData", postdata[idname],postdata);
  7045. }
  7046. }
  7047. if(rp_ge[$t.p.id].closeAfterEdit) {$.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});}
  7048. }
  7049. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  7050. copydata = data;
  7051. setTimeout(function(){rp_ge[$t.p.id].afterComplete(copydata,postdata,$("#"+frmgr));copydata=null;},500);
  7052. }
  7053. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7054. $("#"+frmgr).data("disabled",false);
  7055. if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !="_empty"){
  7056. for(var key in rp_ge[$t.p.id]._savedData) {
  7057. if(postdata[key]) {
  7058. rp_ge[$t.p.id]._savedData[key] = postdata[key];
  7059. }
  7060. }
  7061. }
  7062. }
  7063. }
  7064. rp_ge[$t.p.id].processing=false;
  7065. $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
  7066. try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
  7067. }
  7068. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions );
  7069. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  7070. if ($.isFunction($t.p.dataProxy)) {
  7071. rp_ge[$t.p.id].useDataProxy = true;
  7072. } else {
  7073. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  7074. }
  7075. }
  7076. if (ret[0]) {
  7077. if (rp_ge[$t.p.id].useDataProxy) {
  7078. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id);
  7079. if(typeof(dpret) == "undefined") {
  7080. dpret = [true, ""];
  7081. }
  7082. if(dpret[0] === false ) {
  7083. ret[0] = false;
  7084. ret[1] = dpret[1] || "Error deleting the selected row!"
  7085. } else {
  7086. if(ajaxOptions.data.oper == opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) {
  7087. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7088. }
  7089. if(ajaxOptions.data.oper == opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) {
  7090. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7091. }
  7092. }
  7093. } else {
  7094. $.ajax(ajaxOptions);
  7095. }
  7096. }
  7097. }
  7098. if(ret[0] === false) {
  7099. $("#FormError>td","#"+frmtb).html(ret[1]);
  7100. $("#FormError","#"+frmtb).show();
  7101. // return;
  7102. }
  7103. }
  7104. function compareData(nObj, oObj ) {
  7105. var ret = false,key;
  7106. for (key in nObj) {
  7107. if(nObj[key] != oObj[key]) {
  7108. ret = true;
  7109. break;
  7110. }
  7111. }
  7112. return ret;
  7113. }
  7114. function setNulls() {
  7115. $.each($t.p.colModel, function(i,n){
  7116. if(n.editoptions && n.editoptions.NullIfEmpty === true) {
  7117. if(postdata.hasOwnProperty(n.name) && postdata[n.name] == "") {
  7118. postdata[n.name] = 'null';
  7119. }
  7120. }
  7121. });
  7122. }
  7123. function checkUpdates () {
  7124. var stat = true;
  7125. $("#FormError","#"+frmtb).hide();
  7126. if(rp_ge[$t.p.id].checkOnUpdate) {
  7127. postdata = {};extpost={};
  7128. getFormData();
  7129. newData = $.extend({},postdata,extpost);
  7130. diff = compareData(newData,rp_ge[$t.p.id]._savedData);
  7131. if(diff) {
  7132. $("#"+frmgr).data("disabled",true);
  7133. $(".confirm","#"+IDs.themodal).show();
  7134. stat = false;
  7135. }
  7136. }
  7137. return stat;
  7138. }
  7139. function restoreInline()
  7140. {
  7141. if (rowid !== "_empty" && typeof($t.p.savedRow) !== "undefined" && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) {
  7142. for (var i=0;i<$t.p.savedRow.length;i++) {
  7143. if ($t.p.savedRow[i].id == rowid) {
  7144. $($t).jqGrid('restoreRow',rowid);
  7145. break;
  7146. }
  7147. }
  7148. }
  7149. }
  7150. function updateNav(cr,totr){
  7151. if (cr===0) {$("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');} else {$("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');}
  7152. if (cr==totr) {$("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');} else {$("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');}
  7153. }
  7154. function getCurrPos() {
  7155. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  7156. selrow = $("#id_g","#"+frmtb).val(),
  7157. pos = $.inArray(selrow,rowsInGrid);
  7158. return [pos,rowsInGrid];
  7159. }
  7160. if ( $("#"+IDs.themodal).html() !== null ) {
  7161. if(onBeforeInit) {
  7162. showFrm = onBeforeInit($("#"+frmgr));
  7163. if(typeof(showFrm) == "undefined") {
  7164. showFrm = true;
  7165. }
  7166. }
  7167. if(showFrm === false) {return;}
  7168. restoreInline();
  7169. $(".ui-jqdialog-title","#"+IDs.modalhead).html(p.caption);
  7170. $("#FormError","#"+frmtb).hide();
  7171. if(rp_ge[$t.p.id].topinfo) {
  7172. $(".topinfo","#"+frmtb).html(rp_ge[$t.p.id].topinfo);
  7173. $(".tinfo","#"+frmtb).show();
  7174. } else {
  7175. $(".tinfo","#"+frmtb).hide();
  7176. }
  7177. if(rp_ge[$t.p.id].bottominfo) {
  7178. $(".bottominfo","#"+frmtb+"_2").html(rp_ge[$t.p.id].bottominfo);
  7179. $(".binfo","#"+frmtb+"_2").show();
  7180. } else {
  7181. $(".binfo","#"+frmtb+"_2").hide();
  7182. }
  7183. // filldata
  7184. fillData(rowid,$t,frmgr);
  7185. ///
  7186. if(rowid=="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {
  7187. $("#pData, #nData","#"+frmtb+"_2").hide();
  7188. } else {
  7189. $("#pData, #nData","#"+frmtb+"_2").show();
  7190. }
  7191. if(rp_ge[$t.p.id].processing===true) {
  7192. rp_ge[$t.p.id].processing=false;
  7193. $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
  7194. }
  7195. if($("#"+frmgr).data("disabled")===true) {
  7196. $(".confirm","#"+IDs.themodal).hide();
  7197. $("#"+frmgr).data("disabled",false);
  7198. }
  7199. if(onBeforeShow) {onBeforeShow($("#"+frmgr));}
  7200. $("#"+IDs.themodal).data("onClose",rp_ge[$t.p.id].onClose);
  7201. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
  7202. if(!closeovrl) {
  7203. $(".jqmOverlay").click(function(){
  7204. if(!checkUpdates()) {return false;}
  7205. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7206. return false;
  7207. });
  7208. }
  7209. if(onAfterShow) {onAfterShow($("#"+frmgr));}
  7210. } else {
  7211. var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px",
  7212. frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
  7213. tbl = $("<table id='"+frmtb+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>");
  7214. if(onBeforeInit) {
  7215. showFrm = onBeforeInit($("#"+frmgr));
  7216. if(typeof(showFrm) == "undefined") {
  7217. showFrm = true;
  7218. }
  7219. }
  7220. if(showFrm === false) {return;}
  7221. restoreInline();
  7222. $($t.p.colModel).each( function(i) {
  7223. var fmto = this.formoptions;
  7224. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  7225. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  7226. });
  7227. $(frm).append(tbl);
  7228. var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
  7229. flr[0].rp = 0;
  7230. $(tbl).append(flr);
  7231. //topinfo
  7232. flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge[$t.p.id].topinfo+"</td></tr>");
  7233. flr[0].rp = 0;
  7234. $(tbl).append(flr);
  7235. // set the id.
  7236. // use carefull only to change here colproperties.
  7237. // create data
  7238. var rtlb = $t.p.direction == "rtl" ? true :false,
  7239. bp = rtlb ? "nData" : "pData",
  7240. bn = rtlb ? "pData" : "nData";
  7241. createData(rowid,$t,tbl,maxCols);
  7242. // buttons at footer
  7243. var bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  7244. bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  7245. bS ="<a href='javascript:void(0)' id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  7246. bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  7247. var bt = "<table border='0' cellspacing='0' cellpadding='0' class='EditTable' id='"+frmtb+"_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>";
  7248. bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>";
  7249. bt += "</tbody></table>";
  7250. if(maxRows > 0) {
  7251. var sd=[], div={};
  7252. $.each($(tbl)[0].rows,function(i,r){
  7253. sd[i] = r;
  7254. });
  7255. sd.sort(function(a,b){
  7256. if(a.rp > b.rp) {return 1;}
  7257. if(a.rp < b.rp) {return -1;}
  7258. return 0;
  7259. });
  7260. $.each(sd, function(index, row) {
  7261. div.html += row;
  7262. });
  7263. $('tbody',tbl).append(div.html);
  7264. }
  7265. p.gbox = "#gbox_"+gID;
  7266. var cle = false;
  7267. if(p.closeOnEscape===true){
  7268. p.closeOnEscape = false;
  7269. cle = true;
  7270. }
  7271. var tms = $("<span></span>").append(frm).append(bt);
  7272. $.jgrid.createModal(IDs,tms,p,"#gview_"+$t.p.id,$("#gbox_"+$t.p.id)[0]);
  7273. if(rtlb) {
  7274. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  7275. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  7276. }
  7277. if(rp_ge[$t.p.id].topinfo) {$(".tinfo","#"+frmtb).show();}
  7278. if(rp_ge[$t.p.id].bottominfo) {$(".binfo","#"+frmtb+"_2").show();}
  7279. tms = null;bt=null;
  7280. $("#"+IDs.themodal).keydown( function( e ) {
  7281. var wkey = e.target;
  7282. if ($("#"+frmgr).data("disabled")===true ) {return false;}//??
  7283. if(rp_ge[$t.p.id].savekey[0] === true && e.which == rp_ge[$t.p.id].savekey[1]) { // save
  7284. if(wkey.tagName != "TEXTAREA") {
  7285. $("#sData", "#"+frmtb+"_2").trigger("click");
  7286. return false;
  7287. }
  7288. }
  7289. if(e.which === 27) {
  7290. if(!checkUpdates()) {return false;}
  7291. if(cle) {$.jgrid.hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  7292. return false;
  7293. }
  7294. if(rp_ge[$t.p.id].navkeys[0]===true) {
  7295. if($("#id_g","#"+frmtb).val() == "_empty") {return true;}
  7296. if(e.which == rp_ge[$t.p.id].navkeys[1]){ //up
  7297. $("#pData", "#"+frmtb+"_2").trigger("click");
  7298. return false;
  7299. }
  7300. if(e.which == rp_ge[$t.p.id].navkeys[2]){ //down
  7301. $("#nData", "#"+frmtb+"_2").trigger("click");
  7302. return false;
  7303. }
  7304. }
  7305. });
  7306. if(p.checkOnUpdate) {
  7307. $("a.ui-jqdialog-titlebar-close span","#"+IDs.themodal).removeClass("jqmClose");
  7308. $("a.ui-jqdialog-titlebar-close","#"+IDs.themodal).unbind("click")
  7309. .click(function(){
  7310. if(!checkUpdates()) {return false;}
  7311. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7312. return false;
  7313. });
  7314. }
  7315. p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
  7316. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  7317. // beforeinitdata after creation of the form
  7318. if(p.saveicon[0]===true) {
  7319. $("#sData","#"+frmtb+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7320. .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
  7321. }
  7322. if(p.closeicon[0]===true) {
  7323. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7324. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  7325. }
  7326. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7327. bS ="<a href='javascript:void(0)' id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
  7328. bN ="<a href='javascript:void(0)' id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
  7329. bC ="<a href='javascript:void(0)' id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
  7330. var ii, zI = p.zIndex || 999;zI ++;
  7331. if ($.browser.msie && $.browser.version ==6) {
  7332. ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
  7333. } else {ii="";}
  7334. $("<div class='ui-widget-overlay jqgrid-overlay confirm' style='z-index:"+zI+";display:none;'>&#160;"+ii+"</div><div class='confirm ui-widget-content ui-jqconfirm' style='z-index:"+(zI+1)+"'>"+p.saveData+"<br/><br/>"+bS+bN+bC+"</div>").insertAfter("#"+frmgr);
  7335. $("#sNew","#"+IDs.themodal).click(function(){
  7336. postIt();
  7337. $("#"+frmgr).data("disabled",false);
  7338. $(".confirm","#"+IDs.themodal).hide();
  7339. return false;
  7340. });
  7341. $("#nNew","#"+IDs.themodal).click(function(){
  7342. $(".confirm","#"+IDs.themodal).hide();
  7343. $("#"+frmgr).data("disabled",false);
  7344. setTimeout(function(){$(":input","#"+frmgr)[0].focus();},0);
  7345. return false;
  7346. });
  7347. $("#cNew","#"+IDs.themodal).click(function(){
  7348. $(".confirm","#"+IDs.themodal).hide();
  7349. $("#"+frmgr).data("disabled",false);
  7350. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7351. return false;
  7352. });
  7353. }
  7354. // here initform - only once
  7355. if(onInitializeForm) {onInitializeForm($("#"+frmgr));}
  7356. if(rowid=="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData","#"+frmtb+"_2").hide();} else {$("#pData,#nData","#"+frmtb+"_2").show();}
  7357. if(onBeforeShow) {onBeforeShow($("#"+frmgr));}
  7358. $("#"+IDs.themodal).data("onClose",rp_ge[$t.p.id].onClose);
  7359. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, overlay: p.overlay,modal:p.modal});
  7360. if(!closeovrl) {
  7361. $(".jqmOverlay").click(function(){
  7362. if(!checkUpdates()) {return false;}
  7363. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7364. return false;
  7365. });
  7366. }
  7367. if(onAfterShow) {onAfterShow($("#"+frmgr));}
  7368. $(".fm-button","#"+IDs.themodal).hover(
  7369. function(){$(this).addClass('ui-state-hover');},
  7370. function(){$(this).removeClass('ui-state-hover');}
  7371. );
  7372. $("#sData", "#"+frmtb+"_2").click(function(e){
  7373. postdata = {};extpost={};
  7374. $("#FormError","#"+frmtb).hide();
  7375. // all depend on ret array
  7376. //ret[0] - succes
  7377. //ret[1] - msg if not succes
  7378. //ret[2] - the id that will be set if reload after submit false
  7379. getFormData();
  7380. if(postdata[$t.p.id+"_id"] == "_empty") {postIt();}
  7381. else if(p.checkOnSubmit===true ) {
  7382. newData = $.extend({},postdata,extpost);
  7383. diff = compareData(newData,rp_ge[$t.p.id]._savedData);
  7384. if(diff) {
  7385. $("#"+frmgr).data("disabled",true);
  7386. $(".confirm","#"+IDs.themodal).show();
  7387. } else {
  7388. postIt();
  7389. }
  7390. } else {
  7391. postIt();
  7392. }
  7393. return false;
  7394. });
  7395. $("#cData", "#"+frmtb+"_2").click(function(e){
  7396. if(!checkUpdates()) {return false;}
  7397. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7398. return false;
  7399. });
  7400. $("#nData", "#"+frmtb+"_2").click(function(e){
  7401. if(!checkUpdates()) {return false;}
  7402. $("#FormError","#"+frmtb).hide();
  7403. var npos = getCurrPos();
  7404. npos[0] = parseInt(npos[0],10);
  7405. if(npos[0] != -1 && npos[1][npos[0]+1]) {
  7406. if($.isFunction(p.onclickPgButtons)) {
  7407. p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]);
  7408. }
  7409. fillData(npos[1][npos[0]+1],$t,frmgr);
  7410. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  7411. if($.isFunction(p.afterclickPgButtons)) {
  7412. p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]);
  7413. }
  7414. updateNav(npos[0]+1,npos[1].length-1);
  7415. }
  7416. return false;
  7417. });
  7418. $("#pData", "#"+frmtb+"_2").click(function(e){
  7419. if(!checkUpdates()) {return false;}
  7420. $("#FormError","#"+frmtb).hide();
  7421. var ppos = getCurrPos();
  7422. if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
  7423. if($.isFunction(p.onclickPgButtons)) {
  7424. p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]);
  7425. }
  7426. fillData(ppos[1][ppos[0]-1],$t,frmgr);
  7427. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  7428. if($.isFunction(p.afterclickPgButtons)) {
  7429. p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  7430. }
  7431. updateNav(ppos[0]-1,ppos[1].length-1);
  7432. }
  7433. return false;
  7434. });
  7435. }
  7436. var posInit =getCurrPos();
  7437. updateNav(posInit[0],posInit[1].length-1);
  7438. });
  7439. },
  7440. viewGridRow : function(rowid, p){
  7441. p = $.extend({
  7442. top : 0,
  7443. left: 0,
  7444. width: 0,
  7445. height: 'auto',
  7446. dataheight: 'auto',
  7447. modal: false,
  7448. overlay: 30,
  7449. drag: true,
  7450. resize: true,
  7451. jqModal: true,
  7452. closeOnEscape : false,
  7453. labelswidth: '30%',
  7454. closeicon: [],
  7455. navkeys: [false,38,40],
  7456. onClose: null,
  7457. beforeShowForm : null,
  7458. beforeInitData : null,
  7459. viewPagerButtons : true
  7460. }, $.jgrid.view, p || {});
  7461. return this.each(function(){
  7462. var $t = this;
  7463. if (!$t.grid || !rowid) {return;}
  7464. var gID = $t.p.id,
  7465. frmgr = "ViewGrid_"+gID , frmtb = "ViewTbl_"+gID,
  7466. IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
  7467. onBeforeInit = $.isFunction(p.beforeInitData) ? p.beforeInitData : false,
  7468. showFrm = true,
  7469. maxCols = 1, maxRows=0;
  7470. function focusaref(){ //Sfari 3 issues
  7471. if(p.closeOnEscape===true || p.navkeys[0]===true) {
  7472. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+IDs.modalhead).focus();},0);
  7473. }
  7474. }
  7475. function createData(rowid,obj,tb,maxcols){
  7476. var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false,
  7477. tdtmpl = "<td class='CaptionTD form-view-label ui-widget-content' width='"+p.labelswidth+"'>&#160;</td><td class='DataTD form-view-data ui-helper-reset ui-widget-content'>&#160;</td>", tmpl="",
  7478. tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
  7479. fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
  7480. for (var i =1;i<=maxcols;i++) {
  7481. tmpl += i == 1 ? tdtmpl : tdtmpl2;
  7482. }
  7483. // find max number align rigth with property formatter
  7484. $(obj.p.colModel).each( function(i) {
  7485. if(this.editrules && this.editrules.edithidden === true) {
  7486. hc = false;
  7487. } else {
  7488. hc = this.hidden === true ? true : false;
  7489. }
  7490. if(!hc && this.align==='right') {
  7491. if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
  7492. max1 = Math.max(max1,parseInt(this.width,10));
  7493. } else {
  7494. max2 = Math.max(max2,parseInt(this.width,10));
  7495. }
  7496. }
  7497. });
  7498. maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
  7499. ind = $(obj).jqGrid("getInd",rowid);
  7500. $(obj.p.colModel).each( function(i) {
  7501. nm = this.name;
  7502. setme = false;
  7503. // hidden fields are included in the form
  7504. if(this.editrules && this.editrules.edithidden === true) {
  7505. hc = false;
  7506. } else {
  7507. hc = this.hidden === true ? true : false;
  7508. }
  7509. dc = hc ? "style='display:none'" : "";
  7510. viewfld = (typeof this.viewable != 'boolean') ? true : this.viewable;
  7511. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
  7512. if(ind === false) {
  7513. tmp = "";
  7514. } else {
  7515. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7516. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  7517. } else {
  7518. tmp = $("td:eq("+i+")",obj.rows[ind]).html();
  7519. }
  7520. }
  7521. setme = this.align === 'right' && maxw !==0 ? true : false;
  7522. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
  7523. frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
  7524. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  7525. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  7526. if(frmopt.rowabove) {
  7527. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  7528. $(tb).append(newdata);
  7529. newdata[0].rp = rp;
  7530. }
  7531. trdata = $(tb).find("tr[rowpos="+rp+"]");
  7532. if ( trdata.length===0 ) {
  7533. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
  7534. $(trdata).append(tmpl);
  7535. $(tb).append(trdata);
  7536. trdata[0].rp = rp;
  7537. }
  7538. $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label)+'</b>');
  7539. $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
  7540. if(setme){
  7541. $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
  7542. }
  7543. retpos[cnt] = i;
  7544. cnt++;
  7545. }
  7546. });
  7547. if( cnt > 0) {
  7548. 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>");
  7549. idrow[0].rp = cnt+99;
  7550. $(tb).append(idrow);
  7551. }
  7552. return retpos;
  7553. }
  7554. function fillData(rowid,obj){
  7555. var nm, hc,cnt=0,tmp, opt,trv;
  7556. trv = $(obj).jqGrid("getInd",rowid,true);
  7557. if(!trv) {return;}
  7558. $('td',trv).each( function(i) {
  7559. nm = obj.p.colModel[i].name;
  7560. // hidden fields are included in the form
  7561. if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
  7562. hc = false;
  7563. } else {
  7564. hc = obj.p.colModel[i].hidden === true ? true : false;
  7565. }
  7566. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  7567. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7568. tmp = $(this).text();
  7569. } else {
  7570. tmp = $(this).html();
  7571. }
  7572. opt = $.extend({},obj.p.colModel[i].editoptions || {});
  7573. nm = $.jgrid.jqID("v_"+nm);
  7574. $("#"+nm+" span","#"+frmtb).html(tmp);
  7575. if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();}
  7576. cnt++;
  7577. }
  7578. });
  7579. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  7580. }
  7581. function updateNav(cr,totr){
  7582. if (cr===0) {$("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');} else {$("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');}
  7583. if (cr==totr) {$("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');} else {$("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');}
  7584. }
  7585. function getCurrPos() {
  7586. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  7587. selrow = $("#id_g","#"+frmtb).val(),
  7588. pos = $.inArray(selrow,rowsInGrid);
  7589. return [pos,rowsInGrid];
  7590. }
  7591. if ( $("#"+IDs.themodal).html() !== null ) {
  7592. if(onBeforeInit) {
  7593. showFrm = onBeforeInit($("#"+frmgr));
  7594. if(typeof(showFrm) == "undefined") {
  7595. showFrm = true;
  7596. }
  7597. }
  7598. if(showFrm === false) {return;}
  7599. $(".ui-jqdialog-title","#"+IDs.modalhead).html(p.caption);
  7600. $("#FormError","#"+frmtb).hide();
  7601. fillData(rowid,$t);
  7602. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm($("#"+frmgr));}
  7603. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
  7604. focusaref();
  7605. } else {
  7606. var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
  7607. var frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>"),
  7608. tbl =$("<table id='"+frmtb+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
  7609. if(onBeforeInit) {
  7610. showFrm = onBeforeInit($("#"+frmgr));
  7611. if(typeof(showFrm) == "undefined") {
  7612. showFrm = true;
  7613. }
  7614. }
  7615. if(showFrm === false) {return;}
  7616. $($t.p.colModel).each( function(i) {
  7617. var fmto = this.formoptions;
  7618. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  7619. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  7620. });
  7621. // set the id.
  7622. $(frm).append(tbl);
  7623. createData(rowid, $t, tbl, maxCols);
  7624. var rtlb = $t.p.direction == "rtl" ? true :false,
  7625. bp = rtlb ? "nData" : "pData",
  7626. bn = rtlb ? "pData" : "nData",
  7627. // buttons at footer
  7628. bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  7629. bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  7630. bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
  7631. if(maxRows > 0) {
  7632. var sd=[];
  7633. $.each($(tbl)[0].rows,function(i,r){
  7634. sd[i] = r;
  7635. });
  7636. sd.sort(function(a,b){
  7637. if(a.rp > b.rp) {return 1;}
  7638. if(a.rp < b.rp) {return -1;}
  7639. return 0;
  7640. });
  7641. $.each(sd, function(index, row) {
  7642. $('tbody',tbl).append(row);
  7643. });
  7644. }
  7645. p.gbox = "#gbox_"+gID;
  7646. var cle = false;
  7647. if(p.closeOnEscape===true){
  7648. p.closeOnEscape = false;
  7649. cle = true;
  7650. }
  7651. var bt = $("<span></span>").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>");
  7652. $.jgrid.createModal(IDs,bt,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
  7653. if(rtlb) {
  7654. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  7655. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  7656. }
  7657. if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();}
  7658. bt = null;
  7659. $("#"+IDs.themodal).keydown( function( e ) {
  7660. if(e.which === 27) {
  7661. if(cle) {$.jgrid.hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose});}
  7662. return false;
  7663. }
  7664. if(p.navkeys[0]===true) {
  7665. if(e.which === p.navkeys[1]){ //up
  7666. $("#pData", "#"+frmtb+"_2").trigger("click");
  7667. return false;
  7668. }
  7669. if(e.which === p.navkeys[2]){ //down
  7670. $("#nData", "#"+frmtb+"_2").trigger("click");
  7671. return false;
  7672. }
  7673. }
  7674. });
  7675. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  7676. if(p.closeicon[0]===true) {
  7677. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7678. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  7679. }
  7680. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm($("#"+frmgr));}
  7681. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, modal:p.modal});
  7682. $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
  7683. function(){$(this).addClass('ui-state-hover');},
  7684. function(){$(this).removeClass('ui-state-hover');}
  7685. );
  7686. focusaref();
  7687. $("#cData", "#"+frmtb+"_2").click(function(e){
  7688. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
  7689. return false;
  7690. });
  7691. $("#nData", "#"+frmtb+"_2").click(function(e){
  7692. $("#FormError","#"+frmtb).hide();
  7693. var npos = getCurrPos();
  7694. npos[0] = parseInt(npos[0],10);
  7695. if(npos[0] != -1 && npos[1][npos[0]+1]) {
  7696. if($.isFunction(p.onclickPgButtons)) {
  7697. p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]);
  7698. }
  7699. fillData(npos[1][npos[0]+1],$t);
  7700. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  7701. if($.isFunction(p.afterclickPgButtons)) {
  7702. p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]);
  7703. }
  7704. updateNav(npos[0]+1,npos[1].length-1);
  7705. }
  7706. focusaref();
  7707. return false;
  7708. });
  7709. $("#pData", "#"+frmtb+"_2").click(function(e){
  7710. $("#FormError","#"+frmtb).hide();
  7711. var ppos = getCurrPos();
  7712. if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
  7713. if($.isFunction(p.onclickPgButtons)) {
  7714. p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]);
  7715. }
  7716. fillData(ppos[1][ppos[0]-1],$t);
  7717. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  7718. if($.isFunction(p.afterclickPgButtons)) {
  7719. p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  7720. }
  7721. updateNav(ppos[0]-1,ppos[1].length-1);
  7722. }
  7723. focusaref();
  7724. return false;
  7725. });
  7726. }
  7727. var posInit =getCurrPos();
  7728. updateNav(posInit[0],posInit[1].length-1);
  7729. });
  7730. },
  7731. delGridRow : function(rowids,p) {
  7732. p = $.extend({
  7733. top : 0,
  7734. left: 0,
  7735. width: 240,
  7736. height: 'auto',
  7737. dataheight : 'auto',
  7738. modal: false,
  7739. overlay: 30,
  7740. drag: true,
  7741. resize: true,
  7742. url : '',
  7743. mtype : "POST",
  7744. reloadAfterSubmit: true,
  7745. beforeShowForm: null,
  7746. beforeInitData : null,
  7747. afterShowForm: null,
  7748. beforeSubmit: null,
  7749. onclickSubmit: null,
  7750. afterSubmit: null,
  7751. jqModal : true,
  7752. closeOnEscape : false,
  7753. delData: {},
  7754. delicon : [],
  7755. cancelicon : [],
  7756. onClose : null,
  7757. ajaxDelOptions : {},
  7758. processing : false,
  7759. serializeDelData : null,
  7760. useDataProxy : false
  7761. }, $.jgrid.del, p ||{});
  7762. rp_ge[$(this)[0].p.id] = p;
  7763. return this.each(function(){
  7764. var $t = this;
  7765. if (!$t.grid ) {return;}
  7766. if(!rowids) {return;}
  7767. var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ),
  7768. onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ),
  7769. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  7770. gID = $t.p.id, onCS = {},
  7771. showFrm = true,
  7772. dtbl = "DelTbl_"+gID,postd, idname, opers, oper,
  7773. IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
  7774. if (jQuery.isArray(rowids)) {rowids = rowids.join();}
  7775. if ( $("#"+IDs.themodal).html() !== null ) {
  7776. if(onBeforeInit) {
  7777. showFrm = onBeforeInit( $("#"+dtbl));
  7778. if(typeof(showFrm) == "undefined") {
  7779. showFrm = true;
  7780. }
  7781. }
  7782. if(showFrm === false) {return;}
  7783. $("#DelData>td","#"+dtbl).text(rowids);
  7784. $("#DelError","#"+dtbl).hide();
  7785. if( rp_ge[$t.p.id].processing === true) {
  7786. rp_ge[$t.p.id].processing=false;
  7787. $("#dData", "#"+dtbl).removeClass('ui-state-active');
  7788. }
  7789. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm($("#"+dtbl));}
  7790. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:rp_ge[$t.p.id].jqModal,jqM: false, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal});
  7791. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm($("#"+dtbl));}
  7792. } else {
  7793. var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px";
  7794. var tbl = "<div id='"+dtbl+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
  7795. tbl += "<table class='DelTable'><tbody>";
  7796. // error data
  7797. tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
  7798. tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
  7799. tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td >&#160;</td></tr>";
  7800. // buttons at footer
  7801. tbl += "</tbody></table></div>";
  7802. var bS = "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  7803. bC = "<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  7804. 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+"&#160;"+bC+"</td></tr></tbody></table>";
  7805. p.gbox = "#gbox_"+gID;
  7806. $.jgrid.createModal(IDs,tbl,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
  7807. if(onBeforeInit) {
  7808. showFrm = onBeforeInit( $("#"+dtbl) );
  7809. if(typeof(showFrm) == "undefined") {
  7810. showFrm = true;
  7811. }
  7812. }
  7813. if(showFrm === false) {return;}
  7814. $(".fm-button","#"+dtbl+"_2").hover(
  7815. function(){$(this).addClass('ui-state-hover');},
  7816. function(){$(this).removeClass('ui-state-hover');}
  7817. );
  7818. p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon);
  7819. p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon);
  7820. if(p.delicon[0]===true) {
  7821. $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7822. .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
  7823. }
  7824. if(p.cancelicon[0]===true) {
  7825. $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7826. .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
  7827. }
  7828. $("#dData","#"+dtbl+"_2").click(function(e){
  7829. var ret=[true,""];onCS = {};
  7830. var postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
  7831. if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit(rp_ge[$t.p.id], postdata) || {} }
  7832. if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit(postdata);}
  7833. if(ret[0] && !rp_ge[$t.p.id].processing) {
  7834. rp_ge[$t.p.id].processing = true;
  7835. $(this).addClass('ui-state-active');
  7836. opers = $t.p.prmNames;
  7837. postd = $.extend({},rp_ge[$t.p.id].delData, onCS);
  7838. oper = opers.oper;
  7839. postd[oper] = opers.deloper;
  7840. idname = opers.id;
  7841. postdata = postdata.split(",");
  7842. for( var pk in postdata) {
  7843. if(postdata.hasOwnProperty(pk)) {
  7844. postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]);
  7845. }
  7846. }
  7847. postd[idname] = postdata.join();
  7848. var ajaxOptions = $.extend({
  7849. url: rp_ge[$t.p.id].url ? rp_ge[$t.p.id].url : $($t).jqGrid('getGridParam','editurl'),
  7850. type: rp_ge[$t.p.id].mtype,
  7851. data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData(postd) : postd,
  7852. complete:function(data,Status){
  7853. if(Status != "success") {
  7854. ret[0] = false;
  7855. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  7856. ret[1] = rp_ge[$t.p.id].errorTextFormat(data);
  7857. } else {
  7858. ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  7859. }
  7860. } else {
  7861. // data is posted successful
  7862. // execute aftersubmit with the returned data from server
  7863. if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) {
  7864. ret = rp_ge[$t.p.id].afterSubmit(data,postd);
  7865. }
  7866. }
  7867. if(ret[0] === false) {
  7868. $("#DelError>td","#"+dtbl).html(ret[1]);
  7869. $("#DelError","#"+dtbl).show();
  7870. } else {
  7871. if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local") {
  7872. $($t).trigger("reloadGrid");
  7873. } else {
  7874. var toarr = [];
  7875. toarr = postdata.split(",");
  7876. if($t.p.treeGrid===true){
  7877. try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+toarr[0]);} catch(e){}
  7878. } else {
  7879. for(var i=0;i<toarr.length;i++) {
  7880. $($t).jqGrid("delRowData",$t.p.idPrefix+ toarr[i]);
  7881. }
  7882. }
  7883. $t.p.selrow = null;
  7884. $t.p.selarrrow = [];
  7885. }
  7886. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  7887. setTimeout(function(){rp_ge[$t.p.id].afterComplete(data,postdata);},500);
  7888. }
  7889. }
  7890. rp_ge[$t.p.id].processing=false;
  7891. $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
  7892. if(ret[0]) {$.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  7893. }
  7894. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions);
  7895. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  7896. if ($.isFunction($t.p.dataProxy)) {
  7897. rp_ge[$t.p.id].useDataProxy = true;
  7898. } else {
  7899. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  7900. }
  7901. }
  7902. if (ret[0]) {
  7903. if (rp_ge[$t.p.id].useDataProxy) {
  7904. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id);
  7905. if(typeof(dpret) == "undefined") {
  7906. dpret = [true, ""];
  7907. }
  7908. if(dpret[0] === false ) {
  7909. ret[0] = false;
  7910. ret[1] = dpret[1] || "Error deleting the selected row!"
  7911. } else {
  7912. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7913. }
  7914. }
  7915. else {$.ajax(ajaxOptions);}
  7916. }
  7917. }
  7918. if(ret[0] === false) {
  7919. $("#DelError>td","#"+dtbl).html(ret[1]);
  7920. $("#DelError","#"+dtbl).show();
  7921. }
  7922. return false;
  7923. });
  7924. $("#eData", "#"+dtbl+"_2").click(function(e){
  7925. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:rp_ge[$t.p.id].jqModal, onClose: rp_ge[$t.p.id].onClose});
  7926. return false;
  7927. });
  7928. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm($("#"+dtbl));}
  7929. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:rp_ge[$t.p.id].jqModal, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal});
  7930. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm($("#"+dtbl));}
  7931. }
  7932. if(rp_ge[$t.p.id].closeOnEscape===true) {
  7933. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+IDs.modalhead).focus();},0);
  7934. }
  7935. });
  7936. },
  7937. navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
  7938. o = $.extend({
  7939. edit: true,
  7940. editicon: "ui-icon-pencil",
  7941. add: true,
  7942. addicon:"ui-icon-plus",
  7943. del: true,
  7944. delicon:"ui-icon-trash",
  7945. search: true,
  7946. searchicon:"ui-icon-search",
  7947. refresh: true,
  7948. refreshicon:"ui-icon-refresh",
  7949. refreshstate: 'firstpage',
  7950. view: false,
  7951. viewicon : "ui-icon-document",
  7952. position : "left",
  7953. closeOnEscape : true,
  7954. beforeRefresh : null,
  7955. afterRefresh : null,
  7956. cloneToTop : false,
  7957. alertwidth : 200,
  7958. alertheight : 'auto',
  7959. alerttop: null,
  7960. alertleft: null,
  7961. alertzIndex : null
  7962. }, $.jgrid.nav, o ||{});
  7963. return this.each(function() {
  7964. if(this.nav) {return;}
  7965. var alertIDs = {themodal:'alertmod',modalhead:'alerthd',modalcontent:'alertcnt'},
  7966. $t = this, twd, tdw;
  7967. if(!$t.grid || typeof elem != 'string') {return;}
  7968. if ($("#"+alertIDs.themodal).html() === null) {
  7969. if(!o.alerttop && !o.alertleft) {
  7970. if (typeof window.innerWidth != 'undefined') {
  7971. o.alertleft = window.innerWidth;
  7972. o.alerttop = window.innerHeight;
  7973. } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth !== 0) {
  7974. o.alertleft = document.documentElement.clientWidth;
  7975. o.alerttop = document.documentElement.clientHeight;
  7976. } else {
  7977. o.alertleft=1024;
  7978. o.alerttop=768;
  7979. }
  7980. o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2;
  7981. o.alerttop = o.alerttop/2-25;
  7982. }
  7983. $.jgrid.createModal(alertIDs,"<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",{gbox:"#gbox_"+$t.p.id,jqModal:true,drag:true,resize:true,caption:o.alertcap,top:o.alerttop,left:o.alertleft,width:o.alertwidth,height: o.alertheight,closeOnEscape:o.closeOnEscape, zIndex: o.alertzIndex},"","",true);
  7984. }
  7985. var clone = 1;
  7986. if(o.cloneToTop && $t.p.toppager) {clone = 2;}
  7987. for(var i = 0; i<clone; i++) {
  7988. var tbd,
  7989. navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
  7990. sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  7991. pgid, elemids;
  7992. if(i===0) {
  7993. pgid = elem;
  7994. elemids = $t.p.id;
  7995. if(pgid == $t.p.toppager) {
  7996. elemids += "_top";
  7997. clone = 1;
  7998. }
  7999. } else {
  8000. pgid = $t.p.toppager;
  8001. elemids = $t.p.id+"_top";
  8002. }
  8003. if($t.p.direction == "rtl") {$(navtbl).attr("dir","rtl").css("float","right");}
  8004. if (o.add) {
  8005. pAdd = pAdd || {};
  8006. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8007. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
  8008. $("tr",navtbl).append(tbd);
  8009. $(tbd,navtbl)
  8010. .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
  8011. .click(function(){
  8012. if (!$(this).hasClass('ui-state-disabled')) {
  8013. if ($.isFunction( o.addfunc )) {
  8014. o.addfunc();
  8015. } else {
  8016. $($t).jqGrid("editGridRow","new",pAdd);
  8017. }
  8018. }
  8019. return false;
  8020. }).hover(
  8021. function () {
  8022. if (!$(this).hasClass('ui-state-disabled')) {
  8023. $(this).addClass("ui-state-hover");
  8024. }
  8025. },
  8026. function () {$(this).removeClass("ui-state-hover");}
  8027. );
  8028. tbd = null;
  8029. }
  8030. if (o.edit) {
  8031. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8032. pEdit = pEdit || {};
  8033. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
  8034. $("tr",navtbl).append(tbd);
  8035. $(tbd,navtbl)
  8036. .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
  8037. .click(function(){
  8038. if (!$(this).hasClass('ui-state-disabled')) {
  8039. var sr = $t.p.selrow;
  8040. if (sr) {
  8041. if($.isFunction( o.editfunc ) ) {
  8042. o.editfunc(sr);
  8043. } else {
  8044. $($t).jqGrid("editGridRow",sr,pEdit);
  8045. }
  8046. } else {
  8047. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true});
  8048. $("#jqg_alrt").focus();
  8049. }
  8050. }
  8051. return false;
  8052. }).hover(
  8053. function () {
  8054. if (!$(this).hasClass('ui-state-disabled')) {
  8055. $(this).addClass("ui-state-hover");
  8056. }
  8057. },
  8058. function () {$(this).removeClass("ui-state-hover");}
  8059. );
  8060. tbd = null;
  8061. }
  8062. if (o.view) {
  8063. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8064. pView = pView || {};
  8065. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
  8066. $("tr",navtbl).append(tbd);
  8067. $(tbd,navtbl)
  8068. .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
  8069. .click(function(){
  8070. if (!$(this).hasClass('ui-state-disabled')) {
  8071. var sr = $t.p.selrow;
  8072. if (sr) {
  8073. if($.isFunction( o.viewfunc ) ) {
  8074. o.viewfunc(sr);
  8075. } else {
  8076. $($t).jqGrid("viewGridRow",sr,pView);
  8077. }
  8078. } else {
  8079. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true});
  8080. $("#jqg_alrt").focus();
  8081. }
  8082. }
  8083. return false;
  8084. }).hover(
  8085. function () {
  8086. if (!$(this).hasClass('ui-state-disabled')) {
  8087. $(this).addClass("ui-state-hover");
  8088. }
  8089. },
  8090. function () {$(this).removeClass("ui-state-hover");}
  8091. );
  8092. tbd = null;
  8093. }
  8094. if (o.del) {
  8095. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8096. pDel = pDel || {};
  8097. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
  8098. $("tr",navtbl).append(tbd);
  8099. $(tbd,navtbl)
  8100. .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
  8101. .click(function(){
  8102. if (!$(this).hasClass('ui-state-disabled')) {
  8103. var dr;
  8104. if($t.p.multiselect) {
  8105. dr = $t.p.selarrrow;
  8106. if(dr.length===0) {dr = null;}
  8107. } else {
  8108. dr = $t.p.selrow;
  8109. }
  8110. if(dr){
  8111. if("function" == typeof o.delfunc){
  8112. o.delfunc(dr);
  8113. }else{
  8114. $($t).jqGrid("delGridRow",dr,pDel);
  8115. }
  8116. } else {
  8117. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true});$("#jqg_alrt").focus();
  8118. }
  8119. }
  8120. return false;
  8121. }).hover(
  8122. function () {
  8123. if (!$(this).hasClass('ui-state-disabled')) {
  8124. $(this).addClass("ui-state-hover");
  8125. }
  8126. },
  8127. function () {$(this).removeClass("ui-state-hover");}
  8128. );
  8129. tbd = null;
  8130. }
  8131. if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);}
  8132. if (o.search) {
  8133. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8134. pSearch = pSearch || {};
  8135. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
  8136. $("tr",navtbl).append(tbd);
  8137. $(tbd,navtbl)
  8138. .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
  8139. .click(function(){
  8140. if (!$(this).hasClass('ui-state-disabled')) {
  8141. $($t).jqGrid("searchGrid",pSearch);
  8142. }
  8143. return false;
  8144. }).hover(
  8145. function () {
  8146. if (!$(this).hasClass('ui-state-disabled')) {
  8147. $(this).addClass("ui-state-hover");
  8148. }
  8149. },
  8150. function () {$(this).removeClass("ui-state-hover");}
  8151. );
  8152. if (pSearch.showOnLoad && pSearch.showOnLoad === true)
  8153. $(tbd,navtbl).click();
  8154. tbd = null;
  8155. }
  8156. if (o.refresh) {
  8157. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8158. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
  8159. $("tr",navtbl).append(tbd);
  8160. $(tbd,navtbl)
  8161. .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
  8162. .click(function(){
  8163. if (!$(this).hasClass('ui-state-disabled')) {
  8164. if($.isFunction(o.beforeRefresh)) {o.beforeRefresh();}
  8165. $t.p.search = false;
  8166. try {
  8167. var gID = $t.p.id;
  8168. $t.p.postData.filters ="";
  8169. $("#fbox_"+gID).jqFilter('resetFilter');
  8170. if($.isFunction($t.clearToolbar)) {$t.clearToolbar(false);}
  8171. } catch (e) {}
  8172. switch (o.refreshstate) {
  8173. case 'firstpage':
  8174. $($t).trigger("reloadGrid", [{page:1}]);
  8175. break;
  8176. case 'current':
  8177. $($t).trigger("reloadGrid", [{current:true}]);
  8178. break;
  8179. }
  8180. if($.isFunction(o.afterRefresh)) {o.afterRefresh();}
  8181. }
  8182. return false;
  8183. }).hover(
  8184. function () {
  8185. if (!$(this).hasClass('ui-state-disabled')) {
  8186. $(this).addClass("ui-state-hover");
  8187. }
  8188. },
  8189. function () {$(this).removeClass("ui-state-hover");}
  8190. );
  8191. tbd = null;
  8192. }
  8193. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  8194. $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  8195. twd = $(navtbl).clone().appendTo("#testpg2").width();
  8196. $("#testpg2").remove();
  8197. $(pgid+"_"+o.position,pgid).append(navtbl);
  8198. if($t.p._nvtd) {
  8199. if(twd > $t.p._nvtd[0] ) {
  8200. $(pgid+"_"+o.position,pgid).width(twd);
  8201. $t.p._nvtd[0] = twd;
  8202. }
  8203. $t.p._nvtd[1] = twd;
  8204. }
  8205. tdw =null;twd=null;navtbl =null;
  8206. this.nav = true;
  8207. }
  8208. });
  8209. },
  8210. navButtonAdd : function (elem, p) {
  8211. p = $.extend({
  8212. caption : "newButton",
  8213. title: '',
  8214. buttonicon : 'ui-icon-newwin',
  8215. onClickButton: null,
  8216. position : "last",
  8217. cursor : 'pointer'
  8218. }, p ||{});
  8219. return this.each(function() {
  8220. if( !this.grid) {return;}
  8221. if( elem.indexOf("#") !== 0) {elem = "#"+elem;}
  8222. var findnav = $(".navtable",elem)[0], $t = this;
  8223. if (findnav) {
  8224. if( p.id && $("#"+p.id, findnav).html() !== null ) {return;}
  8225. var tbd = $("<td></td>");
  8226. if(p.buttonicon.toString().toUpperCase() == "NONE") {
  8227. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
  8228. } else {
  8229. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
  8230. }
  8231. if(p.id) {$(tbd).attr("id",p.id);}
  8232. if(p.position=='first'){
  8233. if(findnav.rows[0].cells.length ===0 ) {
  8234. $("tr",findnav).append(tbd);
  8235. } else {
  8236. $("tr td:eq(0)",findnav).before(tbd);
  8237. }
  8238. } else {
  8239. $("tr",findnav).append(tbd);
  8240. }
  8241. $(tbd,findnav)
  8242. .attr("title",p.title || "")
  8243. .click(function(e){
  8244. if (!$(this).hasClass('ui-state-disabled')) {
  8245. if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);}
  8246. }
  8247. return false;
  8248. })
  8249. .hover(
  8250. function () {
  8251. if (!$(this).hasClass('ui-state-disabled')) {
  8252. $(this).addClass('ui-state-hover');
  8253. }
  8254. },
  8255. function () {$(this).removeClass("ui-state-hover");}
  8256. );
  8257. }
  8258. });
  8259. },
  8260. navSeparatorAdd:function (elem,p) {
  8261. p = $.extend({
  8262. sepclass : "ui-separator",
  8263. sepcontent: ''
  8264. }, p ||{});
  8265. return this.each(function() {
  8266. if( !this.grid) {return;}
  8267. if( elem.indexOf("#") !== 0) {elem = "#"+elem;}
  8268. var findnav = $(".navtable",elem)[0];
  8269. if(findnav) {
  8270. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
  8271. $("tr",findnav).append(sep);
  8272. }
  8273. });
  8274. },
  8275. GridToForm : function( rowid, formid ) {
  8276. return this.each(function(){
  8277. var $t = this;
  8278. if (!$t.grid) {return;}
  8279. var rowdata = $($t).jqGrid("getRowData",rowid);
  8280. if (rowdata) {
  8281. for(var i in rowdata) {
  8282. if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
  8283. $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
  8284. if( $(this).val() == rowdata[i] ) {
  8285. $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  8286. } else {
  8287. $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  8288. }
  8289. });
  8290. } else {
  8291. // this is very slow on big table and form.
  8292. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]);
  8293. }
  8294. }
  8295. }
  8296. });
  8297. },
  8298. FormToGrid : function(rowid, formid, mode, position){
  8299. return this.each(function() {
  8300. var $t = this;
  8301. if(!$t.grid) {return;}
  8302. if(!mode) {mode = 'set';}
  8303. if(!position) {position = 'first';}
  8304. var fields = $(formid).serializeArray();
  8305. var griddata = {};
  8306. $.each(fields, function(i, field){
  8307. griddata[field.name] = field.value;
  8308. });
  8309. if(mode=='add') {$($t).jqGrid("addRowData",rowid,griddata, position);}
  8310. else if(mode=='set') {$($t).jqGrid("setRowData",rowid,griddata);}
  8311. });
  8312. }
  8313. });
  8314. })(jQuery);
  8315. ;(function($){
  8316. /**
  8317. * jqGrid extension for manipulating Grid Data
  8318. * Tony Tomov tony@trirand.com
  8319. * http://trirand.com/blog/
  8320. * Dual licensed under the MIT and GPL licenses:
  8321. * http://www.opensource.org/licenses/mit-license.php
  8322. * http://www.gnu.org/licenses/gpl-2.0.html
  8323. **/
  8324. $.jgrid.extend({
  8325. //Editing
  8326. editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  8327. // Compatible mode old versions
  8328. var settings = {
  8329. "keys" : keys || false,
  8330. "oneditfunc" : oneditfunc || null,
  8331. "successfunc" : successfunc || null,
  8332. "url" : url || null,
  8333. "extraparam" : extraparam || {},
  8334. "aftersavefunc" : aftersavefunc || null,
  8335. "errorfunc": errorfunc || null,
  8336. "afterrestorefunc" : afterrestorefunc|| null,
  8337. "restoreAfterError" : true,
  8338. "mtype" : "POST"
  8339. },
  8340. args = $.makeArray(arguments).slice(1), o;
  8341. if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
  8342. o = $.extend(settings,args[0]);
  8343. } else {
  8344. o = settings;
  8345. }
  8346. // End compatible
  8347. return this.each(function(){
  8348. var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm;
  8349. if (!$t.grid ) { return; }
  8350. ind = $($t).jqGrid("getInd",rowid,true);
  8351. if( ind === false ) {return;}
  8352. editable = $(ind).attr("editable") || "0";
  8353. if (editable == "0" && !$(ind).hasClass("not-editable-row")) {
  8354. cm = $t.p.colModel;
  8355. $('td',ind).each( function(i) {
  8356. nm = cm[i].name;
  8357. var treeg = $t.p.treeGrid===true && nm == $t.p.ExpandColumn;
  8358. if(treeg) { tmp = $("span:first",this).html();}
  8359. else {
  8360. try {
  8361. tmp = $.unformat(this,{rowId:rowid, colModel:cm[i]},i);
  8362. } catch (_) {
  8363. tmp = ( cm[i].edittype && cm[i].edittype == 'textarea' ) ? $(this).text() : $(this).html();
  8364. }
  8365. }
  8366. if ( nm != 'cb' && nm != 'subgrid' && nm != 'rn') {
  8367. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  8368. svr[nm]=tmp;
  8369. if(cm[i].editable===true) {
  8370. if(focus===null) { focus = i; }
  8371. if (treeg) { $("span:first",this).html(""); }
  8372. else { $(this).html(""); }
  8373. var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm});
  8374. if(!cm[i].edittype) { cm[i].edittype = "text"; }
  8375. if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
  8376. var elc = $.jgrid.createEl(cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  8377. $(elc).addClass("editable");
  8378. if(treeg) { $("span:first",this).append(elc); }
  8379. else { $(this).append(elc); }
  8380. //Again IE
  8381. if(cm[i].edittype == "select" && typeof(cm[i].editoptions)!=="undefined" && cm[i].editoptions.multiple===true && typeof(cm[i].editoptions.dataUrl)==="undefined" && $.browser.msie) {
  8382. $(elc).width($(elc).width());
  8383. }
  8384. cnt++;
  8385. }
  8386. }
  8387. });
  8388. if(cnt > 0) {
  8389. svr.id = rowid; $t.p.savedRow.push(svr);
  8390. $(ind).attr("editable","1");
  8391. $("td:eq("+focus+") input",ind).focus();
  8392. if(o.keys===true) {
  8393. $(ind).bind("keydown",function(e) {
  8394. if (e.keyCode === 27) {$($t).jqGrid("restoreRow",rowid, afterrestorefunc);}
  8395. if (e.keyCode === 13) {
  8396. var ta = e.target;
  8397. if(ta.tagName == 'TEXTAREA') { return true; }
  8398. $($t).jqGrid("saveRow", rowid, o );
  8399. return false;
  8400. }
  8401. e.stopPropagation();
  8402. });
  8403. }
  8404. if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
  8405. }
  8406. }
  8407. });
  8408. },
  8409. saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  8410. // Compatible mode old versions
  8411. var settings = {
  8412. "successfunc" : successfunc || null,
  8413. "url" : url || null,
  8414. "extraparam" : extraparam || {},
  8415. "aftersavefunc" : aftersavefunc || null,
  8416. "errorfunc": errorfunc || null,
  8417. "afterrestorefunc" : afterrestorefunc|| null,
  8418. "restoreAfterError" : true,
  8419. "mtype" : "POST"
  8420. },
  8421. args = $.makeArray(arguments).slice(1), o;
  8422. if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
  8423. o = $.extend(settings,args[0]);
  8424. } else {
  8425. o = settings;
  8426. }
  8427. // End compatible
  8428. var success = false;
  8429. var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
  8430. if (!$t.grid ) { return success; }
  8431. ind = $($t).jqGrid("getInd",rowid,true);
  8432. if(ind === false) {return success;}
  8433. editable = $(ind).attr("editable");
  8434. o.url = o.url ? o.url : $t.p.editurl;
  8435. if (editable==="1") {
  8436. var cm;
  8437. $("td",ind).each(function(i) {
  8438. cm = $t.p.colModel[i];
  8439. nm = cm.name;
  8440. if ( nm != 'cb' && nm != 'subgrid' && cm.editable===true && nm != 'rn' && !$(this).hasClass('not-editable-cell')) {
  8441. switch (cm.edittype) {
  8442. case "checkbox":
  8443. var cbv = ["Yes","No"];
  8444. if(cm.editoptions ) {
  8445. cbv = cm.editoptions.value.split(":");
  8446. }
  8447. tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  8448. break;
  8449. case 'text':
  8450. case 'password':
  8451. case 'textarea':
  8452. case "button" :
  8453. tmp[nm]=$("input, textarea",this).val();
  8454. break;
  8455. case 'select':
  8456. if(!cm.editoptions.multiple) {
  8457. tmp[nm] = $("select option:selected",this).val();
  8458. tmp2[nm] = $("select option:selected", this).text();
  8459. } else {
  8460. var sel = $("select",this), selectedText = [];
  8461. tmp[nm] = $(sel).val();
  8462. if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
  8463. $("select option:selected",this).each(
  8464. function(i,selected){
  8465. selectedText[i] = $(selected).text();
  8466. }
  8467. );
  8468. tmp2[nm] = selectedText.join(",");
  8469. }
  8470. if(cm.formatter && cm.formatter == 'select') { tmp2={}; }
  8471. break;
  8472. case 'custom' :
  8473. try {
  8474. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  8475. tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  8476. if (tmp[nm] === undefined) { throw "e2"; }
  8477. } else { throw "e1"; }
  8478. } catch (e) {
  8479. if (e=="e1") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose); }
  8480. if (e=="e2") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); }
  8481. else { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
  8482. }
  8483. break;
  8484. }
  8485. cv = $.jgrid.checkValues(tmp[nm],i,$t);
  8486. if(cv[0] === false) {
  8487. cv[1] = tmp[nm] + " " + cv[1];
  8488. return false;
  8489. }
  8490. if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
  8491. if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
  8492. if(tmp[nm] == "") {
  8493. tmp3[nm] = 'null';
  8494. }
  8495. }
  8496. }
  8497. });
  8498. if (cv[0] === false){
  8499. try {
  8500. var positions = $.jgrid.findPos($("#"+$.jgrid.jqID(rowid), $t.grid.bDiv)[0]);
  8501. $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]});
  8502. } catch (e) {
  8503. alert(cv[1]);
  8504. }
  8505. return success;
  8506. }
  8507. var idname, opers, oper;
  8508. opers = $t.p.prmNames;
  8509. oper = opers.oper;
  8510. idname = opers.id;
  8511. if(tmp) {
  8512. tmp[oper] = opers.editoper;
  8513. tmp[idname] = rowid;
  8514. if(typeof($t.p.inlineData) == 'undefined') { $t.p.inlineData ={}; }
  8515. tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
  8516. }
  8517. if (o.url == 'clientArray') {
  8518. tmp = $.extend({},tmp, tmp2);
  8519. if($t.p.autoencode) {
  8520. $.each(tmp,function(n,v){
  8521. tmp[n] = $.jgrid.htmlDecode(v);
  8522. });
  8523. }
  8524. var resp = $($t).jqGrid("setRowData",rowid,tmp);
  8525. $(ind).attr("editable","0");
  8526. for( var k=0;k<$t.p.savedRow.length;k++) {
  8527. if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
  8528. }
  8529. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  8530. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,resp); }
  8531. success = true;
  8532. $(ind).unbind("keydown");
  8533. } else {
  8534. $("#lui_"+$t.p.id).show();
  8535. tmp3 = $.extend({},tmp,tmp3);
  8536. tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
  8537. $.ajax($.extend({
  8538. url:o.url,
  8539. data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
  8540. type: o.mtype,
  8541. async : false, //?!?
  8542. complete: function(res,stat){
  8543. $("#lui_"+$t.p.id).hide();
  8544. if (stat === "success"){
  8545. var ret;
  8546. if( $.isFunction(o.successfunc)) { ret = o.successfunc.call($t, res);}
  8547. else { ret = true; }
  8548. if (ret===true) {
  8549. if($t.p.autoencode) {
  8550. $.each(tmp,function(n,v){
  8551. tmp[n] = $.jgrid.htmlDecode(v);
  8552. });
  8553. }
  8554. tmp = $.extend({},tmp, tmp2);
  8555. $($t).jqGrid("setRowData",rowid,tmp);
  8556. $(ind).attr("editable","0");
  8557. for( var k=0;k<$t.p.savedRow.length;k++) {
  8558. if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
  8559. }
  8560. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  8561. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,res); }
  8562. success = true;
  8563. $(ind).unbind("keydown");
  8564. } else {
  8565. if($.isFunction(o.errorfunc) ) {
  8566. o.errorfunc.call($t, rowid, res, stat);
  8567. }
  8568. if(o.restoreAfterError === true) {
  8569. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  8570. }
  8571. }
  8572. }
  8573. },
  8574. error:function(res,stat){
  8575. $("#lui_"+$t.p.id).hide();
  8576. if($.isFunction(o.errorfunc) ) {
  8577. o.errorfunc.call($t, rowid, res, stat);
  8578. } else {
  8579. try {
  8580. jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,'<div class="ui-state-error">'+ res.responseText +'</div>', jQuery.jgrid.edit.bClose,{buttonalign:'right'});
  8581. }
  8582. catch(e) {
  8583. alert(res.responseText);
  8584. }
  8585. }
  8586. if(o.restoreAfterError === true) {
  8587. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  8588. }
  8589. }
  8590. }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
  8591. }
  8592. }
  8593. return success;
  8594. },
  8595. restoreRow : function(rowid, afterrestorefunc) {
  8596. return this.each(function(){
  8597. var $t= this, fr, ind, ares={};
  8598. if (!$t.grid ) { return; }
  8599. ind = $($t).jqGrid("getInd",rowid,true);
  8600. if(ind === false) {return;}
  8601. for( var k=0;k<$t.p.savedRow.length;k++) {
  8602. if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
  8603. }
  8604. if(fr >= 0) {
  8605. if($.isFunction($.fn.datepicker)) {
  8606. try {
  8607. $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
  8608. } catch (e) {}
  8609. }
  8610. $.each($t.p.colModel, function(i,n){
  8611. if(this.editable === true && this.name in $t.p.savedRow[fr] && !$(this).hasClass('not-editable-cell')) {
  8612. ares[this.name] = $t.p.savedRow[fr][this.name];
  8613. }
  8614. });
  8615. $($t).jqGrid("setRowData",rowid,ares);
  8616. $(ind).attr("editable","0").unbind("keydown");
  8617. $t.p.savedRow.splice(fr,1);
  8618. }
  8619. if ($.isFunction(afterrestorefunc))
  8620. {
  8621. afterrestorefunc.call($t, rowid);
  8622. }
  8623. });
  8624. }
  8625. //end inline edit
  8626. });
  8627. })(jQuery);
  8628. ;(function($){
  8629. /*
  8630. **
  8631. * jqGrid extension for cellediting Grid Data
  8632. * Tony Tomov tony@trirand.com
  8633. * http://trirand.com/blog/
  8634. * Dual licensed under the MIT and GPL licenses:
  8635. * http://www.opensource.org/licenses/mit-license.php
  8636. * http://www.gnu.org/licenses/gpl-2.0.html
  8637. **/
  8638. /**
  8639. * all events and options here are aded anonynous and not in the base grid
  8640. * since the array is to big. Here is the order of execution.
  8641. * From this point we use jQuery isFunction
  8642. * formatCell
  8643. * beforeEditCell,
  8644. * onSelectCell (used only for noneditable cels)
  8645. * afterEditCell,
  8646. * beforeSaveCell, (called before validation of values if any)
  8647. * beforeSubmitCell (if cellsubmit remote (ajax))
  8648. * afterSubmitCell(if cellsubmit remote (ajax)),
  8649. * afterSaveCell,
  8650. * errorCell,
  8651. * serializeCellData - new
  8652. * Options
  8653. * cellsubmit (remote,clientArray) (added in grid options)
  8654. * cellurl
  8655. * ajaxCellOptions
  8656. * */
  8657. $.jgrid.extend({
  8658. editCell : function (iRow,iCol, ed){
  8659. return this.each(function (){
  8660. var $t = this, nm, tmp,cc, cm;
  8661. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  8662. iCol = parseInt(iCol,10);
  8663. // select the row that can be used for other methods
  8664. $t.p.selrow = $t.rows[iRow].id;
  8665. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  8666. // check to see if we have already edited cell
  8667. if ($t.p.savedRow.length>0) {
  8668. // prevent second click on that field and enable selects
  8669. if (ed===true ) {
  8670. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  8671. return;
  8672. }
  8673. }
  8674. // save the cell
  8675. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  8676. } else {
  8677. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  8678. }
  8679. cm = $t.p.colModel[iCol];
  8680. nm = cm.name;
  8681. if (nm=='subgrid' || nm=='cb' || nm=='rn') {return;}
  8682. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  8683. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
  8684. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  8685. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  8686. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  8687. }
  8688. $(cc).addClass("edit-cell ui-state-highlight");
  8689. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  8690. try {
  8691. tmp = $.unformat(cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  8692. } catch (_) {
  8693. tmp = ( cm.edittype && cm.edittype == 'textarea' ) ? $(cc).text() : $(cc).html();
  8694. }
  8695. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  8696. if (!cm.edittype) {cm.edittype = "text";}
  8697. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  8698. if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
  8699. if($.isFunction($t.p.formatCell)) {
  8700. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  8701. if(tmp2 !== undefined ) {tmp = tmp2;}
  8702. }
  8703. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm});
  8704. var elc = $.jgrid.createEl(cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  8705. if ($.isFunction($t.p.beforeEditCell)) {
  8706. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  8707. }
  8708. $(cc).html("").append(elc).attr("tabindex","0");
  8709. window.setTimeout(function () { $(elc).focus();},0);
  8710. $("input, select, textarea",cc).bind("keydown",function(e) {
  8711. if (e.keyCode === 27) {
  8712. if($("input.hasDatepicker",cc).length >0) {
  8713. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  8714. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  8715. } else {
  8716. $($t).jqGrid("restoreCell",iRow,iCol);
  8717. }
  8718. } //ESC
  8719. if (e.keyCode === 13) {$($t).jqGrid("saveCell",iRow,iCol);}//Enter
  8720. if (e.keyCode == 9) {
  8721. if(!$t.grid.hDiv.loading ) {
  8722. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  8723. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  8724. } else {
  8725. return false;
  8726. }
  8727. }
  8728. e.stopPropagation();
  8729. });
  8730. if ($.isFunction($t.p.afterEditCell)) {
  8731. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  8732. }
  8733. } else {
  8734. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  8735. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  8736. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  8737. }
  8738. cc.addClass("edit-cell ui-state-highlight");
  8739. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  8740. if ($.isFunction($t.p.onSelectCell)) {
  8741. tmp = cc.html().replace(/\&#160\;/ig,'');
  8742. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  8743. }
  8744. }
  8745. $t.p.iCol = iCol; $t.p.iRow = iRow;
  8746. });
  8747. },
  8748. saveCell : function (iRow, iCol){
  8749. return this.each(function(){
  8750. var $t= this, fr;
  8751. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  8752. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  8753. if(fr !== null) {
  8754. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  8755. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
  8756. switch (cm.edittype) {
  8757. case "select":
  8758. if(!cm.editoptions.multiple) {
  8759. v = $("#"+iRow+"_"+nmjq+">option:selected",$t.rows[iRow]).val();
  8760. v2 = $("#"+iRow+"_"+nmjq+">option:selected",$t.rows[iRow]).text();
  8761. } else {
  8762. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  8763. v = $(sel).val();
  8764. if(v) { v.join(",");} else { v=""; }
  8765. $("option:selected",sel).each(
  8766. function(i,selected){
  8767. selectedText[i] = $(selected).text();
  8768. }
  8769. );
  8770. v2 = selectedText.join(",");
  8771. }
  8772. if(cm.formatter) { v2 = v; }
  8773. break;
  8774. case "checkbox":
  8775. var cbv = ["Yes","No"];
  8776. if(cm.editoptions){
  8777. cbv = cm.editoptions.value.split(":");
  8778. }
  8779. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  8780. v2=v;
  8781. break;
  8782. case "password":
  8783. case "text":
  8784. case "textarea":
  8785. case "button" :
  8786. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  8787. v2=v;
  8788. break;
  8789. case 'custom' :
  8790. try {
  8791. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  8792. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  8793. if (v===undefined) { throw "e2";} else { v2=v; }
  8794. } else { throw "e1"; }
  8795. } catch (e) {
  8796. if (e=="e1") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose); }
  8797. if (e=="e2") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); }
  8798. else {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
  8799. }
  8800. break;
  8801. }
  8802. // The common approach is if nothing changed do not do anything
  8803. if (v2 !== $t.p.savedRow[fr].v){
  8804. if ($.isFunction($t.p.beforeSaveCell)) {
  8805. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  8806. if (vv) {v = vv; v2=vv;}
  8807. }
  8808. var cv = $.jgrid.checkValues(v,iCol,$t);
  8809. if(cv[0] === true) {
  8810. var addpost = {};
  8811. if ($.isFunction($t.p.beforeSubmitCell)) {
  8812. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  8813. if (!addpost) {addpost={};}
  8814. }
  8815. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  8816. if ($t.p.cellsubmit == 'remote') {
  8817. if ($t.p.cellurl) {
  8818. var postdata = {};
  8819. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  8820. postdata[nm] = v;
  8821. var idname,oper, opers;
  8822. opers = $t.p.prmNames;
  8823. idname = opers.id;
  8824. oper = opers.oper;
  8825. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  8826. postdata[oper] = opers.editoper;
  8827. postdata = $.extend(addpost,postdata);
  8828. $("#lui_"+$t.p.id).show();
  8829. $t.grid.hDiv.loading = true;
  8830. $.ajax( $.extend( {
  8831. url: $t.p.cellurl,
  8832. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
  8833. type: "POST",
  8834. complete: function (result, stat) {
  8835. $("#lui_"+$t.p.id).hide();
  8836. $t.grid.hDiv.loading = false;
  8837. if (stat == 'success') {
  8838. if ($.isFunction($t.p.afterSubmitCell)) {
  8839. var ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  8840. if(ret[0] === true) {
  8841. $(cc).empty();
  8842. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  8843. $(cc).addClass("dirty-cell");
  8844. $($t.rows[iRow]).addClass("edited");
  8845. if ($.isFunction($t.p.afterSaveCell)) {
  8846. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  8847. }
  8848. $t.p.savedRow.splice(0,1);
  8849. } else {
  8850. $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
  8851. $($t).jqGrid("restoreCell",iRow,iCol);
  8852. }
  8853. } else {
  8854. $(cc).empty();
  8855. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  8856. $(cc).addClass("dirty-cell");
  8857. $($t.rows[iRow]).addClass("edited");
  8858. if ($.isFunction($t.p.afterSaveCell)) {
  8859. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  8860. }
  8861. $t.p.savedRow.splice(0,1);
  8862. }
  8863. }
  8864. },
  8865. error:function(res,stat) {
  8866. $("#lui_"+$t.p.id).hide();
  8867. $t.grid.hDiv.loading = false;
  8868. if ($.isFunction($t.p.errorCell)) {
  8869. $t.p.errorCell.call($t, res,stat);
  8870. $($t).jqGrid("restoreCell",iRow,iCol);
  8871. } else {
  8872. $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
  8873. $($t).jqGrid("restoreCell",iRow,iCol);
  8874. }
  8875. }
  8876. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  8877. } else {
  8878. try {
  8879. $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
  8880. $($t).jqGrid("restoreCell",iRow,iCol);
  8881. } catch (e) {}
  8882. }
  8883. }
  8884. if ($t.p.cellsubmit == 'clientArray') {
  8885. $(cc).empty();
  8886. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  8887. $(cc).addClass("dirty-cell");
  8888. $($t.rows[iRow]).addClass("edited");
  8889. if ($.isFunction($t.p.afterSaveCell)) {
  8890. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  8891. }
  8892. $t.p.savedRow.splice(0,1);
  8893. }
  8894. } else {
  8895. try {
  8896. window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
  8897. $($t).jqGrid("restoreCell",iRow,iCol);
  8898. } catch (e) {}
  8899. }
  8900. } else {
  8901. $($t).jqGrid("restoreCell",iRow,iCol);
  8902. }
  8903. }
  8904. if ($.browser.opera) {
  8905. $("#"+$t.p.knv).attr("tabindex","-1").focus();
  8906. } else {
  8907. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  8908. }
  8909. });
  8910. },
  8911. restoreCell : function(iRow, iCol) {
  8912. return this.each(function(){
  8913. var $t= this, fr;
  8914. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  8915. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  8916. if(fr !== null) {
  8917. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  8918. // datepicker fix
  8919. if($.isFunction($.fn.datepicker)) {
  8920. try {
  8921. $("input.hasDatepicker",cc).datepicker('hide');
  8922. } catch (e) {}
  8923. }
  8924. $(cc).empty().attr("tabindex","-1");
  8925. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  8926. if ($.isFunction($t.p.afterRestoreCell)) {
  8927. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  8928. }
  8929. $t.p.savedRow.splice(0,1);
  8930. }
  8931. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  8932. });
  8933. },
  8934. nextCell : function (iRow,iCol) {
  8935. return this.each(function (){
  8936. var $t = this, nCol=false;
  8937. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  8938. // try to find next editable cell
  8939. for (var i=iCol+1; i<$t.p.colModel.length; i++) {
  8940. if ( $t.p.colModel[i].editable ===true) {
  8941. nCol = i; break;
  8942. }
  8943. }
  8944. if(nCol !== false) {
  8945. $($t).jqGrid("editCell",iRow,nCol,true);
  8946. } else {
  8947. if ($t.p.savedRow.length >0) {
  8948. $($t).jqGrid("saveCell",iRow,iCol);
  8949. }
  8950. }
  8951. });
  8952. },
  8953. prevCell : function (iRow,iCol) {
  8954. return this.each(function (){
  8955. var $t = this, nCol=false;
  8956. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  8957. // try to find next editable cell
  8958. for (var i=iCol-1; i>=0; i--) {
  8959. if ( $t.p.colModel[i].editable ===true) {
  8960. nCol = i; break;
  8961. }
  8962. }
  8963. if(nCol !== false) {
  8964. $($t).jqGrid("editCell",iRow,nCol,true);
  8965. } else {
  8966. if ($t.p.savedRow.length >0) {
  8967. $($t).jqGrid("saveCell",iRow,iCol);
  8968. }
  8969. }
  8970. });
  8971. },
  8972. GridNav : function() {
  8973. return this.each(function () {
  8974. var $t = this;
  8975. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  8976. // trick to process keydown on non input elements
  8977. $t.p.knv = $t.p.id + "_kn";
  8978. var selection = $("<span style='width:0px;height:0px;background-color:black;' tabindex='0'><span tabindex='-1' style='width:0px;height:0px;background-color:grey' id='"+$t.p.knv+"'></span></span>"),
  8979. i, kdir;
  8980. $(selection).insertBefore($t.grid.cDiv);
  8981. $("#"+$t.p.knv)
  8982. .focus()
  8983. .keydown(function (e){
  8984. kdir = e.keyCode;
  8985. if($t.p.direction == "rtl") {
  8986. if(kdir==37) { kdir = 39;}
  8987. else if (kdir==39) { kdir = 37; }
  8988. }
  8989. switch (kdir) {
  8990. case 38:
  8991. if ($t.p.iRow-1 >0 ) {
  8992. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  8993. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  8994. }
  8995. break;
  8996. case 40 :
  8997. if ($t.p.iRow+1 <= $t.rows.length-1) {
  8998. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  8999. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  9000. }
  9001. break;
  9002. case 37 :
  9003. if ($t.p.iCol -1 >= 0) {
  9004. i = findNextVisible($t.p.iCol-1,'lft');
  9005. scrollGrid($t.p.iRow, i,'h');
  9006. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  9007. }
  9008. break;
  9009. case 39 :
  9010. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  9011. i = findNextVisible($t.p.iCol+1,'rgt');
  9012. scrollGrid($t.p.iRow,i,'h');
  9013. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  9014. }
  9015. break;
  9016. case 13:
  9017. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9018. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  9019. }
  9020. break;
  9021. }
  9022. return false;
  9023. });
  9024. function scrollGrid(iR, iC, tp){
  9025. if (tp.substr(0,1)=='v') {
  9026. var ch = $($t.grid.bDiv)[0].clientHeight,
  9027. st = $($t.grid.bDiv)[0].scrollTop,
  9028. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  9029. pROT = $t.rows[iR].offsetTop;
  9030. if(tp == 'vd') {
  9031. if(nROT >= ch) {
  9032. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  9033. }
  9034. }
  9035. if(tp == 'vu'){
  9036. if (pROT < st ) {
  9037. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  9038. }
  9039. }
  9040. }
  9041. if(tp=='h') {
  9042. var cw = $($t.grid.bDiv)[0].clientWidth,
  9043. sl = $($t.grid.bDiv)[0].scrollLeft,
  9044. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  9045. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  9046. if(nCOL >= cw+parseInt(sl,10)) {
  9047. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  9048. } else if (pCOL < sl) {
  9049. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  9050. }
  9051. }
  9052. }
  9053. function findNextVisible(iC,act){
  9054. var ind, i;
  9055. if(act == 'lft') {
  9056. ind = iC+1;
  9057. for (i=iC;i>=0;i--){
  9058. if ($t.p.colModel[i].hidden !== true) {
  9059. ind = i;
  9060. break;
  9061. }
  9062. }
  9063. }
  9064. if(act == 'rgt') {
  9065. ind = iC-1;
  9066. for (i=iC; i<$t.p.colModel.length;i++){
  9067. if ($t.p.colModel[i].hidden !== true) {
  9068. ind = i;
  9069. break;
  9070. }
  9071. }
  9072. }
  9073. return ind;
  9074. }
  9075. });
  9076. },
  9077. getChangedCells : function (mthd) {
  9078. var ret=[];
  9079. if (!mthd) {mthd='all';}
  9080. this.each(function(){
  9081. var $t= this,nm;
  9082. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  9083. $($t.rows).each(function(j){
  9084. var res = {};
  9085. if ($(this).hasClass("edited")) {
  9086. $('td',this).each( function(i) {
  9087. nm = $t.p.colModel[i].name;
  9088. if ( nm !== 'cb' && nm !== 'subgrid') {
  9089. if (mthd=='dirty') {
  9090. if ($(this).hasClass('dirty-cell')) {
  9091. try {
  9092. res[nm] = $.unformat(this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  9093. } catch (e){
  9094. res[nm] = $.jgrid.htmlDecode($(this).html());
  9095. }
  9096. }
  9097. } else {
  9098. try {
  9099. res[nm] = $.unformat(this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  9100. } catch (e) {
  9101. res[nm] = $.jgrid.htmlDecode($(this).html());
  9102. }
  9103. }
  9104. }
  9105. });
  9106. res.id = this.id;
  9107. ret.push(res);
  9108. }
  9109. });
  9110. });
  9111. return ret;
  9112. }
  9113. /// end cell editing
  9114. });
  9115. })(jQuery);
  9116. ;(function($){
  9117. /**
  9118. * jqGrid extension for SubGrid Data
  9119. * Tony Tomov tony@trirand.com
  9120. * http://trirand.com/blog/
  9121. * Dual licensed under the MIT and GPL licenses:
  9122. * http://www.opensource.org/licenses/mit-license.php
  9123. * http://www.gnu.org/licenses/gpl-2.0.html
  9124. **/
  9125. $.jgrid.extend({
  9126. setSubGrid : function () {
  9127. return this.each(function (){
  9128. var $t = this, cm,
  9129. suboptions = {
  9130. plusicon : "ui-icon-plus",
  9131. minusicon : "ui-icon-minus",
  9132. openicon: "ui-icon-carat-1-sw",
  9133. expandOnLoad: false,
  9134. delayOnLoad : 50,
  9135. selectOnExpand : false,
  9136. reloadOnExpand : true
  9137. };
  9138. $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {});
  9139. $t.p.colNames.unshift("");
  9140. $t.p.colModel.unshift({name:'subgrid',width: $.browser.safari ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true});
  9141. cm = $t.p.subGridModel;
  9142. if(cm[0]) {
  9143. cm[0].align = $.extend([],cm[0].align || []);
  9144. for(var i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
  9145. }
  9146. });
  9147. },
  9148. addSubGridCell :function (pos,iRow) {
  9149. var prp='',ic,sid;
  9150. this.each(function(){
  9151. prp = this.formatCol(pos,iRow);
  9152. sid= this.p.id;
  9153. ic = this.p.subGridOptions.plusicon;
  9154. });
  9155. return "<td role=\"grid\" aria-describedby=\""+sid+"_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" "+prp+"><a href='javascript:void(0);'><span class='ui-icon "+ic+"'></span></a></td>";
  9156. },
  9157. addSubGrid : function( pos, sind ) {
  9158. return this.each(function(){
  9159. var ts = this;
  9160. if (!ts.grid ) { return; }
  9161. //-------------------------
  9162. var subGridCell = function(trdiv,cell,pos)
  9163. {
  9164. var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
  9165. $(trdiv).append(tddiv);
  9166. };
  9167. var subGridXml = function(sjxml, sbid){
  9168. var tddiv, i, sgmap,
  9169. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  9170. trdiv = $("<tr></tr>");
  9171. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  9172. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  9173. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  9174. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  9175. $(trdiv).append(tddiv);
  9176. }
  9177. $(dummy).append(trdiv);
  9178. if (sjxml){
  9179. sgmap = ts.p.xmlReader.subgrid;
  9180. $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
  9181. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  9182. if(sgmap.repeatitems === true) {
  9183. $(sgmap.cell,this).each( function(i) {
  9184. subGridCell(trdiv, $(this).text() || '&#160;',i);
  9185. });
  9186. } else {
  9187. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  9188. if (f) {
  9189. for (i=0;i<f.length;i++) {
  9190. subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
  9191. }
  9192. }
  9193. }
  9194. $(dummy).append(trdiv);
  9195. });
  9196. }
  9197. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  9198. $("#"+pID+sbid).append(dummy);
  9199. ts.grid.hDiv.loading = false;
  9200. $("#load_"+ts.p.id).hide();
  9201. return false;
  9202. };
  9203. var subGridJson = function(sjxml, sbid){
  9204. var tddiv,result , i,cur, sgmap,j,
  9205. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  9206. trdiv = $("<tr></tr>");
  9207. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  9208. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  9209. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  9210. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  9211. $(trdiv).append(tddiv);
  9212. }
  9213. $(dummy).append(trdiv);
  9214. if (sjxml){
  9215. sgmap = ts.p.jsonReader.subgrid;
  9216. result = sjxml[sgmap.root];
  9217. if ( typeof result !== 'undefined' ) {
  9218. for (i=0;i<result.length;i++) {
  9219. cur = result[i];
  9220. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  9221. if(sgmap.repeatitems === true) {
  9222. if(sgmap.cell) { cur=cur[sgmap.cell]; }
  9223. for (j=0;j<cur.length;j++) {
  9224. subGridCell(trdiv, cur[j] || '&#160;',j);
  9225. }
  9226. } else {
  9227. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  9228. if(f.length) {
  9229. for (j=0;j<f.length;j++) {
  9230. subGridCell(trdiv, cur[f[j]] || '&#160;',j);
  9231. }
  9232. }
  9233. }
  9234. $(dummy).append(trdiv);
  9235. }
  9236. }
  9237. }
  9238. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  9239. $("#"+pID+sbid).append(dummy);
  9240. ts.grid.hDiv.loading = false;
  9241. $("#load_"+ts.p.id).hide();
  9242. return false;
  9243. };
  9244. var populatesubgrid = function( rd )
  9245. {
  9246. var sid,dp, i, j;
  9247. sid = $(rd).attr("id");
  9248. dp = {nd_: (new Date().getTime())};
  9249. dp[ts.p.prmNames.subgridid]=sid;
  9250. if(!ts.p.subGridModel[0]) { return false; }
  9251. if(ts.p.subGridModel[0].params) {
  9252. for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
  9253. for(i=0; i<ts.p.colModel.length; i++) {
  9254. if(ts.p.colModel[i].name == ts.p.subGridModel[0].params[j]) {
  9255. dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
  9256. }
  9257. }
  9258. }
  9259. }
  9260. if(!ts.grid.hDiv.loading) {
  9261. ts.grid.hDiv.loading = true;
  9262. $("#load_"+ts.p.id).show();
  9263. if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
  9264. if($.isFunction(ts.p.subgridtype)) {
  9265. ts.p.subgridtype.call(ts, dp);
  9266. } else {
  9267. ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
  9268. }
  9269. switch(ts.p.subgridtype) {
  9270. case "xml":
  9271. case "json":
  9272. $.ajax($.extend({
  9273. type:ts.p.mtype,
  9274. url: ts.p.subGridUrl,
  9275. dataType:ts.p.subgridtype,
  9276. data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
  9277. complete: function(sxml) {
  9278. if(ts.p.subgridtype == "xml") {
  9279. subGridXml(sxml.responseXML, sid);
  9280. } else {
  9281. subGridJson($.jgrid.parse(sxml.responseText),sid);
  9282. }
  9283. sxml=null;
  9284. }
  9285. }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
  9286. break;
  9287. }
  9288. }
  9289. return false;
  9290. };
  9291. var _id, pID,atd, nhc=0, bfsc, r;
  9292. $.each(ts.p.colModel,function(i,v){
  9293. if(this.hidden === true || this.name == 'rn' || this.name == 'cb') {
  9294. nhc++;
  9295. }
  9296. });
  9297. var len = ts.rows.length, i=1;
  9298. if( sind !== undefined && sind > 0) {
  9299. i = sind;
  9300. len = sind+1;
  9301. }
  9302. while(i < len) {
  9303. if($(ts.rows[i]).hasClass('jqgrow')) {
  9304. $(ts.rows[i].cells[pos]).bind('click', function(e) {
  9305. var tr = $(this).parent("tr")[0];
  9306. r = tr.nextSibling;
  9307. if($(this).hasClass("sgcollapsed")) {
  9308. pID = ts.p.id;
  9309. _id = tr.id;
  9310. if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) {
  9311. atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
  9312. bfsc =true;
  9313. if($.isFunction(ts.p.subGridBeforeExpand)) {
  9314. bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id);
  9315. }
  9316. if(bfsc === false) {return false;}
  9317. $(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>" );
  9318. if( $.isFunction(ts.p.subGridRowExpanded)) {
  9319. ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
  9320. } else {
  9321. populatesubgrid(tr);
  9322. }
  9323. } else {
  9324. $(r).show();
  9325. }
  9326. $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
  9327. if(ts.p.subGridOptions.selectOnExpand) {
  9328. $(ts).jqGrid('setSelection',_id);
  9329. }
  9330. } else if($(this).hasClass("sgexpanded")) {
  9331. bfsc = true;
  9332. if( $.isFunction(ts.p.subGridRowColapsed)) {
  9333. _id = tr.id;
  9334. bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id );
  9335. }
  9336. if(bfsc===false) {return false;}
  9337. if(ts.p.subGridOptions.reloadOnExpand === true) {
  9338. $(r).remove(".ui-subgrid");
  9339. } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting
  9340. $(r).hide();
  9341. }
  9342. $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
  9343. }
  9344. return false;
  9345. });
  9346. }
  9347. if(ts.p.subGridOptions.expandOnLoad === true) {
  9348. $(ts.rows[i].cells[pos]).trigger('click');
  9349. }
  9350. i++;
  9351. }
  9352. ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
  9353. ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
  9354. });
  9355. },
  9356. expandSubGridRow : function(rowid) {
  9357. return this.each(function () {
  9358. var $t = this;
  9359. if(!$t.grid && !rowid) {return;}
  9360. if($t.p.subGrid===true) {
  9361. var rc = $(this).jqGrid("getInd",rowid,true);
  9362. if(rc) {
  9363. var sgc = $("td.sgcollapsed",rc)[0];
  9364. if(sgc) {
  9365. $(sgc).trigger("click");
  9366. }
  9367. }
  9368. }
  9369. });
  9370. },
  9371. collapseSubGridRow : function(rowid) {
  9372. return this.each(function () {
  9373. var $t = this;
  9374. if(!$t.grid && !rowid) {return;}
  9375. if($t.p.subGrid===true) {
  9376. var rc = $(this).jqGrid("getInd",rowid,true);
  9377. if(rc) {
  9378. var sgc = $("td.sgexpanded",rc)[0];
  9379. if(sgc) {
  9380. $(sgc).trigger("click");
  9381. }
  9382. }
  9383. }
  9384. });
  9385. },
  9386. toggleSubGridRow : function(rowid) {
  9387. return this.each(function () {
  9388. var $t = this;
  9389. if(!$t.grid && !rowid) {return;}
  9390. if($t.p.subGrid===true) {
  9391. var rc = $(this).jqGrid("getInd",rowid,true);
  9392. if(rc) {
  9393. var sgc = $("td.sgcollapsed",rc)[0];
  9394. if(sgc) {
  9395. $(sgc).trigger("click");
  9396. } else {
  9397. sgc = $("td.sgexpanded",rc)[0];
  9398. if(sgc) {
  9399. $(sgc).trigger("click");
  9400. }
  9401. }
  9402. }
  9403. }
  9404. });
  9405. }
  9406. });
  9407. })(jQuery);
  9408. /**
  9409. * jqGrid extension - Tree Grid
  9410. * Tony Tomov tony@trirand.com
  9411. * http://trirand.com/blog/
  9412. * Dual licensed under the MIT and GPL licenses:
  9413. * http://www.opensource.org/licenses/mit-license.php
  9414. * http://www.gnu.org/licenses/gpl.html
  9415. **/
  9416. /*global document, jQuery, $ */
  9417. (function($) {
  9418. $.jgrid.extend({
  9419. setTreeNode : function(i, len){
  9420. return this.each(function(){
  9421. var $t = this;
  9422. if( !$t.grid || !$t.p.treeGrid ) {return;}
  9423. var expCol = $t.p.expColInd,
  9424. expanded = $t.p.treeReader.expanded_field,
  9425. isLeaf = $t.p.treeReader.leaf_field,
  9426. level = $t.p.treeReader.level_field,
  9427. icon = $t.p.treeReader.icon_field,
  9428. loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap,
  9429. ldat, lf;
  9430. while(i<len) {
  9431. var ind = $t.rows[i].id, dind = $t.p._index[ind], expan;
  9432. ldat = $t.p.data[dind];
  9433. //$t.rows[i].level = ldat[level];
  9434. if($t.p.treeGridModel == 'nested') {
  9435. if(!ldat[isLeaf]) {
  9436. lft = parseInt(ldat[$t.p.treeReader.left_field],10);
  9437. rgt = parseInt(ldat[$t.p.treeReader.right_field],10);
  9438. // NS Model
  9439. ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false';
  9440. $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf];
  9441. }
  9442. }
  9443. //else {
  9444. //row.parent_id = rd[$t.p.treeReader.parent_id_field];
  9445. //}
  9446. curLevel = parseInt(ldat[level],10);
  9447. if($t.p.tree_root_level === 0) {
  9448. ident = curLevel+1;
  9449. lftpos = curLevel;
  9450. } else {
  9451. ident = curLevel;
  9452. lftpos = curLevel -1;
  9453. }
  9454. twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
  9455. twrap += "<div style='"+($t.p.direction=="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
  9456. if(ldat[loaded] !== undefined) {
  9457. if(ldat[loaded]=="true" || ldat[loaded]===true) {
  9458. ldat[loaded] = true;
  9459. } else {
  9460. ldat[loaded] = false;
  9461. }
  9462. }
  9463. if(ldat[isLeaf] == "true" || ldat[isLeaf] === true) {
  9464. twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick";
  9465. ldat[isLeaf] = true;
  9466. lf="leaf";
  9467. } else {
  9468. ldat[isLeaf] = false;
  9469. lf="";
  9470. }
  9471. ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) && ldat[loaded];
  9472. if(ldat[expanded] === false) {
  9473. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'");
  9474. } else {
  9475. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'");
  9476. }
  9477. twrap += "></div></div>";
  9478. $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap);
  9479. if(curLevel !== parseInt($t.p.tree_root_level,10)) {
  9480. var pn = $($t).jqGrid('getNodeParent',ldat);
  9481. expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true;
  9482. if( !expan ){
  9483. $($t.rows[i]).css("display","none");
  9484. }
  9485. }
  9486. $($t.rows[i].cells[expCol])
  9487. .find("div.treeclick")
  9488. .bind("click",function(e){
  9489. var target = e.target || e.srcElement,
  9490. ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
  9491. pos = $t.p._index[ind2];
  9492. if(!$t.p.data[pos][isLeaf]){
  9493. if($t.p.data[pos][expanded]){
  9494. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  9495. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  9496. } else {
  9497. $($t).jqGrid("expandRow",$t.p.data[pos]);
  9498. $($t).jqGrid("expandNode",$t.p.data[pos]);
  9499. }
  9500. }
  9501. return false;
  9502. });
  9503. if($t.p.ExpandColClick === true) {
  9504. $($t.rows[i].cells[expCol])
  9505. .find("span.cell-wrapper")
  9506. .css("cursor","pointer")
  9507. .bind("click",function(e) {
  9508. var target = e.target || e.srcElement,
  9509. ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
  9510. pos = $t.p._index[ind2];
  9511. if(!$t.p.data[pos][isLeaf]){
  9512. if($t.p.data[pos][expanded]){
  9513. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  9514. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  9515. } else {
  9516. $($t).jqGrid("expandRow",$t.p.data[pos]);
  9517. $($t).jqGrid("expandNode",$t.p.data[pos]);
  9518. }
  9519. }
  9520. $($t).jqGrid("setSelection",ind2);
  9521. return false;
  9522. });
  9523. }
  9524. i++;
  9525. }
  9526. });
  9527. },
  9528. setTreeGrid : function() {
  9529. return this.each(function (){
  9530. var $t = this, i=0, pico, ecol = false, nm, key, dupcols=[];
  9531. if(!$t.p.treeGrid) {return;}
  9532. if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});}
  9533. $t.p.subGrid = false;$t.p.altRows =false;
  9534. $t.p.pgbuttons = false;$t.p.pginput = false;
  9535. $t.p.gridview = true;
  9536. if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; }
  9537. $t.p.multiselect = false;$t.p.rowList = [];
  9538. $t.p.expColInd = 0;
  9539. pico = 'ui-icon-triangle-1-' + ($t.p.direction=="rtl" ? 'w' : 'e');
  9540. $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
  9541. if($t.p.treeGridModel == 'nested') {
  9542. $t.p.treeReader = $.extend({
  9543. level_field: "level",
  9544. left_field:"lft",
  9545. right_field: "rgt",
  9546. leaf_field: "isLeaf",
  9547. expanded_field: "expanded",
  9548. loaded: "loaded",
  9549. icon_field: "icon"
  9550. },$t.p.treeReader);
  9551. } else if($t.p.treeGridModel == 'adjacency') {
  9552. $t.p.treeReader = $.extend({
  9553. level_field: "level",
  9554. parent_id_field: "parent",
  9555. leaf_field: "isLeaf",
  9556. expanded_field: "expanded",
  9557. loaded: "loaded",
  9558. icon_field: "icon"
  9559. },$t.p.treeReader );
  9560. }
  9561. for ( key in $t.p.colModel){
  9562. if($t.p.colModel.hasOwnProperty(key)) {
  9563. nm = $t.p.colModel[key].name;
  9564. if( nm == $t.p.ExpandColumn && !ecol ) {
  9565. ecol = true;
  9566. $t.p.expColInd = i;
  9567. }
  9568. i++;
  9569. //
  9570. for(var tkey in $t.p.treeReader) {
  9571. if($t.p.treeReader[tkey] == nm)
  9572. dupcols.push(nm);
  9573. }
  9574. }
  9575. }
  9576. $.each($t.p.treeReader,function(j,n){
  9577. if(n && $.inArray(n, dupcols) === -1){
  9578. if(j==='leaf_field') { $t.p._treeleafpos= i; }
  9579. i++;
  9580. $t.p.colNames.push(n);
  9581. $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
  9582. }
  9583. });
  9584. });
  9585. },
  9586. expandRow: function (record){
  9587. this.each(function(){
  9588. var $t = this;
  9589. if(!$t.grid || !$t.p.treeGrid) {return;}
  9590. var childern = $($t).jqGrid("getNodeChildren",record),
  9591. //if ($($t).jqGrid("isVisibleNode",record)) {
  9592. expanded = $t.p.treeReader.expanded_field;
  9593. $(childern).each(function(i){
  9594. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  9595. $("#"+id,$t.grid.bDiv).css("display","");
  9596. if(this[expanded]) {
  9597. $($t).jqGrid("expandRow",this);
  9598. }
  9599. });
  9600. //}
  9601. });
  9602. },
  9603. collapseRow : function (record) {
  9604. this.each(function(){
  9605. var $t = this;
  9606. if(!$t.grid || !$t.p.treeGrid) {return;}
  9607. var childern = $($t).jqGrid("getNodeChildren",record),
  9608. expanded = $t.p.treeReader.expanded_field;
  9609. $(childern).each(function(i){
  9610. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  9611. $("#"+id,$t.grid.bDiv).css("display","none");
  9612. if(this[expanded]){
  9613. $($t).jqGrid("collapseRow",this);
  9614. }
  9615. });
  9616. });
  9617. },
  9618. // NS ,adjacency models
  9619. getRootNodes : function() {
  9620. var result = [];
  9621. this.each(function(){
  9622. var $t = this;
  9623. if(!$t.grid || !$t.p.treeGrid) {return;}
  9624. switch ($t.p.treeGridModel) {
  9625. case 'nested' :
  9626. var level = $t.p.treeReader.level_field;
  9627. $($t.p.data).each(function(i){
  9628. if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
  9629. result.push(this);
  9630. }
  9631. });
  9632. break;
  9633. case 'adjacency' :
  9634. var parent_id = $t.p.treeReader.parent_id_field;
  9635. $($t.p.data).each(function(i){
  9636. if(this[parent_id] === null || String(this[parent_id]).toLowerCase() == "null") {
  9637. result.push(this);
  9638. }
  9639. });
  9640. break;
  9641. }
  9642. });
  9643. return result;
  9644. },
  9645. getNodeDepth : function(rc) {
  9646. var ret = null;
  9647. this.each(function(){
  9648. if(!this.grid || !this.p.treeGrid) {return;}
  9649. var $t = this;
  9650. switch ($t.p.treeGridModel) {
  9651. case 'nested' :
  9652. var level = $t.p.treeReader.level_field;
  9653. ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
  9654. break;
  9655. case 'adjacency' :
  9656. ret = $($t).jqGrid("getNodeAncestors",rc).length;
  9657. break;
  9658. }
  9659. });
  9660. return ret;
  9661. },
  9662. getNodeParent : function(rc) {
  9663. var result = null;
  9664. this.each(function(){
  9665. var $t = this;
  9666. if(!$t.grid || !$t.p.treeGrid) {return;}
  9667. switch ($t.p.treeGridModel) {
  9668. case 'nested' :
  9669. var lftc = $t.p.treeReader.left_field,
  9670. rgtc = $t.p.treeReader.right_field,
  9671. levelc = $t.p.treeReader.level_field,
  9672. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  9673. $(this.p.data).each(function(){
  9674. if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
  9675. result = this;
  9676. return false;
  9677. }
  9678. });
  9679. break;
  9680. case 'adjacency' :
  9681. var parent_id = $t.p.treeReader.parent_id_field,
  9682. dtid = $t.p.localReader.id;
  9683. $(this.p.data).each(function(i,val){
  9684. if(this[dtid] == rc[parent_id] ) {
  9685. result = this;
  9686. return false;
  9687. }
  9688. });
  9689. break;
  9690. }
  9691. });
  9692. return result;
  9693. },
  9694. getNodeChildren : function(rc) {
  9695. var result = [];
  9696. this.each(function(){
  9697. var $t = this;
  9698. if(!$t.grid || !$t.p.treeGrid) {return;}
  9699. switch ($t.p.treeGridModel) {
  9700. case 'nested' :
  9701. var lftc = $t.p.treeReader.left_field,
  9702. rgtc = $t.p.treeReader.right_field,
  9703. levelc = $t.p.treeReader.level_field,
  9704. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  9705. $(this.p.data).each(function(i){
  9706. if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
  9707. result.push(this);
  9708. }
  9709. });
  9710. break;
  9711. case 'adjacency' :
  9712. var parent_id = $t.p.treeReader.parent_id_field,
  9713. dtid = $t.p.localReader.id;
  9714. $(this.p.data).each(function(i,val){
  9715. if(this[parent_id] == rc[dtid]) {
  9716. result.push(this);
  9717. }
  9718. });
  9719. break;
  9720. }
  9721. });
  9722. return result;
  9723. },
  9724. getFullTreeNode : function(rc) {
  9725. var result = [];
  9726. this.each(function(){
  9727. var $t = this, len;
  9728. if(!$t.grid || !$t.p.treeGrid) {return;}
  9729. switch ($t.p.treeGridModel) {
  9730. case 'nested' :
  9731. var lftc = $t.p.treeReader.left_field,
  9732. rgtc = $t.p.treeReader.right_field,
  9733. levelc = $t.p.treeReader.level_field,
  9734. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  9735. $(this.p.data).each(function(i){
  9736. if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
  9737. result.push(this);
  9738. }
  9739. });
  9740. break;
  9741. case 'adjacency' :
  9742. if(rc) {
  9743. result.push(rc);
  9744. var parent_id = $t.p.treeReader.parent_id_field,
  9745. dtid = $t.p.localReader.id;
  9746. $(this.p.data).each(function(i){
  9747. len = result.length;
  9748. for (i = 0; i < len; i++) {
  9749. if (result[i][dtid] == this[parent_id]) {
  9750. result.push(this);
  9751. break;
  9752. }
  9753. }
  9754. });
  9755. }
  9756. break;
  9757. }
  9758. });
  9759. return result;
  9760. },
  9761. // End NS, adjacency Model
  9762. getNodeAncestors : function(rc) {
  9763. var ancestors = [];
  9764. this.each(function(){
  9765. if(!this.grid || !this.p.treeGrid) {return;}
  9766. var parent = $(this).jqGrid("getNodeParent",rc);
  9767. while (parent) {
  9768. ancestors.push(parent);
  9769. parent = $(this).jqGrid("getNodeParent",parent);
  9770. }
  9771. });
  9772. return ancestors;
  9773. },
  9774. isVisibleNode : function(rc) {
  9775. var result = true;
  9776. this.each(function(){
  9777. var $t = this;
  9778. if(!$t.grid || !$t.p.treeGrid) {return;}
  9779. var ancestors = $($t).jqGrid("getNodeAncestors",rc),
  9780. expanded = $t.p.treeReader.expanded_field;
  9781. $(ancestors).each(function(){
  9782. result = result && this[expanded];
  9783. if(!result) {return false;}
  9784. });
  9785. });
  9786. return result;
  9787. },
  9788. isNodeLoaded : function(rc) {
  9789. var result;
  9790. this.each(function(){
  9791. var $t = this;
  9792. if(!$t.grid || !$t.p.treeGrid) {return;}
  9793. var isLeaf = $t.p.treeReader.leaf_field;
  9794. if(rc !== undefined ) {
  9795. if(rc.loaded !== undefined) {
  9796. result = rc.loaded;
  9797. } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
  9798. result = true;
  9799. } else {
  9800. result = false;
  9801. }
  9802. } else {
  9803. result = false;
  9804. }
  9805. });
  9806. return result;
  9807. },
  9808. expandNode : function(rc) {
  9809. return this.each(function(){
  9810. if(!this.grid || !this.p.treeGrid) {return;}
  9811. var expanded = this.p.treeReader.expanded_field,
  9812. parent = this.p.treeReader.parent_id_field,
  9813. loaded = this.p.treeReader.loaded,
  9814. level = this.p.treeReader.level_field,
  9815. lft = this.p.treeReader.left_field,
  9816. rgt = this.p.treeReader.right_field;
  9817. if(!rc[expanded]) {
  9818. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  9819. var rc1 = $("#"+id,this.grid.bDiv)[0];
  9820. var position = this.p._index[id];
  9821. if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
  9822. rc[expanded] = true;
  9823. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  9824. } else {
  9825. rc[expanded] = true;
  9826. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  9827. this.p.treeANode = rc1.rowIndex;
  9828. this.p.datatype = this.p.treedatatype;
  9829. if(this.p.treeGridModel == 'nested') {
  9830. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  9831. } else {
  9832. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  9833. }
  9834. $(this).trigger("reloadGrid");
  9835. rc[loaded] = true;
  9836. if(this.p.treeGridModel == 'nested') {
  9837. $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  9838. } else {
  9839. $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
  9840. }
  9841. }
  9842. }
  9843. });
  9844. },
  9845. collapseNode : function(rc) {
  9846. return this.each(function(){
  9847. if(!this.grid || !this.p.treeGrid) {return;}
  9848. if(rc.expanded) {
  9849. rc.expanded = false;
  9850. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  9851. var rc1 = $("#"+id,this.grid.bDiv)[0];
  9852. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
  9853. }
  9854. });
  9855. },
  9856. SortTree : function( sortname, newDir, st, datefmt) {
  9857. return this.each(function(){
  9858. if(!this.grid || !this.p.treeGrid) {return;}
  9859. var i, len,
  9860. rec, records = [], $t = this, query, roots,
  9861. rt = $(this).jqGrid("getRootNodes");
  9862. // Sorting roots
  9863. query = $.jgrid.from(rt);
  9864. query.orderBy(sortname,newDir,st, datefmt);
  9865. roots = query.select();
  9866. // Sorting children
  9867. for (i = 0, len = roots.length; i < len; i++) {
  9868. rec = roots[i];
  9869. records.push(rec);
  9870. $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
  9871. }
  9872. $.each(records, function(index, row) {
  9873. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  9874. $('#'+$t.p.id+ ' tbody tr:eq('+index+')').after($('tr#'+id,$t.grid.bDiv));
  9875. });
  9876. query = null;roots=null;records=null;
  9877. });
  9878. },
  9879. collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
  9880. return this.each(function(){
  9881. if(!this.grid || !this.p.treeGrid) {return;}
  9882. var i, len,
  9883. child, ch, query, children;
  9884. ch = $(this).jqGrid("getNodeChildren",rec);
  9885. query = $.jgrid.from(ch);
  9886. query.orderBy(sortname, newDir, st, datefmt);
  9887. children = query.select();
  9888. for (i = 0, len = children.length; i < len; i++) {
  9889. child = children[i];
  9890. records.push(child);
  9891. $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
  9892. }
  9893. });
  9894. },
  9895. // experimental
  9896. setTreeRow : function(rowid, data) {
  9897. var success=false;
  9898. this.each(function(){
  9899. var t = this;
  9900. if(!t.grid || !t.p.treeGrid) {return;}
  9901. success = $(t).jqGrid("setRowData",rowid,data);
  9902. });
  9903. return success;
  9904. },
  9905. delTreeNode : function (rowid) {
  9906. return this.each(function () {
  9907. var $t = this, rid = $t.p.localReader.id,
  9908. left = $t.p.treeReader.left_field,
  9909. right = $t.p.treeReader.right_field, myright, width, res, key;
  9910. if(!$t.grid || !$t.p.treeGrid) {return;}
  9911. var rc = $t.p._index[rowid];
  9912. if (rc !== undefined) {
  9913. // nested
  9914. myright = parseInt($t.p.data[rc][right],10);
  9915. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  9916. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  9917. if(dr.length>0){
  9918. for (var i=0;i<dr.length;i++){
  9919. $($t).jqGrid("delRowData",dr[i][rid]);
  9920. }
  9921. }
  9922. if( $t.p.treeGridModel === "nested") {
  9923. // ToDo - update grid data
  9924. res = $.jgrid.from($t.p.data)
  9925. .greater(left,myright,{stype:'integer'})
  9926. .select();
  9927. if(res.length) {
  9928. for( key in res) {
  9929. res[key][left] = parseInt(res[key][left],10) - width ;
  9930. }
  9931. }
  9932. res = $.jgrid.from($t.p.data)
  9933. .greater(right,myright,{stype:'integer'})
  9934. .select();
  9935. if(res.length) {
  9936. for( key in res) {
  9937. res[key][right] = parseInt(res[key][right],10) - width ;
  9938. }
  9939. }
  9940. }
  9941. }
  9942. });
  9943. },
  9944. addChildNode : function( nodeid, parentid, data ) {
  9945. //return this.each(function(){
  9946. var $t = this[0];
  9947. if(data) {
  9948. // we suppose tha the id is autoincremet and
  9949. var expanded = $t.p.treeReader.expanded_field,
  9950. isLeaf = $t.p.treeReader.leaf_field,
  9951. level = $t.p.treeReader.level_field,
  9952. icon = $t.p.treeReader.icon_field,
  9953. parent = $t.p.treeReader.parent_id_field,
  9954. left = $t.p.treeReader.left_field,
  9955. right = $t.p.treeReader.right_field,
  9956. loaded = $t.p.treeReader.loaded,
  9957. method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
  9958. if ( !nodeid ) {
  9959. i = $t.p.data.length-1;
  9960. if( i>= 0 ) {
  9961. while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;}
  9962. }
  9963. nodeid = max+1;
  9964. }
  9965. var prow = $($t).jqGrid('getInd', parentid);
  9966. leaf = false;
  9967. // if not a parent we assume root
  9968. if ( parentid === undefined || parentid === null || parentid==="") {
  9969. parentid = null;
  9970. rowind = null;
  9971. method = 'last';
  9972. parentlevel = $t.p.tree_root_level;
  9973. i = $t.p.data.length+1;
  9974. } else {
  9975. method = 'after';
  9976. parentindex = $t.p._index[parentid];
  9977. parentdata = $t.p.data[parentindex];
  9978. parentid = parentdata[$t.p.localReader.id];
  9979. parentlevel = parseInt(parentdata[level],10)+1;
  9980. var childs = $($t).jqGrid('getFullTreeNode', parentdata);
  9981. // if there are child nodes get the last index of it
  9982. if(childs.length) {
  9983. i = childs[childs.length-1][$t.p.localReader.id];
  9984. rowind = i;
  9985. i = $($t).jqGrid('getInd',rowind)+1;
  9986. } else {
  9987. i = $($t).jqGrid('getInd', parentid)+1;
  9988. }
  9989. // if the node is leaf
  9990. if(parentdata[isLeaf]) {
  9991. leaf = true;
  9992. parentdata[expanded] = true;
  9993. //var prow = $($t).jqGrid('getInd', parentid);
  9994. $($t.rows[prow])
  9995. .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
  9996. .end()
  9997. .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
  9998. $t.p.data[parentindex][isLeaf] = false;
  9999. parentdata[loaded] = true;
  10000. }
  10001. }
  10002. len = i+1;
  10003. data[expanded] = false;
  10004. data[loaded] = true;
  10005. data[level] = parentlevel;
  10006. data[isLeaf] = true;
  10007. if( $t.p.treeGridModel === "adjacency") {
  10008. data[parent] = parentid;
  10009. }
  10010. if( $t.p.treeGridModel === "nested") {
  10011. // this method requiere more attention
  10012. var query, res, key;
  10013. //maxright = parseInt(maxright,10);
  10014. // ToDo - update grid data
  10015. if(parentid !== null) {
  10016. maxright = parseInt(parentdata[right],10);
  10017. query = $.jgrid.from($t.p.data);
  10018. query = query.greaterOrEquals(right,maxright,{stype:'integer'});
  10019. res = query.select();
  10020. if(res.length) {
  10021. for( key in res) {
  10022. res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left];
  10023. res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right];
  10024. }
  10025. }
  10026. data[left] = maxright;
  10027. data[right]= maxright+1;
  10028. } else {
  10029. maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10);
  10030. res = $.jgrid.from($t.p.data)
  10031. .greater(left,maxright,{stype:'integer'})
  10032. .select();
  10033. if(res.length) {
  10034. for( key in res) {
  10035. res[key][left] = parseInt(res[key][left],10) +2 ;
  10036. }
  10037. }
  10038. res = $.jgrid.from($t.p.data)
  10039. .greater(right,maxright,{stype:'integer'})
  10040. .select();
  10041. if(res.length) {
  10042. for( key in res) {
  10043. res[key][right] = parseInt(res[key][right],10) +2 ;
  10044. }
  10045. }
  10046. data[left] = maxright+1;
  10047. data[right] = maxright + 2;
  10048. }
  10049. }
  10050. if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) {
  10051. $($t).jqGrid('addRowData', nodeid, data, method, rowind);
  10052. $($t).jqGrid('setTreeNode', i, len);
  10053. }
  10054. if(parentdata && !parentdata[expanded]) {
  10055. $($t.rows[prow])
  10056. .find("div.treeclick")
  10057. .click();
  10058. }
  10059. }
  10060. //});
  10061. }
  10062. });
  10063. })(jQuery);// Grouping module
  10064. ;(function($){
  10065. $.jgrid.extend({
  10066. groupingSetup : function () {
  10067. return this.each(function (){
  10068. var $t = this,
  10069. grp = $t.p.groupingView;
  10070. if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
  10071. if(!grp.groupField.length) {
  10072. $t.p.grouping = false;
  10073. } else {
  10074. if ( typeof(grp.visibiltyOnNextGrouping) == 'undefined') {
  10075. grp.visibiltyOnNextGrouping = [];
  10076. }
  10077. for(var i=0;i<grp.groupField.length;i++) {
  10078. if(!grp.groupOrder[i]) {
  10079. grp.groupOrder[i] = 'asc';
  10080. }
  10081. if(!grp.groupText[i]) {
  10082. grp.groupText[i] = '{0}';
  10083. }
  10084. if( typeof(grp.groupColumnShow[i]) != 'boolean') {
  10085. grp.groupColumnShow[i] = true;
  10086. }
  10087. if( typeof(grp.groupSummary[i]) != 'boolean') {
  10088. grp.groupSummary[i] = false;
  10089. }
  10090. if(grp.groupColumnShow[i] === true) {
  10091. grp.visibiltyOnNextGrouping[i] = true;
  10092. $($t).jqGrid('showCol',grp.groupField[i]);
  10093. } else {
  10094. grp.visibiltyOnNextGrouping[i] = $("#"+$t.p.id+"_"+grp.groupField[i]).is(":visible");
  10095. $($t).jqGrid('hideCol',grp.groupField[i]);
  10096. }
  10097. grp.sortitems[i] = [];
  10098. grp.sortnames[i] = [];
  10099. grp.summaryval[i] = [];
  10100. if(grp.groupSummary[i]) {
  10101. grp.summary[i] =[];
  10102. var cm = $t.p.colModel;
  10103. for(var j=0, cml = cm.length; j < cml; j++) {
  10104. if(cm[j].summaryType) {
  10105. grp.summary[i].push({nm:cm[j].name,st:cm[j].summaryType, v:''});
  10106. }
  10107. }
  10108. }
  10109. }
  10110. $t.p.scroll = false;
  10111. $t.p.rownumbers = false;
  10112. $t.p.subGrid = false;
  10113. $t.p.treeGrid = false;
  10114. $t.p.gridview = true;
  10115. }
  10116. } else {
  10117. $t.p.grouping = false;
  10118. }
  10119. });
  10120. },
  10121. groupingPrepare : function (rData, items, gdata, record) {
  10122. this.each(function(){
  10123. // currently only one level
  10124. // Is this a good idea to do it so!!!!?????
  10125. items[0] += "";
  10126. var itm = items[0].toString().split(' ').join('');
  10127. var grp = this.p.groupingView, $t= this;
  10128. if(gdata.hasOwnProperty(itm)) {
  10129. gdata[itm].push(rData);
  10130. } else {
  10131. gdata[itm] = [];
  10132. gdata[itm].push(rData);
  10133. grp.sortitems[0].push(itm);
  10134. grp.sortnames[0].push($.trim(items[0].toString()));
  10135. grp.summaryval[0][itm] = $.extend(true,[],grp.summary[0]);
  10136. }
  10137. if(grp.groupSummary[0]) {
  10138. $.each(grp.summaryval[0][itm],function() {
  10139. if ($.isFunction(this.st)) {
  10140. this.v = this.st.call($t, this.v, this.nm, record);
  10141. } else {
  10142. this.v = $($t).jqGrid('groupingCalculations.'+this.st, this.v, this.nm, record);
  10143. }
  10144. });
  10145. }
  10146. });
  10147. return gdata;
  10148. },
  10149. groupingToggle : function(hid){
  10150. this.each(function(){
  10151. var $t = this,
  10152. grp = $t.p.groupingView,
  10153. strpos = hid.lastIndexOf('_'),
  10154. uid = hid.substring(0,strpos+1),
  10155. num = parseInt(hid.substring(strpos+1),10)+1,
  10156. minus = grp.minusicon,
  10157. plus = grp.plusicon,
  10158. tar = $("#"+hid),
  10159. r = tar.length ? tar[0].nextSibling : null,
  10160. tarspan = $("#"+hid+" span."+"tree-wrap-"+$t.p.direction),
  10161. collapsed = false;
  10162. if( tarspan.hasClass(minus) ) {
  10163. if(grp.showSummaryOnHide && grp.groupSummary[0]) {
  10164. if(r){
  10165. while(r) {
  10166. if($(r).hasClass('jqfoot') ) { break; }
  10167. $(r).hide();
  10168. r = r.nextSibling;
  10169. }
  10170. }
  10171. } else {
  10172. if(r){
  10173. while(r) {
  10174. if($(r).attr('id') ==uid+String(num) ) { break; }
  10175. $(r).hide();
  10176. r = r.nextSibling;
  10177. }
  10178. }
  10179. }
  10180. tarspan.removeClass(minus).addClass(plus);
  10181. collapsed = true;
  10182. } else {
  10183. if(r){
  10184. while(r) {
  10185. if($(r).attr('id') ==uid+String(num) ) { break; }
  10186. $(r).show();
  10187. r = r.nextSibling;
  10188. }
  10189. }
  10190. tarspan.removeClass(plus).addClass(minus);
  10191. }
  10192. if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
  10193. });
  10194. return false;
  10195. },
  10196. groupingRender : function (grdata, colspans ) {
  10197. return this.each(function(){
  10198. var $t = this,
  10199. grp = $t.p.groupingView,
  10200. str = "", icon = "", hid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp, ii;
  10201. //only one level for now
  10202. if(!grp.groupDataSorted) {
  10203. // ???? TO BE IMPROVED
  10204. grp.sortitems[0].sort();
  10205. grp.sortnames[0].sort();
  10206. if(grp.groupOrder[0].toLowerCase() == 'desc')
  10207. {
  10208. grp.sortitems[0].reverse();
  10209. grp.sortnames[0].reverse();
  10210. }
  10211. }
  10212. pmrtl += " tree-wrap-"+$t.p.direction;
  10213. ii = 0;
  10214. while(ii < colspans) {
  10215. if($t.p.colModel[ii].name == grp.groupField[0]) {
  10216. cp = ii;
  10217. break;
  10218. }
  10219. ii++;
  10220. }
  10221. $.each(grp.sortitems[0],function(i,n){
  10222. hid = $t.p.id+"ghead_"+i;
  10223. icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$t.p.id+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
  10224. try {
  10225. gv = $t.formatter(hid, grp.sortnames[0][i], cp, grp.sortitems[0] );
  10226. } catch (egv) {
  10227. gv = grp.sortnames[0][i];
  10228. }
  10229. str += "<tr id=\""+hid+"\" role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+"\"><td colspan=\""+colspans+"\">"+icon+$.jgrid.format(grp.groupText[0], gv, grdata[n].length)+"</td></tr>";
  10230. for(var kk=0;kk<grdata[n].length;kk++) {
  10231. str += grdata[n][kk].join('');
  10232. }
  10233. if(grp.groupSummary[0]) {
  10234. var hhdr = "";
  10235. if(grp.groupCollapse && !grp.showSummaryOnHide) {
  10236. hhdr = " style=\"display:none;\"";
  10237. }
  10238. str += "<tr"+hhdr+" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">";
  10239. var fdata = grp.summaryval[0][n],
  10240. cm = $t.p.colModel,
  10241. vv, grlen = grdata[n].length;
  10242. for(var k=0; k<colspans;k++) {
  10243. var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
  10244. tplfld = "{0}";
  10245. $.each(fdata,function(){
  10246. if(this.nm == cm[k].name) {
  10247. if(cm[k].summaryTpl) {
  10248. tplfld = cm[k].summaryTpl;
  10249. }
  10250. if(this.st == 'avg') {
  10251. if(this.v && grlen > 0) {
  10252. this.v = (this.v/grlen);
  10253. }
  10254. }
  10255. try {
  10256. vv = $t.formatter('', this.v, k, this);
  10257. } catch (ef) {
  10258. vv = this.v;
  10259. }
  10260. tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>";
  10261. return false;
  10262. }
  10263. });
  10264. str += tmpdata;
  10265. }
  10266. str += "</tr>";
  10267. }
  10268. });
  10269. $("#"+$t.p.id+" tbody:first").append(str);
  10270. // free up memory
  10271. str = null;
  10272. });
  10273. },
  10274. groupingGroupBy : function (name, options ) {
  10275. return this.each(function(){
  10276. var $t = this;
  10277. if(typeof(name) == "string") {
  10278. name = [name];
  10279. }
  10280. var grp = $t.p.groupingView;
  10281. $t.p.grouping = true;
  10282. //Set default, in case visibilityOnNextGrouping is undefined
  10283. if (typeof grp.visibiltyOnNextGrouping == "undefined") {
  10284. grp.visibiltyOnNextGrouping = [];
  10285. }
  10286. var i;
  10287. // show previous hidden groups if they are hidden and weren't removed yet
  10288. for(i=0;i<grp.groupField.length;i++) {
  10289. if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  10290. $($t).jqGrid('showCol',grp.groupField[i]);
  10291. }
  10292. }
  10293. // set visibility status of current group columns on next grouping
  10294. for(i=0;i<name.length;i++) {
  10295. grp.visibiltyOnNextGrouping[i] = $("#"+$t.p.id+"_"+name[i]).is(":visible");
  10296. }
  10297. $t.p.groupingView = $.extend($t.p.groupingView, options || {});
  10298. grp.groupField = name;
  10299. $($t).trigger("reloadGrid");
  10300. });
  10301. },
  10302. groupingRemove : function (current) {
  10303. return this.each(function(){
  10304. var $t = this;
  10305. if(typeof(current) == 'undefined') {
  10306. current = true;
  10307. }
  10308. $t.p.grouping = false;
  10309. if(current===true) {
  10310. var grp = $t.p.groupingView;
  10311. // show previous hidden groups if they are hidden and weren't removed yet
  10312. for(var i=0;i<grp.groupField.length;i++) {
  10313. if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  10314. $($t).jqGrid('showCol', grp.groupField);
  10315. }
  10316. }
  10317. $("tr.jqgroup, tr.jqfoot","#"+$t.p.id+" tbody:first").remove();
  10318. $("tr.jqgrow:hidden","#"+$t.p.id+" tbody:first").show();
  10319. } else {
  10320. $($t).trigger("reloadGrid");
  10321. }
  10322. });
  10323. },
  10324. groupingCalculations : {
  10325. "sum" : function(v, field, rc) {
  10326. return parseFloat(v||0) + parseFloat((rc[field]||0));
  10327. },
  10328. "min" : function(v, field, rc) {
  10329. if(v==="") {
  10330. return parseFloat(rc[field]||0);
  10331. }
  10332. return Math.min(parseFloat(v),parseFloat(rc[field]||0));
  10333. },
  10334. "max" : function(v, field, rc) {
  10335. if(v==="") {
  10336. return parseFloat(rc[field]||0);
  10337. }
  10338. return Math.max(parseFloat(v),parseFloat(rc[field]||0));
  10339. },
  10340. "count" : function(v, field, rc) {
  10341. if(v==="") {v=0;}
  10342. if(rc.hasOwnProperty(field)) {
  10343. return v+1;
  10344. } else {
  10345. return 0;
  10346. }
  10347. },
  10348. "avg" : function(v, field, rc) {
  10349. // the same as sum, but at end we divide it
  10350. return parseFloat(v||0) + parseFloat((rc[field]||0));
  10351. }
  10352. }
  10353. });
  10354. })(jQuery);
  10355. ;(function($){
  10356. /*
  10357. * jqGrid extension for constructing Grid Data from external file
  10358. * Tony Tomov tony@trirand.com
  10359. * http://trirand.com/blog/
  10360. * Dual licensed under the MIT and GPL licenses:
  10361. * http://www.opensource.org/licenses/mit-license.php
  10362. * http://www.gnu.org/licenses/gpl-2.0.html
  10363. **/
  10364. $.jgrid.extend({
  10365. jqGridImport : function(o) {
  10366. o = $.extend({
  10367. imptype : "xml", // xml, json, xmlstring, jsonstring
  10368. impstring: "",
  10369. impurl: "",
  10370. mtype: "GET",
  10371. impData : {},
  10372. xmlGrid :{
  10373. config : "roots>grid",
  10374. data: "roots>rows"
  10375. },
  10376. jsonGrid :{
  10377. config : "grid",
  10378. data: "data"
  10379. },
  10380. ajaxOptions :{}
  10381. }, o || {});
  10382. return this.each(function(){
  10383. var $t = this;
  10384. var XmlConvert = function (xml,o) {
  10385. var cnfg = $(o.xmlGrid.config,xml)[0];
  10386. var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1;
  10387. if(xmlJsonClass.xml2json && $.jgrid.parse) {
  10388. jstr = xmlJsonClass.xml2json(cnfg," ");
  10389. jstr = $.jgrid.parse(jstr);
  10390. for(var key in jstr) {
  10391. if(jstr.hasOwnProperty(key)) {
  10392. jstr1=jstr[key];
  10393. }
  10394. }
  10395. if(xmldata) {
  10396. // save the datatype
  10397. var svdatatype = jstr.grid.datatype;
  10398. jstr.grid.datatype = 'xmlstring';
  10399. jstr.grid.datastr = xml;
  10400. $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
  10401. } else {
  10402. $($t).jqGrid( jstr1 );
  10403. }
  10404. jstr = null;jstr1=null;
  10405. } else {
  10406. alert("xml2json or parse are not present");
  10407. }
  10408. };
  10409. var JsonConvert = function (jsonstr,o){
  10410. if (jsonstr && typeof jsonstr == 'string') {
  10411. var json = $.jgrid.parse(jsonstr);
  10412. var gprm = json[o.jsonGrid.config];
  10413. var jdata = json[o.jsonGrid.data];
  10414. if(jdata) {
  10415. var svdatatype = gprm.datatype;
  10416. gprm.datatype = 'jsonstring';
  10417. gprm.datastr = jdata;
  10418. $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
  10419. } else {
  10420. $($t).jqGrid( gprm );
  10421. }
  10422. }
  10423. };
  10424. switch (o.imptype){
  10425. case 'xml':
  10426. $.ajax($.extend({
  10427. url:o.impurl,
  10428. type:o.mtype,
  10429. data: o.impData,
  10430. dataType:"xml",
  10431. complete: function(xml,stat) {
  10432. if(stat == 'success') {
  10433. XmlConvert(xml.responseXML,o);
  10434. if($.isFunction(o.importComplete)) {
  10435. o.importComplete(xml);
  10436. }
  10437. }
  10438. xml=null;
  10439. }
  10440. }, o.ajaxOptions));
  10441. break;
  10442. case 'xmlstring' :
  10443. // we need to make just the conversion and use the same code as xml
  10444. if(o.impstring && typeof o.impstring == 'string') {
  10445. var xmld = $.jgrid.stringToDoc(o.impstring);
  10446. if(xmld) {
  10447. XmlConvert(xmld,o);
  10448. if($.isFunction(o.importComplete)) {
  10449. o.importComplete(xmld);
  10450. }
  10451. o.impstring = null;
  10452. }
  10453. xmld = null;
  10454. }
  10455. break;
  10456. case 'json':
  10457. $.ajax($.extend({
  10458. url:o.impurl,
  10459. type:o.mtype,
  10460. data: o.impData,
  10461. dataType:"json",
  10462. complete: function(json,stat) {
  10463. if(stat == 'success') {
  10464. JsonConvert(json.responseText,o );
  10465. if($.isFunction(o.importComplete)) {
  10466. o.importComplete(json);
  10467. }
  10468. }
  10469. json=null;
  10470. }
  10471. }, o.ajaxOptions ));
  10472. break;
  10473. case 'jsonstring' :
  10474. if(o.impstring && typeof o.impstring == 'string') {
  10475. JsonConvert(o.impstring,o );
  10476. if($.isFunction(o.importComplete)) {
  10477. o.importComplete(o.impstring);
  10478. }
  10479. o.impstring = null;
  10480. }
  10481. break;
  10482. }
  10483. });
  10484. },
  10485. jqGridExport : function(o) {
  10486. o = $.extend({
  10487. exptype : "xmlstring",
  10488. root: "grid",
  10489. ident: "\t"
  10490. }, o || {});
  10491. var ret = null;
  10492. this.each(function () {
  10493. if(!this.grid) { return;}
  10494. var gprm = $.extend({},$(this).jqGrid("getGridParam"));
  10495. // we need to check for:
  10496. // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
  10497. if(gprm.rownumbers) {
  10498. gprm.colNames.splice(0,1);
  10499. gprm.colModel.splice(0,1);
  10500. }
  10501. if(gprm.multiselect) {
  10502. gprm.colNames.splice(0,1);
  10503. gprm.colModel.splice(0,1);
  10504. }
  10505. if(gprm.subGrid) {
  10506. gprm.colNames.splice(0,1);
  10507. gprm.colModel.splice(0,1);
  10508. }
  10509. gprm.knv = null;
  10510. if(gprm.treeGrid) {
  10511. for (var key in gprm.treeReader) {
  10512. if(gprm.treeReader.hasOwnProperty(key)) {
  10513. gprm.colNames.splice(gprm.colNames.length-1);
  10514. gprm.colModel.splice(gprm.colModel.length-1);
  10515. }
  10516. }
  10517. }
  10518. switch (o.exptype) {
  10519. case 'xmlstring' :
  10520. ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
  10521. break;
  10522. case 'jsonstring' :
  10523. ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}";
  10524. if(gprm.postData.filters !== undefined) {
  10525. ret=ret.replace(/filters":"/,'filters":');
  10526. ret=ret.replace(/}]}"/,'}]}');
  10527. }
  10528. break;
  10529. }
  10530. });
  10531. return ret;
  10532. },
  10533. excelExport : function(o) {
  10534. o = $.extend({
  10535. exptype : "remote",
  10536. url : null,
  10537. oper: "oper",
  10538. tag: "excel",
  10539. exportOptions : {}
  10540. }, o || {});
  10541. return this.each(function(){
  10542. if(!this.grid) { return;}
  10543. var url;
  10544. if(o.exptype == "remote") {
  10545. var pdata = $.extend({},this.p.postData);
  10546. pdata[o.oper] = o.tag;
  10547. var params = jQuery.param(pdata);
  10548. if(o.url.indexOf("?") != -1) { url = o.url+"&"+params; }
  10549. else { url = o.url+"?"+params; }
  10550. window.location = url;
  10551. }
  10552. });
  10553. }
  10554. });
  10555. })(jQuery);;(function($){
  10556. /*
  10557. **
  10558. * jqGrid addons using jQuery UI
  10559. * Author: Mark Williams
  10560. * Dual licensed under the MIT and GPL licenses:
  10561. * http://www.opensource.org/licenses/mit-license.php
  10562. * http://www.gnu.org/licenses/gpl-2.0.html
  10563. * depends on jQuery UI
  10564. **/
  10565. if ($.browser.msie && $.browser.version==8) {
  10566. $.expr[":"].hidden = function(elem) {
  10567. return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
  10568. elem.style.display == "none";
  10569. };
  10570. }
  10571. // requiere load multiselect before grid
  10572. $.jgrid._multiselect = false;
  10573. if($.ui) {
  10574. if ($.ui.multiselect ) {
  10575. if($.ui.multiselect.prototype._setSelected) {
  10576. var setSelected = $.ui.multiselect.prototype._setSelected;
  10577. $.ui.multiselect.prototype._setSelected = function(item,selected) {
  10578. var ret = setSelected.call(this,item,selected);
  10579. if (selected && this.selectedList) {
  10580. var elt = this.element;
  10581. this.selectedList.find('li').each(function() {
  10582. if ($(this).data('optionLink')) {
  10583. $(this).data('optionLink').remove().appendTo(elt);
  10584. }
  10585. });
  10586. }
  10587. return ret;
  10588. };
  10589. }
  10590. if($.ui.multiselect.prototype.destroy) {
  10591. $.ui.multiselect.prototype.destroy = function() {
  10592. this.element.show();
  10593. this.container.remove();
  10594. if ($.Widget === undefined) {
  10595. $.widget.prototype.destroy.apply(this, arguments);
  10596. } else {
  10597. $.Widget.prototype.destroy.apply(this, arguments);
  10598. }
  10599. };
  10600. }
  10601. $.jgrid._multiselect = true;
  10602. }
  10603. }
  10604. $.jgrid.extend({
  10605. sortableColumns : function (tblrow)
  10606. {
  10607. return this.each(function (){
  10608. var ts = this, tid= ts.p.id;
  10609. function start() {ts.p.disableClick = true;}
  10610. var sortable_opts = {
  10611. "tolerance" : "pointer",
  10612. "axis" : "x",
  10613. "scrollSensitivity": "1",
  10614. "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)',
  10615. "placeholder": {
  10616. element: function(item) {
  10617. var el = $(document.createElement(item[0].nodeName))
  10618. .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight")
  10619. .removeClass("ui-sortable-helper")[0];
  10620. return el;
  10621. },
  10622. update: function(self, p) {
  10623. p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10));
  10624. p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10));
  10625. }
  10626. },
  10627. "update": function(event, ui) {
  10628. var p = $(ui.item).parent(),
  10629. th = $(">th", p),
  10630. colModel = ts.p.colModel,
  10631. cmMap = {}, tid= ts.p.id+"_";
  10632. $.each(colModel, function(i) { cmMap[this.name]=i; });
  10633. var permutation = [];
  10634. th.each(function(i) {
  10635. var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,"");
  10636. if (id in cmMap) {
  10637. permutation.push(cmMap[id]);
  10638. }
  10639. });
  10640. $(ts).jqGrid("remapColumns",permutation, true, true);
  10641. if ($.isFunction(ts.p.sortable.update)) {
  10642. ts.p.sortable.update(permutation);
  10643. }
  10644. setTimeout(function(){ts.p.disableClick=false;}, 50);
  10645. }
  10646. };
  10647. if (ts.p.sortable.options) {
  10648. $.extend(sortable_opts, ts.p.sortable.options);
  10649. } else if ($.isFunction(ts.p.sortable)) {
  10650. ts.p.sortable = { "update" : ts.p.sortable };
  10651. }
  10652. if (sortable_opts.start) {
  10653. var s = sortable_opts.start;
  10654. sortable_opts.start = function(e,ui) {
  10655. start();
  10656. s.call(this,e,ui);
  10657. };
  10658. } else {
  10659. sortable_opts.start = start;
  10660. }
  10661. if (ts.p.sortable.exclude) {
  10662. sortable_opts.items += ":not("+ts.p.sortable.exclude+")";
  10663. }
  10664. tblrow.sortable(sortable_opts).data("sortable").floating = true;
  10665. });
  10666. },
  10667. columnChooser : function(opts) {
  10668. var self = this;
  10669. if($("#colchooser_"+self[0].p.id).length ) { return; }
  10670. var selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
  10671. var select = $('select', selector);
  10672. function insert(perm,i,v) {
  10673. if(i>=0){
  10674. var a = perm.slice();
  10675. var b = a.splice(i,Math.max(perm.length-i,i));
  10676. if(i>perm.length) { i = perm.length; }
  10677. a[i] = v;
  10678. return a.concat(b);
  10679. }
  10680. }
  10681. opts = $.extend({
  10682. "width" : 420,
  10683. "height" : 240,
  10684. "classname" : null,
  10685. "done" : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
  10686. /* msel is either the name of a ui widget class that
  10687. extends a multiselect, or a function that supports
  10688. creating a multiselect object (with no argument,
  10689. or when passed an object), and destroying it (when
  10690. passed the string "destroy"). */
  10691. "msel" : "multiselect",
  10692. /* "msel_opts" : {}, */
  10693. /* dlog is either the name of a ui widget class that
  10694. behaves in a dialog-like way, or a function, that
  10695. supports creating a dialog (when passed dlog_opts)
  10696. or destroying a dialog (when passed the string
  10697. "destroy")
  10698. */
  10699. "dlog" : "dialog",
  10700. /* dlog_opts is either an option object to be passed
  10701. to "dlog", or (more likely) a function that creates
  10702. the options object.
  10703. The default produces a suitable options object for
  10704. ui.dialog */
  10705. "dlog_opts" : function(opts) {
  10706. var buttons = {};
  10707. buttons[opts.bSubmit] = function() {
  10708. opts.apply_perm();
  10709. opts.cleanup(false);
  10710. };
  10711. buttons[opts.bCancel] = function() {
  10712. opts.cleanup(true);
  10713. };
  10714. return {
  10715. "buttons": buttons,
  10716. "close": function() {
  10717. opts.cleanup(true);
  10718. },
  10719. "modal" : opts.modal ? opts.modal : false,
  10720. "resizable": opts.resizable ? opts.resizable : true,
  10721. "width": opts.width+20
  10722. };
  10723. },
  10724. /* Function to get the permutation array, and pass it to the
  10725. "done" function */
  10726. "apply_perm" : function() {
  10727. $('option',select).each(function(i) {
  10728. if (this.selected) {
  10729. self.jqGrid("showCol", colModel[this.value].name);
  10730. } else {
  10731. self.jqGrid("hideCol", colModel[this.value].name);
  10732. }
  10733. });
  10734. var perm = [];
  10735. //fixedCols.slice(0);
  10736. $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); });
  10737. $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
  10738. $.each(colMap, function() {
  10739. var ti = parseInt(this,10);
  10740. perm = insert(perm,ti,ti);
  10741. });
  10742. if (opts.done) {
  10743. opts.done.call(self, perm);
  10744. }
  10745. },
  10746. /* Function to cleanup the dialog, and select. Also calls the
  10747. done function with no permutation (to indicate that the
  10748. columnChooser was aborted */
  10749. "cleanup" : function(calldone) {
  10750. call(opts.dlog, selector, 'destroy');
  10751. call(opts.msel, select, 'destroy');
  10752. selector.remove();
  10753. if (calldone && opts.done) {
  10754. opts.done.call(self);
  10755. }
  10756. },
  10757. "msel_opts" : {}
  10758. }, $.jgrid.col, opts || {});
  10759. if($.ui) {
  10760. if ($.ui.multiselect ) {
  10761. if(opts.msel == "multiselect") {
  10762. if(!$.jgrid._multiselect) {
  10763. // should be in language file
  10764. alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
  10765. return;
  10766. }
  10767. opts.msel_opts = $.extend($.ui.multiselect.defaults,opts.msel_opts);
  10768. }
  10769. }
  10770. }
  10771. if (opts.caption) {
  10772. selector.attr("title", opts.caption);
  10773. }
  10774. if (opts.classname) {
  10775. selector.addClass(opts.classname);
  10776. select.addClass(opts.classname);
  10777. }
  10778. if (opts.width) {
  10779. $(">div",selector).css({"width": opts.width,"margin":"0 auto"});
  10780. select.css("width", opts.width);
  10781. }
  10782. if (opts.height) {
  10783. $(">div",selector).css("height", opts.height);
  10784. select.css("height", opts.height - 10);
  10785. }
  10786. var colModel = self.jqGrid("getGridParam", "colModel");
  10787. var colNames = self.jqGrid("getGridParam", "colNames");
  10788. var colMap = {}, fixedCols = [];
  10789. select.empty();
  10790. $.each(colModel, function(i) {
  10791. colMap[this.name] = i;
  10792. if (this.hidedlg) {
  10793. if (!this.hidden) {
  10794. fixedCols.push(i);
  10795. }
  10796. return;
  10797. }
  10798. select.append("<option value='"+i+"' "+
  10799. (this.hidden?"":"selected='selected'")+">"+colNames[i]+"</option>");
  10800. });
  10801. function call(fn, obj) {
  10802. if (!fn) { return; }
  10803. if (typeof fn == 'string') {
  10804. if ($.fn[fn]) {
  10805. $.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
  10806. }
  10807. } else if ($.isFunction(fn)) {
  10808. fn.apply(obj, $.makeArray(arguments).slice(2));
  10809. }
  10810. }
  10811. var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
  10812. call(opts.dlog, selector, dopts);
  10813. var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
  10814. call(opts.msel, select, mopts);
  10815. },
  10816. sortableRows : function (opts) {
  10817. // Can accept all sortable options and events
  10818. return this.each(function(){
  10819. var $t = this;
  10820. if(!$t.grid) { return; }
  10821. // Currently we disable a treeGrid sortable
  10822. if($t.p.treeGrid) { return; }
  10823. if($.fn.sortable) {
  10824. opts = $.extend({
  10825. "cursor":"move",
  10826. "axis" : "y",
  10827. "items": ".jqgrow"
  10828. },
  10829. opts || {});
  10830. if(opts.start && $.isFunction(opts.start)) {
  10831. opts._start_ = opts.start;
  10832. delete opts.start;
  10833. } else {opts._start_=false;}
  10834. if(opts.update && $.isFunction(opts.update)) {
  10835. opts._update_ = opts.update;
  10836. delete opts.update;
  10837. } else {opts._update_ = false;}
  10838. opts.start = function(ev,ui) {
  10839. $(ui.item).css("border-width","0px");
  10840. $("td",ui.item).each(function(i){
  10841. this.style.width = $t.grid.cols[i].style.width;
  10842. });
  10843. if($t.p.subGrid) {
  10844. var subgid = $(ui.item).attr("id");
  10845. try {
  10846. $($t).jqGrid('collapseSubGridRow',subgid);
  10847. } catch (e) {}
  10848. }
  10849. if(opts._start_) {
  10850. opts._start_.apply(this,[ev,ui]);
  10851. }
  10852. };
  10853. opts.update = function (ev,ui) {
  10854. $(ui.item).css("border-width","");
  10855. if($t.p.rownumbers === true) {
  10856. $("td.jqgrid-rownum",$t.rows).each(function( i ){
  10857. $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
  10858. });
  10859. }
  10860. if(opts._update_) {
  10861. opts._update_.apply(this,[ev,ui]);
  10862. }
  10863. };
  10864. $("tbody:first",$t).sortable(opts);
  10865. $("tbody:first",$t).disableSelection();
  10866. }
  10867. });
  10868. },
  10869. gridDnD : function(opts) {
  10870. return this.each(function(){
  10871. var $t = this;
  10872. if(!$t.grid) { return; }
  10873. // Currently we disable a treeGrid drag and drop
  10874. if($t.p.treeGrid) { return; }
  10875. if(!$.fn.draggable || !$.fn.droppable) { return; }
  10876. function updateDnD ()
  10877. {
  10878. var datadnd = $.data($t,"dnd");
  10879. $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
  10880. }
  10881. var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
  10882. if($("#jqgrid_dnd").html() === null) {
  10883. $('body').append(appender);
  10884. }
  10885. if(typeof opts == 'string' && opts == 'updateDnD' && $t.p.jqgdnd===true) {
  10886. updateDnD();
  10887. return;
  10888. }
  10889. opts = $.extend({
  10890. "drag" : function (opts) {
  10891. return $.extend({
  10892. start : function (ev, ui) {
  10893. // if we are in subgrid mode try to collapse the node
  10894. if($t.p.subGrid) {
  10895. var subgid = $(ui.helper).attr("id");
  10896. try {
  10897. $($t).jqGrid('collapseSubGridRow',subgid);
  10898. } catch (e) {}
  10899. }
  10900. // hack
  10901. // drag and drop does not insert tr in table, when the table has no rows
  10902. // we try to insert new empty row on the target(s)
  10903. for (var i=0;i<$.data($t,"dnd").connectWith.length;i++){
  10904. if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') == "0" ){
  10905. $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{});
  10906. }
  10907. }
  10908. ui.helper.addClass("ui-state-highlight");
  10909. $("td",ui.helper).each(function(i) {
  10910. this.style.width = $t.grid.headers[i].width+"px";
  10911. });
  10912. if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); }
  10913. },
  10914. stop :function(ev,ui) {
  10915. if(ui.helper.dropped && !opts.dragcopy) {
  10916. var ids = $(ui.helper).attr("id");
  10917. $($t).jqGrid('delRowData',ids );
  10918. }
  10919. // if we have a empty row inserted from start event try to delete it
  10920. for (var i=0;i<$.data($t,"dnd").connectWith.length;i++){
  10921. $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row');
  10922. }
  10923. if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); }
  10924. }
  10925. },opts.drag_opts || {});
  10926. },
  10927. "drop" : function (opts) {
  10928. return $.extend({
  10929. accept: function(d) {
  10930. if (!$(d).hasClass('jqgrow')) { return d;}
  10931. var tid = $(d).closest("table.ui-jqgrid-btable");
  10932. if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) {
  10933. var cn = $.data(tid[0],"dnd").connectWith;
  10934. return $.inArray('#'+this.id,cn) != -1 ? true : false;
  10935. }
  10936. return d;
  10937. },
  10938. drop: function(ev, ui) {
  10939. if (!$(ui.draggable).hasClass('jqgrow')) { return; }
  10940. var accept = $(ui.draggable).attr("id");
  10941. var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept);
  10942. if(!opts.dropbyname) {
  10943. var j =0, tmpdata = {}, dropname;
  10944. var dropmodel = $("#"+this.id).jqGrid('getGridParam','colModel');
  10945. try {
  10946. for (var key in getdata) {
  10947. if(getdata.hasOwnProperty(key) && dropmodel[j]) {
  10948. dropname = dropmodel[j].name;
  10949. tmpdata[dropname] = getdata[key];
  10950. }
  10951. j++;
  10952. }
  10953. getdata = tmpdata;
  10954. } catch (e) {}
  10955. }
  10956. ui.helper.dropped = true;
  10957. if(opts.beforedrop && $.isFunction(opts.beforedrop) ) {
  10958. //parameters to this callback - event, element, data to be inserted, sender, reciever
  10959. // should return object which will be inserted into the reciever
  10960. var datatoinsert = opts.beforedrop.call(this,ev,ui,getdata,$('#'+$t.id),$(this));
  10961. if (typeof datatoinsert != "undefined" && datatoinsert !== null && typeof datatoinsert == "object") { getdata = datatoinsert; }
  10962. }
  10963. if(ui.helper.dropped) {
  10964. var grid;
  10965. if(opts.autoid) {
  10966. if($.isFunction(opts.autoid)) {
  10967. grid = opts.autoid.call(this,getdata);
  10968. } else {
  10969. grid = Math.ceil(Math.random()*1000);
  10970. grid = opts.autoidprefix+grid;
  10971. }
  10972. }
  10973. // NULL is interpreted as undefined while null as object
  10974. $("#"+this.id).jqGrid('addRowData',grid,getdata,opts.droppos);
  10975. }
  10976. if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); }
  10977. }}, opts.drop_opts || {});
  10978. },
  10979. "onstart" : null,
  10980. "onstop" : null,
  10981. "beforedrop": null,
  10982. "ondrop" : null,
  10983. "drop_opts" : {
  10984. "activeClass": "ui-state-active",
  10985. "hoverClass": "ui-state-hover"
  10986. },
  10987. "drag_opts" : {
  10988. "revert": "invalid",
  10989. "helper": "clone",
  10990. "cursor": "move",
  10991. "appendTo" : "#jqgrid_dnd",
  10992. "zIndex": 5000
  10993. },
  10994. "dragcopy": false,
  10995. "dropbyname" : false,
  10996. "droppos" : "first",
  10997. "autoid" : true,
  10998. "autoidprefix" : "dnd_"
  10999. }, opts || {});
  11000. if(!opts.connectWith) { return; }
  11001. opts.connectWith = opts.connectWith.split(",");
  11002. opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);});
  11003. $.data($t,"dnd",opts);
  11004. if($t.p.reccount != "0" && !$t.p.jqgdnd) {
  11005. updateDnD();
  11006. }
  11007. $t.p.jqgdnd = true;
  11008. for (var i=0;i<opts.connectWith.length;i++){
  11009. var cn =opts.connectWith[i];
  11010. $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop);
  11011. }
  11012. });
  11013. },
  11014. gridResize : function(opts) {
  11015. return this.each(function(){
  11016. var $t = this;
  11017. if(!$t.grid || !$.fn.resizable) { return; }
  11018. opts = $.extend({}, opts || {});
  11019. if(opts.alsoResize ) {
  11020. opts._alsoResize_ = opts.alsoResize;
  11021. delete opts.alsoResize;
  11022. } else {
  11023. opts._alsoResize_ = false;
  11024. }
  11025. if(opts.stop && $.isFunction(opts.stop)) {
  11026. opts._stop_ = opts.stop;
  11027. delete opts.stop;
  11028. } else {
  11029. opts._stop_ = false;
  11030. }
  11031. opts.stop = function (ev, ui) {
  11032. $($t).jqGrid('setGridParam',{height:$("#gview_"+$t.p.id+" .ui-jqgrid-bdiv").height()});
  11033. $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit);
  11034. if(opts._stop_) { opts._stop_.call($t,ev,ui); }
  11035. };
  11036. if(opts._alsoResize_) {
  11037. var optstest = "{\'#gview_"+$t.p.id+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}";
  11038. opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this
  11039. } else {
  11040. opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+$t.p.id);
  11041. }
  11042. delete opts._alsoResize_;
  11043. $("#gbox_"+$t.p.id).resizable(opts);
  11044. });
  11045. }
  11046. });
  11047. })(jQuery);
  11048. /*
  11049. Transform a table to a jqGrid.
  11050. Peter Romianowski <peter.romianowski@optivo.de>
  11051. If the first column of the table contains checkboxes or
  11052. radiobuttons then the jqGrid is made selectable.
  11053. */
  11054. // Addition - selector can be a class or id
  11055. function tableToGrid(selector, options) {
  11056. jQuery(selector).each(function() {
  11057. if(this.grid) {return;} //Adedd from Tony Tomov
  11058. // This is a small "hack" to make the width of the jqGrid 100%
  11059. jQuery(this).width("99%");
  11060. var w = jQuery(this).width();
  11061. // Text whether we have single or multi select
  11062. var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this));
  11063. var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this));
  11064. var selectMultiple = inputCheckbox.length > 0;
  11065. var selectSingle = !selectMultiple && inputRadio.length > 0;
  11066. var selectable = selectMultiple || selectSingle;
  11067. //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
  11068. // Build up the columnModel and the data
  11069. var colModel = [];
  11070. var colNames = [];
  11071. jQuery('th', jQuery(this)).each(function() {
  11072. if (colModel.length === 0 && selectable) {
  11073. colModel.push({
  11074. name: '__selection__',
  11075. index: '__selection__',
  11076. width: 0,
  11077. hidden: true
  11078. });
  11079. colNames.push('__selection__');
  11080. } else {
  11081. colModel.push({
  11082. name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  11083. index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  11084. width: jQuery(this).width() || 150
  11085. });
  11086. colNames.push(jQuery(this).html());
  11087. }
  11088. });
  11089. var data = [];
  11090. var rowIds = [];
  11091. var rowChecked = [];
  11092. jQuery('tbody > tr', jQuery(this)).each(function() {
  11093. var row = {};
  11094. var rowPos = 0;
  11095. jQuery('td', jQuery(this)).each(function() {
  11096. if (rowPos === 0 && selectable) {
  11097. var input = jQuery('input', jQuery(this));
  11098. var rowId = input.attr("value");
  11099. rowIds.push(rowId || data.length);
  11100. if (input.is(":checked")) {
  11101. rowChecked.push(rowId);
  11102. }
  11103. row[colModel[rowPos].name] = input.attr("value");
  11104. } else {
  11105. row[colModel[rowPos].name] = jQuery(this).html();
  11106. }
  11107. rowPos++;
  11108. });
  11109. if(rowPos >0) { data.push(row); }
  11110. });
  11111. // Clear the original HTML table
  11112. jQuery(this).empty();
  11113. // Mark it as jqGrid
  11114. jQuery(this).addClass("scroll");
  11115. jQuery(this).jqGrid(jQuery.extend({
  11116. datatype: "local",
  11117. width: w,
  11118. colNames: colNames,
  11119. colModel: colModel,
  11120. multiselect: selectMultiple
  11121. //inputName: inputName,
  11122. //inputValueCol: imputName != null ? "__selection__" : null
  11123. }, options || {}));
  11124. // Add data
  11125. var a;
  11126. for (a = 0; a < data.length; a++) {
  11127. var id = null;
  11128. if (rowIds.length > 0) {
  11129. id = rowIds[a];
  11130. if (id && id.replace) {
  11131. // We have to do this since the value of a checkbox
  11132. // or radio button can be anything
  11133. id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
  11134. }
  11135. }
  11136. if (id === null) {
  11137. id = a + 1;
  11138. }
  11139. jQuery(this).jqGrid("addRowData",id, data[a]);
  11140. }
  11141. // Set the selection
  11142. for (a = 0; a < rowChecked.length; a++) {
  11143. jQuery(this).jqGrid("setSelection",rowChecked[a]);
  11144. }
  11145. });
  11146. };