rails_jq_grid 0.0.3.pre2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/VERSION +1 -1
  2. data/public/javascripts/rails-jqgrid/Changes.txt +0 -0
  3. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg.js +132 -1
  4. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg1251.js +132 -1
  5. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cat.js +128 -1
  6. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cn.js +132 -1
  7. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cs.js +128 -1
  8. data/public/javascripts/rails-jqgrid/i18n/grid.locale-da.js +128 -0
  9. data/public/javascripts/rails-jqgrid/i18n/grid.locale-de.js +133 -1
  10. data/public/javascripts/rails-jqgrid/i18n/grid.locale-el.js +126 -1
  11. data/public/javascripts/rails-jqgrid/i18n/grid.locale-en.js +128 -1
  12. data/public/javascripts/rails-jqgrid/i18n/grid.locale-es.js +128 -1
  13. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fa.js +145 -1
  14. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fi.js +130 -1
  15. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fr.js +126 -1
  16. data/public/javascripts/rails-jqgrid/i18n/grid.locale-gl.js +126 -0
  17. data/public/javascripts/rails-jqgrid/i18n/grid.locale-he.js +127 -1
  18. data/public/javascripts/rails-jqgrid/i18n/grid.locale-hu.js +129 -1
  19. data/public/javascripts/rails-jqgrid/i18n/grid.locale-is.js +126 -1
  20. data/public/javascripts/rails-jqgrid/i18n/grid.locale-it.js +1 -1
  21. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ja.js +155 -1
  22. data/public/javascripts/rails-jqgrid/i18n/grid.locale-nl.js +149 -1
  23. data/public/javascripts/rails-jqgrid/i18n/grid.locale-no.js +1 -1
  24. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pl.js +127 -1
  25. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt-br.js +127 -1
  26. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt.js +125 -1
  27. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ro.js +139 -1
  28. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ru.js +127 -1
  29. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sk.js +127 -1
  30. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sr.js +128 -0
  31. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sv.js +127 -1
  32. data/public/javascripts/rails-jqgrid/i18n/grid.locale-tr.js +126 -1
  33. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ua.js +127 -1
  34. data/public/javascripts/rails-jqgrid/install.txt +0 -0
  35. data/public/javascripts/rails-jqgrid/jquery.jqGrid.min.js +445 -432
  36. data/public/javascripts/rails-jqgrid/src/JsonXml.js +329 -329
  37. data/public/javascripts/rails-jqgrid/src/css/ellipsis-xbl.xml +0 -0
  38. data/public/javascripts/rails-jqgrid/src/css/ui.jqgrid.css +139 -129
  39. data/public/javascripts/rails-jqgrid/src/css/ui.multiselect.css +0 -0
  40. data/public/javascripts/rails-jqgrid/src/grid.base.js +3078 -3003
  41. data/public/javascripts/rails-jqgrid/src/grid.celledit.js +486 -486
  42. data/public/javascripts/rails-jqgrid/src/grid.common.js +646 -636
  43. data/public/javascripts/rails-jqgrid/src/grid.custom.js +820 -817
  44. data/public/javascripts/rails-jqgrid/src/grid.formedit.js +1954 -1872
  45. data/public/javascripts/rails-jqgrid/src/grid.grouping.js +250 -0
  46. data/public/javascripts/rails-jqgrid/src/grid.import.js +200 -200
  47. data/public/javascripts/rails-jqgrid/src/grid.inlinedit.js +255 -250
  48. data/public/javascripts/rails-jqgrid/src/grid.jqueryui.js +504 -503
  49. data/public/javascripts/rails-jqgrid/src/grid.loader.js +1 -0
  50. data/public/javascripts/rails-jqgrid/src/grid.postext.js +63 -63
  51. data/public/javascripts/rails-jqgrid/src/grid.setcolumns.js +125 -125
  52. data/public/javascripts/rails-jqgrid/src/grid.subgrid.js +260 -260
  53. data/public/javascripts/rails-jqgrid/src/grid.tbltogrid.js +106 -106
  54. data/public/javascripts/rails-jqgrid/src/grid.treegrid.js +489 -482
  55. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg.js +132 -132
  56. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg1251.js +132 -132
  57. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cat.js +128 -128
  58. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cn.js +132 -132
  59. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cs.js +128 -128
  60. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-da.js +128 -0
  61. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-de.js +132 -127
  62. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-dk.js +0 -0
  63. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-el.js +126 -126
  64. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-en.js +128 -128
  65. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-es.js +128 -128
  66. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fa.js +145 -125
  67. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fi.js +130 -130
  68. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fr.js +2 -2
  69. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-gl.js +126 -0
  70. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-he.js +127 -127
  71. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-hu.js +129 -129
  72. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-is.js +126 -126
  73. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-it.js +0 -0
  74. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ja.js +155 -155
  75. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-nl.js +148 -148
  76. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-no.js +0 -0
  77. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pl.js +126 -126
  78. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt-br.js +127 -127
  79. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt.js +125 -125
  80. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ro.js +139 -139
  81. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ru.js +127 -127
  82. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sk.js +127 -127
  83. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sr.js +128 -0
  84. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sv.js +127 -127
  85. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-tr.js +126 -126
  86. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ua.js +127 -127
  87. data/public/javascripts/rails-jqgrid/src/jqDnR.js +68 -67
  88. data/public/javascripts/rails-jqgrid/src/jqModal.js +68 -68
  89. data/public/javascripts/rails-jqgrid/src/jquery.fmatter.js +563 -541
  90. data/public/javascripts/rails-jqgrid/src/jquery.searchFilter.js +1 -1
  91. data/public/javascripts/rails-jqgrid/src/ui.multiselect.js +0 -0
  92. data/public/stylesheets/rails-jqgrid/ellipsis-xbl.xml +0 -0
  93. data/public/stylesheets/rails-jqgrid/ui.jqgrid.css +139 -2
  94. data/rails_jq_grid.gemspec +10 -3
  95. metadata +15 -11
@@ -1,542 +1,564 @@
1
- /*
2
- **
3
- * formatter for values but most of the values if for jqGrid
4
- * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
5
- * we are trying to keep it as light as possible
6
- * Joshua Burnett josh@9ci.com
7
- * http://www.greenbill.com
8
- *
9
- * Changes from Tony Tomov tony@trirand.com
10
- * Dual licensed under the MIT and GPL licenses:
11
- * http://www.opensource.org/licenses/mit-license.php
12
- * http://www.gnu.org/licenses/gpl-2.0.html
13
- *
14
- **/
15
-
16
- ;(function($) {
17
- $.fmatter = {};
18
- //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
19
- //example {id:1234,}
20
- $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
21
- //debug(this);
22
- //debug(cellval);
23
- // build main options before element iteration
24
- opts = $.extend({}, $.jgrid.formatter, opts);
25
- return fireFormatter(formatType,cellval, opts, rwd, act);
26
- };
27
- $.fmatter.util = {
28
- // Taken from YAHOO utils
29
- NumberFormat : function(nData,opts) {
30
- if(!isNumber(nData)) {
31
- nData *= 1;
32
- }
33
- if(isNumber(nData)) {
34
- var bNegative = (nData < 0);
35
- var sOutput = nData + "";
36
- var sDecimalSeparator = (opts.decimalSeparator) ? opts.decimalSeparator : ".";
37
- var nDotIndex;
38
- if(isNumber(opts.decimalPlaces)) {
39
- // Round to the correct decimal place
40
- var nDecimalPlaces = opts.decimalPlaces;
41
- var nDecimal = Math.pow(10, nDecimalPlaces);
42
- sOutput = Math.round(nData*nDecimal)/nDecimal + "";
43
- nDotIndex = sOutput.lastIndexOf(".");
44
- if(nDecimalPlaces > 0) {
45
- // Add the decimal separator
46
- if(nDotIndex < 0) {
47
- sOutput += sDecimalSeparator;
48
- nDotIndex = sOutput.length-1;
49
- }
50
- // Replace the "."
51
- else if(sDecimalSeparator !== "."){
52
- sOutput = sOutput.replace(".",sDecimalSeparator);
53
- }
54
- // Add missing zeros
55
- while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
56
- sOutput += "0";
57
- }
58
- }
59
- }
60
- if(opts.thousandsSeparator) {
61
- var sThousandsSeparator = opts.thousandsSeparator;
62
- nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
63
- nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
64
- var sNewOutput = sOutput.substring(nDotIndex);
65
- var nCount = -1;
66
- for (var i=nDotIndex; i>0; i--) {
67
- nCount++;
68
- if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
69
- sNewOutput = sThousandsSeparator + sNewOutput;
70
- }
71
- sNewOutput = sOutput.charAt(i-1) + sNewOutput;
72
- }
73
- sOutput = sNewOutput;
74
- }
75
- // Prepend prefix
76
- sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
77
- // Append suffix
78
- sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
79
- return sOutput;
80
-
81
- } else {
82
- return nData;
83
- }
84
- },
85
- // Tony Tomov
86
- // PHP implementation. Sorry not all options are supported.
87
- // Feel free to add them if you want
88
- DateFormat : function (format, date, newformat, opts) {
89
- var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
90
- timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
91
- timezoneClip = /[^-+\dA-Z]/g,
92
- pad = function (value, length) {
93
- value = String(value);
94
- length = parseInt(length,10) || 2;
95
- while (value.length < length) { value = '0' + value; }
96
- return value;
97
- },
98
- ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
99
- timestamp=0, dM, k,hl,
100
- dateFormat=["i18n"];
101
- // Internationalization strings
102
- dateFormat["i18n"] = {
103
- dayNames: opts.dayNames,
104
- monthNames: opts.monthNames
105
- };
106
- if( format in opts.masks ) { format = opts.masks[format]; }
107
- if(date.constructor === Date) {
108
- timestamp = date;
109
- } else {
110
- date = date.split(/[\\\/:_;.\t\T\s-]/);
111
- format = format.split(/[\\\/:_;.\t\T\s-]/);
112
- // parsing for month names
113
- for(k=0,hl=format.length;k<hl;k++){
114
- if(format[k] == 'M') {
115
- dM = $.inArray(date[k],dateFormat.i18n.monthNames);
116
- if(dM !== -1 && dM < 12){date[k] = dM+1;}
117
- }
118
- if(format[k] == 'F') {
119
- dM = $.inArray(date[k],dateFormat.i18n.monthNames);
120
- if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
121
- }
122
- if(date[k]) {
123
- ts[format[k].toLowerCase()] = parseInt(date[k],10);
124
- }
125
- }
126
- ts.m = parseInt(ts.m,10)-1;
127
- var ty = ts.y;
128
- if (ty >= 70 && ty <= 99) { ts.y = 1900+ts.y; }
129
- else if (ty >=0 && ty <=69) { ts.y= 2000+ts.y; }
130
- timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
131
- }
132
-
133
- if( newformat in opts.masks ) {
134
- newformat = opts.masks[newformat];
135
- } else if ( !newformat ) {
136
- newformat = 'Y-m-d';
137
- }
138
- var
139
- G = timestamp.getHours(),
140
- i = timestamp.getMinutes(),
141
- j = timestamp.getDate(),
142
- n = timestamp.getMonth() + 1,
143
- o = timestamp.getTimezoneOffset(),
144
- s = timestamp.getSeconds(),
145
- u = timestamp.getMilliseconds(),
146
- w = timestamp.getDay(),
147
- Y = timestamp.getFullYear(),
148
- N = (w + 6) % 7 + 1,
149
- z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
150
- flags = {
151
- // Day
152
- d: pad(j),
153
- D: dateFormat.i18n.dayNames[w],
154
- j: j,
155
- l: dateFormat.i18n.dayNames[w + 7],
156
- N: N,
157
- S: opts.S(j),
158
- //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
159
- w: w,
160
- z: z,
161
- // Week
162
- 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),
163
- // Month
164
- F: dateFormat.i18n.monthNames[n - 1 + 12],
165
- m: pad(n),
166
- M: dateFormat.i18n.monthNames[n - 1],
167
- n: n,
168
- t: '?',
169
- // Year
170
- L: '?',
171
- o: '?',
172
- Y: Y,
173
- y: String(Y).substring(2),
174
- // Time
175
- a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
176
- A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
177
- B: '?',
178
- g: G % 12 || 12,
179
- G: G,
180
- h: pad(G % 12 || 12),
181
- H: pad(G),
182
- i: pad(i),
183
- s: pad(s),
184
- u: u,
185
- // Timezone
186
- e: '?',
187
- I: '?',
188
- O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
189
- P: '?',
190
- T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
191
- Z: '?',
192
- // Full Date/Time
193
- c: '?',
194
- r: '?',
195
- U: Math.floor(timestamp / 1000)
196
- };
197
- return newformat.replace(token, function ($0) {
198
- return $0 in flags ? flags[$0] : $0.substring(1);
199
- });
200
- }
201
- };
202
- $.fn.fmatter.defaultFormat = function(cellval, opts) {
203
- return (isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue ? opts.defaultValue : "&#160;";
204
- };
205
- $.fn.fmatter.email = function(cellval, opts) {
206
- if(!isEmpty(cellval)) {
207
- return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
208
- }else {
209
- return $.fn.fmatter.defaultFormat(cellval,opts );
210
- }
211
- };
212
- $.fn.fmatter.checkbox =function(cval, opts) {
213
- var op = $.extend({},opts.checkbox), ds;
214
- if(!isUndefined(opts.colModel.formatoptions)) {
215
- op = $.extend({},op,opts.colModel.formatoptions);
216
- }
217
- if(op.disabled===true) {ds = "disabled";} else {ds="";}
218
- if(isEmpty(cval) || isUndefined(cval) ) { cval = $.fn.fmatter.defaultFormat(cval,op); }
219
- cval=cval+""; cval=cval.toLowerCase();
220
- var bchk = cval.search(/(false|0|no|off)/i)<0 ? " checked='checked' " : "";
221
- return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
222
- };
223
- $.fn.fmatter.link = function(cellval, opts) {
224
- var op = {target:opts.target };
225
- var target = "";
226
- if(!isUndefined(opts.colModel.formatoptions)) {
227
- op = $.extend({},op,opts.colModel.formatoptions);
228
- }
229
- if(op.target) {target = 'target=' + op.target;}
230
- if(!isEmpty(cellval)) {
231
- return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
232
- }else {
233
- return $.fn.fmatter.defaultFormat(cellval,opts);
234
- }
235
- };
236
- $.fn.fmatter.showlink = function(cellval, opts) {
237
- var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName },
238
- target = "", idUrl;
239
- if(!isUndefined(opts.colModel.formatoptions)) {
240
- op = $.extend({},op,opts.colModel.formatoptions);
241
- }
242
- if(op.target) {target = 'target=' + op.target;}
243
- idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
244
- if(isString(cellval)) { //add this one even if its blank string
245
- return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
246
- }else {
247
- return $.fn.fmatter.defaultFormat(cellval,opts);
248
- }
249
- };
250
- $.fn.fmatter.integer = function(cellval, opts) {
251
- var op = $.extend({},opts.integer);
252
- if(!isUndefined(opts.colModel.formatoptions)) {
253
- op = $.extend({},op,opts.colModel.formatoptions);
254
- }
255
- if(isEmpty(cellval)) {
256
- return op.defaultValue;
257
- }
258
- return $.fmatter.util.NumberFormat(cellval,op);
259
- };
260
- $.fn.fmatter.number = function (cellval, opts) {
261
- var op = $.extend({},opts.number);
262
- if(!isUndefined(opts.colModel.formatoptions)) {
263
- op = $.extend({},op,opts.colModel.formatoptions);
264
- }
265
- if(isEmpty(cellval)) {
266
- return op.defaultValue;
267
- }
268
- return $.fmatter.util.NumberFormat(cellval,op);
269
- };
270
- $.fn.fmatter.currency = function (cellval, opts) {
271
- var op = $.extend({},opts.currency);
272
- if(!isUndefined(opts.colModel.formatoptions)) {
273
- op = $.extend({},op,opts.colModel.formatoptions);
274
- }
275
- if(isEmpty(cellval)) {
276
- return op.defaultValue;
277
- }
278
- return $.fmatter.util.NumberFormat(cellval,op);
279
- };
280
- $.fn.fmatter.date = function (cellval, opts, rwd, act) {
281
- var op = $.extend({},opts.date);
282
- if(!isUndefined(opts.colModel.formatoptions)) {
283
- op = $.extend({},op,opts.colModel.formatoptions);
284
- }
285
- if(!op.reformatAfterEdit && act=='edit'){
286
- return $.fn.fmatter.defaultFormat(cellval, opts);
287
- } else if(!isEmpty(cellval)) {
288
- return $.fmatter.util.DateFormat(op.srcformat,cellval,op.newformat,op);
289
- } else {
290
- return $.fn.fmatter.defaultFormat(cellval, opts);
291
- }
292
- };
293
- $.fn.fmatter.select = function (cellval,opts, rwd, act) {
294
- // jqGrid specific
295
- cellval = cellval + "";
296
- var oSelect = false, ret=[];
297
- if(!isUndefined(opts.colModel.editoptions)){
298
- oSelect= opts.colModel.editoptions.value;
299
- }
300
- if (oSelect) {
301
- var msl = opts.colModel.editoptions.multiple === true ? true : false,
302
- scell = [], sv;
303
- if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
304
- if (isString(oSelect)) {
305
- // mybe here we can use some caching with care ????
306
- var so = oSelect.split(";"), j=0;
307
- for(var i=0; i<so.length;i++){
308
- sv = so[i].split(":");
309
- if(sv.length > 2 ) {
310
- sv[1] = jQuery.map(sv,function(n,i){if(i>0) { return n; } }).join(":");
311
- }
312
- if(msl) {
313
- if(jQuery.inArray(sv[0],scell)>-1) {
314
- ret[j] = sv[1];
315
- j++;
316
- }
317
- } else if($.trim(sv[0])==$.trim(cellval)) {
318
- ret[0] = sv[1];
319
- break;
320
- }
321
- }
322
- } else if(isObject(oSelect)) {
323
- // this is quicker
324
- if(msl) {
325
- ret = jQuery.map(scell, function(n, i){
326
- return oSelect[n];
327
- });
328
- } else {
329
- ret[0] = oSelect[cellval] || "";
330
- }
331
- }
332
- }
333
- cellval = ret.join(", ");
334
- return cellval == "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
335
- };
336
- $.fn.fmatter.rowactions = function(rid,gid,act,keys) {
337
- switch(act)
338
- {
339
- case 'edit':
340
- var restorerow = function() {
341
- $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).show();
342
- $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).hide();
343
- };
344
- $('#'+gid).jqGrid('editRow',rid,keys,null,null,null,{oper:'edit'},restorerow,null,restorerow);
345
- $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).hide();
346
- $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).show();
347
- break;
348
- case 'save':
349
- $('#'+gid).jqGrid('saveRow',rid,null,null );
350
- $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).show();
351
- $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).hide();
352
- break;
353
- case 'cancel' :
354
- $('#'+gid).jqGrid('restoreRow',rid);
355
- $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).show();
356
- $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).hide();
357
- break;
358
- }
359
- };
360
- $.fn.fmatter.actions = function(cellval,opts, rwd) {
361
- var op ={keys:false, editbutton:true, delbutton:true};
362
- if(!isUndefined(opts.colModel.formatoptions)) {
363
- op = $.extend(op,opts.colModel.formatoptions);
364
- }
365
- var rowid = opts.rowId, str="",ocl;
366
- if(typeof(rowid) =='undefined' || isEmpty(rowid)) { return ""; }
367
- if(op.editbutton){
368
- ocl = "onclick=$.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','edit',"+op.keys+");";
369
- str =str+ "<div style='margin-left:8px;'><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>";
370
- }
371
- if(op.delbutton) {
372
- ocl = "onclick=jQuery('#"+opts.gid+"').jqGrid('delGridRow','"+rowid+"');";
373
- 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>";
374
- }
375
- ocl = "onclick=$.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','save',false);";
376
- str = str+"<div title='"+$.jgrid.edit.bSubmit+"' style='float:left;display:none' class='ui-pg-div ui-inline-save'><span class='ui-icon ui-icon-disk' "+ocl+"></span></div>";
377
- ocl = "onclick=$.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','cancel',false);";
378
- str = str+"<div title='"+$.jgrid.edit.bCancel+"' style='float:left;display:none;margin-left:5px;' class='ui-pg-div ui-inline-cancel'><span class='ui-icon ui-icon-cancel' "+ocl+"></span></div></div>";
379
- return str;
380
- };
381
- $.unformat = function (cellval,options,pos,cnt) {
382
- // specific for jqGrid only
383
- var ret, formatType = options.colModel.formatter,
384
- op =options.colModel.formatoptions || {}, sep,
385
- re = /([\.\*\_\'\(\)\{\}\+\?\\])/g;
386
- unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
387
- if(typeof unformatFunc !== 'undefined' && isFunction(unformatFunc) ) {
388
- ret = unformatFunc($(cellval).text(), options, cellval);
389
- } else if(typeof formatType !== 'undefined' && isString(formatType) ) {
390
- var opts = $.jgrid.formatter || {}, stripTag;
391
- switch(formatType) {
392
- case 'integer' :
393
- op = $.extend({},opts.integer,op);
394
- sep = op.thousandsSeparator.replace(re,"\\$1");
395
- stripTag = new RegExp(sep, "g");
396
- ret = $(cellval).text().replace(stripTag,'');
397
- break;
398
- case 'number' :
399
- op = $.extend({},opts.number,op);
400
- sep = op.thousandsSeparator.replace(re,"\\$1");
401
- stripTag = new RegExp(sep, "g");
402
- ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
403
- break;
404
- case 'currency':
405
- op = $.extend({},opts.currency,op);
406
- sep = op.thousandsSeparator.replace(re,"\\$1");
407
- stripTag = new RegExp(sep, "g");
408
- ret = $(cellval).text().replace(stripTag,'').replace(op.decimalSeparator,'.').replace(op.prefix,'').replace(op.suffix,'');
409
- break;
410
- case 'checkbox':
411
- var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
412
- ret = $('input',cellval).attr("checked") ? cbv[0] : cbv[1];
413
- break;
414
- case 'select' :
415
- ret = $.unformat.select(cellval,options,pos,cnt);
416
- break;
417
- case 'actions':
418
- return "";
419
- default:
420
- ret= $(cellval).text();
421
- }
422
- }
423
- return ret ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
424
- };
425
- $.unformat.select = function (cellval,options,pos,cnt) {
426
- // Spacial case when we have local data and perform a sort
427
- // cnt is set to true only in sortDataArray
428
- var ret = [];
429
- var cell = $(cellval).text();
430
- if(cnt===true) { return cell; }
431
- var op = $.extend({},options.colModel.editoptions);
432
- if(op.value){
433
- var oSelect = op.value,
434
- msl = op.multiple === true ? true : false,
435
- scell = [], sv;
436
- if(msl) { scell = cell.split(","); scell = $.map(scell,function(n){return $.trim(n);}); }
437
- if (isString(oSelect)) {
438
- var so = oSelect.split(";"), j=0;
439
- for(var i=0; i<so.length;i++){
440
- sv = so[i].split(":");
441
- if(sv.length > 2 ) {
442
- sv[1] = jQuery.map(sv,function(n,i){if(i>0) { return n; } }).join(":");
443
- }
444
- if(msl) {
445
- if(jQuery.inArray(sv[1],scell)>-1) {
446
- ret[j] = sv[0];
447
- j++;
448
- }
449
- } else if($.trim(sv[1])==$.trim(cell)) {
450
- ret[0] = sv[0];
451
- break;
452
- }
453
- }
454
- } else if(isObject(oSelect)) {
455
- if(!msl) { scell[0] = cell; }
456
- ret = jQuery.map(scell, function(n){
457
- var rv;
458
- $.each(oSelect, function(i,val){
459
- if (val == n) {
460
- rv = i;
461
- return false;
462
- }
463
- });
464
- if( rv) { return rv; }
465
- });
466
- }
467
- return ret.join(", ");
468
- } else {
469
- return cell || "";
470
- }
471
- };
472
- $.unformat.date = function (cellval, opts) {
473
- var op = $.jgrid.formatter.date || {};
474
- if(!isUndefined(opts.formatoptions)) {
475
- op = $.extend({},op,opts.formatoptions);
476
- }
477
- if(!isEmpty(cellval)) {
478
- return $.fmatter.util.DateFormat(op.newformat,cellval,op.srcformat,op);
479
- } else {
480
- return $.fn.fmatter.defaultFormat(cellval, opts);
481
- }
482
- };
483
- function fireFormatter(formatType,cellval, opts, rwd, act) {
484
- var v=cellval;
485
-
486
- if ($.fn.fmatter[formatType]){
487
- v = $.fn.fmatter[formatType](cellval, opts, rwd, act);
488
- }
489
-
490
- return v;
491
- }
492
- //private methods and data
493
- function debug($obj) {
494
- if (window.console && window.console.log) { window.console.log($obj); }
495
- }
496
- /**
497
- * A convenience method for detecting a legitimate non-null value.
498
- * Returns false for null/undefined/NaN, true for other values,
499
- * including 0/false/''
500
- * --taken from the yui.lang
501
- */
502
- isValue= function(o) {
503
- return (isObject(o) || isString(o) || isNumber(o) || isBoolean(o));
504
- };
505
- isBoolean= function(o) {
506
- return typeof o === 'boolean';
507
- };
508
- isNull= function(o) {
509
- return o === null;
510
- };
511
- isNumber= function(o) {
512
- return typeof o === 'number' && isFinite(o);
513
- };
514
- isString= function(o) {
515
- return typeof o === 'string';
516
- };
517
- /**
518
- * check if its empty trim it and replace \&nbsp and \&#160 with '' and check if its empty ===""
519
- * if its is not a string but has a value then it returns false, Returns true for null/undefined/NaN
520
- essentailly this provdes a way to see if it has any value to format for things like links
521
- */
522
- isEmpty= function(o) {
523
- if(!isString(o) && isValue(o)) {
524
- return false;
525
- }else if (!isValue(o)){
526
- return true;
527
- }
528
- o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
529
- return o==="";
530
-
531
- };
532
- isUndefined= function(o) {
533
- return typeof o === 'undefined';
534
- };
535
- isObject= function(o) {
536
- return (o && (typeof o === 'object' || isFunction(o))) || false;
537
- };
538
- isFunction= function(o) {
539
- return typeof o === 'function';
540
- };
541
-
1
+ /*
2
+ **
3
+ * formatter for values but most of the values if for jqGrid
4
+ * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
5
+ * we are trying to keep it as light as possible
6
+ * Joshua Burnett josh@9ci.com
7
+ * http://www.greenbill.com
8
+ *
9
+ * Changes from Tony Tomov tony@trirand.com
10
+ * Dual licensed under the MIT and GPL licenses:
11
+ * http://www.opensource.org/licenses/mit-license.php
12
+ * http://www.gnu.org/licenses/gpl-2.0.html
13
+ *
14
+ **/
15
+
16
+ ;(function($) {
17
+ $.fmatter = {};
18
+ //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
19
+ //example {id:1234,}
20
+ $.extend($.fmatter,{
21
+ isBoolean : function(o) {
22
+ return typeof o === 'boolean';
23
+ },
24
+ isObject : function(o) {
25
+ return (o && (typeof o === 'object' || $.isFunction(o))) || false;
26
+ },
27
+ isString : function(o) {
28
+ return typeof o === 'string';
29
+ },
30
+ isNumber : function(o) {
31
+ return typeof o === 'number' && isFinite(o);
32
+ },
33
+ isNull : function(o) {
34
+ return o === null;
35
+ },
36
+ isUndefined : function(o) {
37
+ return typeof o === 'undefined';
38
+ },
39
+ isValue : function (o) {
40
+ return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
41
+ },
42
+ isEmpty : function(o) {
43
+ if(!this.isString(o) && this.isValue(o)) {
44
+ return false;
45
+ }else if (!this.isValue(o)){
46
+ return true;
47
+ }
48
+ o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
49
+ return o==="";
50
+ }
51
+ });
52
+ $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
53
+ // build main options before element iteration
54
+ var v=cellval;
55
+ opts = $.extend({}, $.jgrid.formatter, opts);
56
+
57
+ if ($.fn.fmatter[formatType]){
58
+ v = $.fn.fmatter[formatType](cellval, opts, rwd, act);
59
+ }
60
+ return v;
61
+ };
62
+ $.fmatter.util = {
63
+ // Taken from YAHOO utils
64
+ NumberFormat : function(nData,opts) {
65
+ if(!$.fmatter.isNumber(nData)) {
66
+ nData *= 1;
67
+ }
68
+ if($.fmatter.isNumber(nData)) {
69
+ var bNegative = (nData < 0);
70
+ var sOutput = nData + "";
71
+ var sDecimalSeparator = (opts.decimalSeparator) ? opts.decimalSeparator : ".";
72
+ var nDotIndex;
73
+ if($.fmatter.isNumber(opts.decimalPlaces)) {
74
+ // Round to the correct decimal place
75
+ var nDecimalPlaces = opts.decimalPlaces;
76
+ var nDecimal = Math.pow(10, nDecimalPlaces);
77
+ sOutput = Math.round(nData*nDecimal)/nDecimal + "";
78
+ nDotIndex = sOutput.lastIndexOf(".");
79
+ if(nDecimalPlaces > 0) {
80
+ // Add the decimal separator
81
+ if(nDotIndex < 0) {
82
+ sOutput += sDecimalSeparator;
83
+ nDotIndex = sOutput.length-1;
84
+ }
85
+ // Replace the "."
86
+ else if(sDecimalSeparator !== "."){
87
+ sOutput = sOutput.replace(".",sDecimalSeparator);
88
+ }
89
+ // Add missing zeros
90
+ while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
91
+ sOutput += "0";
92
+ }
93
+ }
94
+ }
95
+ if(opts.thousandsSeparator) {
96
+ var sThousandsSeparator = opts.thousandsSeparator;
97
+ nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
98
+ nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
99
+ var sNewOutput = sOutput.substring(nDotIndex);
100
+ var nCount = -1;
101
+ for (var i=nDotIndex; i>0; i--) {
102
+ nCount++;
103
+ if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
104
+ sNewOutput = sThousandsSeparator + sNewOutput;
105
+ }
106
+ sNewOutput = sOutput.charAt(i-1) + sNewOutput;
107
+ }
108
+ sOutput = sNewOutput;
109
+ }
110
+ // Prepend prefix
111
+ sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
112
+ // Append suffix
113
+ sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
114
+ return sOutput;
115
+
116
+ } else {
117
+ return nData;
118
+ }
119
+ },
120
+ // Tony Tomov
121
+ // PHP implementation. Sorry not all options are supported.
122
+ // Feel free to add them if you want
123
+ DateFormat : function (format, date, newformat, opts) {
124
+ var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
125
+ timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
126
+ timezoneClip = /[^-+\dA-Z]/g,
127
+ msDateRegExp = new RegExp("^/Date\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\)/$"),
128
+ msMatch = date.match(msDateRegExp),
129
+ pad = function (value, length) {
130
+ value = String(value);
131
+ length = parseInt(length,10) || 2;
132
+ while (value.length < length) { value = '0' + value; }
133
+ return value;
134
+ },
135
+ ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
136
+ timestamp=0, dM, k,hl,
137
+ dateFormat=["i18n"];
138
+ // Internationalization strings
139
+ dateFormat.i18n = {
140
+ dayNames: opts.dayNames,
141
+ monthNames: opts.monthNames
142
+ };
143
+ if( format in opts.masks ) { format = opts.masks[format]; }
144
+ if(date.constructor === Number) {
145
+ timestamp = new Date(date);
146
+ } else if(date.constructor === Date) {
147
+ timestamp = date;
148
+ // Microsoft date format support
149
+ } else if( msMatch !== null ) {
150
+ timestamp = new Date(parseInt(msMatch[1], 10));
151
+ if (msMatch[3]) {
152
+ var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
153
+ offset *= ((msMatch[4] == '-') ? 1 : -1);
154
+ offset -= timestamp.getTimezoneOffset();
155
+ timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
156
+ }
157
+ } else {
158
+ date = date.split(/[\\\/:_;.,\t\T\s-]/);
159
+ format = format.split(/[\\\/:_;.,\t\T\s-]/);
160
+ // parsing for month names
161
+ for(k=0,hl=format.length;k<hl;k++){
162
+ if(format[k] == 'M') {
163
+ dM = $.inArray(date[k],dateFormat.i18n.monthNames);
164
+ if(dM !== -1 && dM < 12){date[k] = dM+1;}
165
+ }
166
+ if(format[k] == 'F') {
167
+ dM = $.inArray(date[k],dateFormat.i18n.monthNames);
168
+ if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
169
+ }
170
+ if(date[k]) {
171
+ ts[format[k].toLowerCase()] = parseInt(date[k],10);
172
+ }
173
+ }
174
+ if(ts.f) { ts.m = ts.f; }
175
+ if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
176
+ return "&#160;" ;
177
+ }
178
+ ts.m = parseInt(ts.m,10)-1;
179
+ var ty = ts.y;
180
+ if (ty >= 70 && ty <= 99) { ts.y = 1900+ts.y; }
181
+ else if (ty >=0 && ty <=69) { ts.y= 2000+ts.y; }
182
+ timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
183
+ }
184
+
185
+ if( newformat in opts.masks ) {
186
+ newformat = opts.masks[newformat];
187
+ } else if ( !newformat ) {
188
+ newformat = 'Y-m-d';
189
+ }
190
+ var
191
+ G = timestamp.getHours(),
192
+ i = timestamp.getMinutes(),
193
+ j = timestamp.getDate(),
194
+ n = timestamp.getMonth() + 1,
195
+ o = timestamp.getTimezoneOffset(),
196
+ s = timestamp.getSeconds(),
197
+ u = timestamp.getMilliseconds(),
198
+ w = timestamp.getDay(),
199
+ Y = timestamp.getFullYear(),
200
+ N = (w + 6) % 7 + 1,
201
+ z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
202
+ flags = {
203
+ // Day
204
+ d: pad(j),
205
+ D: dateFormat.i18n.dayNames[w],
206
+ j: j,
207
+ l: dateFormat.i18n.dayNames[w + 7],
208
+ N: N,
209
+ S: opts.S(j),
210
+ //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
211
+ w: w,
212
+ z: z,
213
+ // Week
214
+ 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),
215
+ // Month
216
+ F: dateFormat.i18n.monthNames[n - 1 + 12],
217
+ m: pad(n),
218
+ M: dateFormat.i18n.monthNames[n - 1],
219
+ n: n,
220
+ t: '?',
221
+ // Year
222
+ L: '?',
223
+ o: '?',
224
+ Y: Y,
225
+ y: String(Y).substring(2),
226
+ // Time
227
+ a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
228
+ A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
229
+ B: '?',
230
+ g: G % 12 || 12,
231
+ G: G,
232
+ h: pad(G % 12 || 12),
233
+ H: pad(G),
234
+ i: pad(i),
235
+ s: pad(s),
236
+ u: u,
237
+ // Timezone
238
+ e: '?',
239
+ I: '?',
240
+ O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
241
+ P: '?',
242
+ T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
243
+ Z: '?',
244
+ // Full Date/Time
245
+ c: '?',
246
+ r: '?',
247
+ U: Math.floor(timestamp / 1000)
248
+ };
249
+ return newformat.replace(token, function ($0) {
250
+ return $0 in flags ? flags[$0] : $0.substring(1);
251
+ });
252
+ }
253
+ };
254
+ $.fn.fmatter.defaultFormat = function(cellval, opts) {
255
+ return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue ? opts.defaultValue : "&#160;";
256
+ };
257
+ $.fn.fmatter.email = function(cellval, opts) {
258
+ if(!$.fmatter.isEmpty(cellval)) {
259
+ return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
260
+ }else {
261
+ return $.fn.fmatter.defaultFormat(cellval,opts );
262
+ }
263
+ };
264
+ $.fn.fmatter.checkbox =function(cval, opts) {
265
+ var op = $.extend({},opts.checkbox), ds;
266
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
267
+ op = $.extend({},op,opts.colModel.formatoptions);
268
+ }
269
+ if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
270
+ if($.fmatter.isEmpty(cval) || $.fmatter.isUndefined(cval) ) { cval = $.fn.fmatter.defaultFormat(cval,op); }
271
+ cval=cval+""; cval=cval.toLowerCase();
272
+ var bchk = cval.search(/(false|0|no|off)/i)<0 ? " checked='checked' " : "";
273
+ return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
274
+ };
275
+ $.fn.fmatter.link = function(cellval, opts) {
276
+ var op = {target:opts.target };
277
+ var target = "";
278
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
279
+ op = $.extend({},op,opts.colModel.formatoptions);
280
+ }
281
+ if(op.target) {target = 'target=' + op.target;}
282
+ if(!$.fmatter.isEmpty(cellval)) {
283
+ return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
284
+ }else {
285
+ return $.fn.fmatter.defaultFormat(cellval,opts);
286
+ }
287
+ };
288
+ $.fn.fmatter.showlink = function(cellval, opts) {
289
+ var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName },
290
+ target = "", idUrl;
291
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
292
+ op = $.extend({},op,opts.colModel.formatoptions);
293
+ }
294
+ if(op.target) {target = 'target=' + op.target;}
295
+ idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
296
+ if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
297
+ return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
298
+ }else {
299
+ return $.fn.fmatter.defaultFormat(cellval,opts);
300
+ }
301
+ };
302
+ $.fn.fmatter.integer = function(cellval, opts) {
303
+ var op = $.extend({},opts.integer);
304
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
305
+ op = $.extend({},op,opts.colModel.formatoptions);
306
+ }
307
+ if($.fmatter.isEmpty(cellval)) {
308
+ return op.defaultValue;
309
+ }
310
+ return $.fmatter.util.NumberFormat(cellval,op);
311
+ };
312
+ $.fn.fmatter.number = function (cellval, opts) {
313
+ var op = $.extend({},opts.number);
314
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
315
+ op = $.extend({},op,opts.colModel.formatoptions);
316
+ }
317
+ if($.fmatter.isEmpty(cellval)) {
318
+ return op.defaultValue;
319
+ }
320
+ return $.fmatter.util.NumberFormat(cellval,op);
321
+ };
322
+ $.fn.fmatter.currency = function (cellval, opts) {
323
+ var op = $.extend({},opts.currency);
324
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
325
+ op = $.extend({},op,opts.colModel.formatoptions);
326
+ }
327
+ if($.fmatter.isEmpty(cellval)) {
328
+ return op.defaultValue;
329
+ }
330
+ return $.fmatter.util.NumberFormat(cellval,op);
331
+ };
332
+ $.fn.fmatter.date = function (cellval, opts, rwd, act) {
333
+ var op = $.extend({},opts.date);
334
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
335
+ op = $.extend({},op,opts.colModel.formatoptions);
336
+ }
337
+ if(!op.reformatAfterEdit && act=='edit'){
338
+ return $.fn.fmatter.defaultFormat(cellval, opts);
339
+ } else if(!$.fmatter.isEmpty(cellval)) {
340
+ return $.fmatter.util.DateFormat(op.srcformat,cellval,op.newformat,op);
341
+ } else {
342
+ return $.fn.fmatter.defaultFormat(cellval, opts);
343
+ }
344
+ };
345
+ $.fn.fmatter.select = function (cellval,opts, rwd, act) {
346
+ // jqGrid specific
347
+ cellval = cellval + "";
348
+ var oSelect = false, ret=[];
349
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)){
350
+ oSelect= opts.colModel.formatoptions.value;
351
+ } else if(!$.fmatter.isUndefined(opts.colModel.editoptions)){
352
+ oSelect= opts.colModel.editoptions.value;
353
+ }
354
+ if (oSelect) {
355
+ var msl = opts.colModel.editoptions.multiple === true ? true : false,
356
+ scell = [], sv;
357
+ if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
358
+ if ($.fmatter.isString(oSelect)) {
359
+ // mybe here we can use some caching with care ????
360
+ var so = oSelect.split(";"), j=0;
361
+ for(var i=0; i<so.length;i++){
362
+ sv = so[i].split(":");
363
+ if(sv.length > 2 ) {
364
+ sv[1] = jQuery.map(sv,function(n,i){if(i>0) { return n; } }).join(":");
365
+ }
366
+ if(msl) {
367
+ if(jQuery.inArray(sv[0],scell)>-1) {
368
+ ret[j] = sv[1];
369
+ j++;
370
+ }
371
+ } else if($.trim(sv[0])==$.trim(cellval)) {
372
+ ret[0] = sv[1];
373
+ break;
374
+ }
375
+ }
376
+ } else if($.fmatter.isObject(oSelect)) {
377
+ // this is quicker
378
+ if(msl) {
379
+ ret = jQuery.map(scell, function(n, i){
380
+ return oSelect[n];
381
+ });
382
+ } else {
383
+ ret[0] = oSelect[cellval] || "";
384
+ }
385
+ }
386
+ }
387
+ cellval = ret.join(", ");
388
+ return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
389
+ };
390
+ $.fn.fmatter.rowactions = function(rid,gid,act,pos) {
391
+ var op ={
392
+ keys:false,
393
+ editbutton:true,
394
+ delbutton:true,
395
+ onEdit : null,
396
+ onSuccess: null,
397
+ afterSave:null,
398
+ onError: null,
399
+ afterRestore: null,
400
+ extraparam: {oper:'edit'},
401
+ url: null,
402
+ delOptions: {}
403
+ },
404
+ cm = $('#'+gid)[0].p.colModel[pos];
405
+ if(!$.fmatter.isUndefined(cm.formatoptions)) {
406
+ op = $.extend(op,cm.formatoptions);
407
+ }
408
+ var saverow = function( rowid) {
409
+ if(op.afterSave) op.afterSave(rowid);
410
+ $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).show();
411
+ $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).hide();
412
+ },
413
+ restorerow = function( rowid) {
414
+ if(op.afterRestore) op.afterRestore(rowid);
415
+ $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).show();
416
+ $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).hide();
417
+ };
418
+
419
+ switch(act)
420
+ {
421
+ case 'edit':
422
+ $('#'+gid).jqGrid('editRow',rid, op.keys, op.onEdit, op.onSuccess, op.url, op.extraparam, saverow, op.onError,restorerow);
423
+ $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).hide();
424
+ $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).show();
425
+ break;
426
+ case 'save':
427
+ $('#'+gid).jqGrid('saveRow',rid, op.onSuccess,op.url, op.extraparam, saverow, op.onError,restorerow);
428
+ $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).show();
429
+ $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).hide();
430
+ break;
431
+ case 'cancel' :
432
+ $('#'+gid).jqGrid('restoreRow',rid, restorerow);
433
+ $("tr#"+rid+" div.ui-inline-edit, "+"tr#"+rid+" div.ui-inline-del","#"+gid).show();
434
+ $("tr#"+rid+" div.ui-inline-save, "+"tr#"+rid+" div.ui-inline-cancel","#"+gid).hide();
435
+ break;
436
+ case 'del':
437
+ $('#'+gid).jqGrid('delGridRow',rid, op.delOptions);
438
+ break;
439
+ }
440
+ };
441
+ $.fn.fmatter.actions = function(cellval,opts, rwd) {
442
+ var op ={keys:false, editbutton:true, delbutton:true};
443
+ if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
444
+ op = $.extend(op,opts.colModel.formatoptions);
445
+ }
446
+ var rowid = opts.rowId, str="",ocl;
447
+ if(typeof(rowid) =='undefined' || $.fmatter.isEmpty(rowid)) { return ""; }
448
+ if(op.editbutton){
449
+ ocl = "onclick=$.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','edit',"+opts.pos+");";
450
+ str =str+ "<div style='margin-left:8px;'><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>";
451
+ }
452
+ if(op.delbutton) {
453
+ ocl = "onclick=$.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','del',"+opts.pos+");";
454
+ 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>";
455
+ }
456
+ ocl = "onclick=$.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','save',"+opts.pos+");";
457
+ str = str+"<div title='"+$.jgrid.edit.bSubmit+"' style='float:left;display:none' class='ui-pg-div ui-inline-save'><span class='ui-icon ui-icon-disk' "+ocl+"></span></div>";
458
+ ocl = "onclick=$.fn.fmatter.rowactions('"+rowid+"','"+opts.gid+"','cancel',"+opts.pos+");";
459
+ str = str+"<div title='"+$.jgrid.edit.bCancel+"' style='float:left;display:none;margin-left:5px;' class='ui-pg-div ui-inline-cancel'><span class='ui-icon ui-icon-cancel' "+ocl+"></span></div></div>";
460
+ return str;
461
+ };
462
+ $.unformat = function (cellval,options,pos,cnt) {
463
+ // specific for jqGrid only
464
+ var ret, formatType = options.colModel.formatter,
465
+ op =options.colModel.formatoptions || {}, sep,
466
+ re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
467
+ unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
468
+ if(typeof unformatFunc !== 'undefined' && $.isFunction(unformatFunc) ) {
469
+ ret = unformatFunc($(cellval).text(), options, cellval);
470
+ } else if(!$.fmatter.isUndefined(formatType) && $.fmatter.isString(formatType) ) {
471
+ var opts = $.jgrid.formatter || {}, stripTag;
472
+ switch(formatType) {
473
+ case 'integer' :
474
+ op = $.extend({},opts.integer,op);
475
+ sep = op.thousandsSeparator.replace(re,"\\$1");
476
+ stripTag = new RegExp(sep, "g");
477
+ ret = $(cellval).text().replace(stripTag,'');
478
+ break;
479
+ case 'number' :
480
+ op = $.extend({},opts.number,op);
481
+ sep = op.thousandsSeparator.replace(re,"\\$1");
482
+ stripTag = new RegExp(sep, "g");
483
+ ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
484
+ break;
485
+ case 'currency':
486
+ op = $.extend({},opts.currency,op);
487
+ sep = op.thousandsSeparator.replace(re,"\\$1");
488
+ stripTag = new RegExp(sep, "g");
489
+ ret = $(cellval).text().replace(stripTag,'').replace(op.decimalSeparator,'.').replace(op.prefix,'').replace(op.suffix,'');
490
+ break;
491
+ case 'checkbox':
492
+ var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
493
+ ret = $('input',cellval).attr("checked") ? cbv[0] : cbv[1];
494
+ break;
495
+ case 'select' :
496
+ ret = $.unformat.select(cellval,options,pos,cnt);
497
+ break;
498
+ case 'actions':
499
+ return "";
500
+ default:
501
+ ret= $(cellval).text();
502
+ }
503
+ }
504
+ return ret ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
505
+ };
506
+ $.unformat.select = function (cellval,options,pos,cnt) {
507
+ // Spacial case when we have local data and perform a sort
508
+ // cnt is set to true only in sortDataArray
509
+ var ret = [];
510
+ var cell = $(cellval).text();
511
+ if(cnt===true) { return cell; }
512
+ var op = $.extend({},options.colModel.editoptions);
513
+ if(op.value){
514
+ var oSelect = op.value,
515
+ msl = op.multiple === true ? true : false,
516
+ scell = [], sv;
517
+ if(msl) { scell = cell.split(","); scell = $.map(scell,function(n){return $.trim(n);}); }
518
+ if ($.fmatter.isString(oSelect)) {
519
+ var so = oSelect.split(";"), j=0;
520
+ for(var i=0; i<so.length;i++){
521
+ sv = so[i].split(":");
522
+ if(sv.length > 2 ) {
523
+ sv[1] = jQuery.map(sv,function(n,i){if(i>0) { return n; } }).join(":");
524
+ }
525
+ if(msl) {
526
+ if(jQuery.inArray(sv[1],scell)>-1) {
527
+ ret[j] = sv[0];
528
+ j++;
529
+ }
530
+ } else if($.trim(sv[1])==$.trim(cell)) {
531
+ ret[0] = sv[0];
532
+ break;
533
+ }
534
+ }
535
+ } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
536
+ if(!msl) { scell[0] = cell; }
537
+ ret = jQuery.map(scell, function(n){
538
+ var rv;
539
+ $.each(oSelect, function(i,val){
540
+ if (val == n) {
541
+ rv = i;
542
+ return false;
543
+ }
544
+ });
545
+ if( typeof(rv) != 'undefined' ) { return rv; }
546
+ });
547
+ }
548
+ return ret.join(", ");
549
+ } else {
550
+ return cell || "";
551
+ }
552
+ };
553
+ $.unformat.date = function (cellval, opts) {
554
+ var op = $.jgrid.formatter.date || {};
555
+ if(!$.fmatter.isUndefined(opts.formatoptions)) {
556
+ op = $.extend({},op,opts.formatoptions);
557
+ }
558
+ if(!$.fmatter.isEmpty(cellval)) {
559
+ return $.fmatter.util.DateFormat(op.newformat,cellval,op.srcformat,op);
560
+ } else {
561
+ return $.fn.fmatter.defaultFormat(cellval, opts);
562
+ }
563
+ };
542
564
  })(jQuery);