corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 /**
2 * @author zhixin wen <wenzhixin2010@gmail.com>
3 * extensions: https://github.com/vitalets/x-editable
4 */
5  
6 (function($) {
7  
8 'use strict';
9  
10 $.extend($.fn.bootstrapTable.defaults, {
11 editable: true,
12 onEditableInit: function() {
13 return false;
14 },
15 onEditableSave: function(field, row, oldValue, $el) {
16 return false;
17 },
18 onEditableShown: function(field, row, $el, editable) {
19 return false;
20 },
21 onEditableHidden: function(field, row, $el, reason) {
22 return false;
23 }
24 });
25  
26 $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
27 'editable-init.bs.table': 'onEditableInit',
28 'editable-save.bs.table': 'onEditableSave',
29 'editable-shown.bs.table': 'onEditableShown',
30 'editable-hidden.bs.table': 'onEditableHidden'
31 });
32  
33 var BootstrapTable = $.fn.bootstrapTable.Constructor,
34 _initTable = BootstrapTable.prototype.initTable,
35 _initBody = BootstrapTable.prototype.initBody;
36  
37 BootstrapTable.prototype.initTable = function() {
38 var that = this;
39 _initTable.apply(this, Array.prototype.slice.apply(arguments));
40  
41 if (!this.options.editable) {
42 return;
43 }
44  
45 $.each(this.columns, function(i, column) {
46 if (!column.editable) {
47 return;
48 }
49  
50 var editableOptions = {},
51 editableDataMarkup = [],
52 editableDataPrefix = 'editable-';
53  
54 var processDataOptions = function(key, value) {
55 // Replace camel case with dashes.
56 var dashKey = key.replace(/([A-Z])/g, function($1) {
57 return "-" + $1.toLowerCase();
58 });
59 if (dashKey.slice(0, editableDataPrefix.length) == editableDataPrefix) {
60 var dataKey = dashKey.replace(editableDataPrefix, 'data-');
61 editableOptions[dataKey] = value;
62 }
63 };
64  
65 $.each(that.options, processDataOptions);
66  
67 column.formatter = column.formatter || function(value, row, index) {
68 return value;
69 };
70 column._formatter = column._formatter ? column._formatter : column.formatter;
71 column.formatter = function(value, row, index) {
72 var result = column._formatter ? column._formatter(value, row, index) : value;
73  
74 $.each(column, processDataOptions);
75  
76 $.each(editableOptions, function(key, value) {
77 editableDataMarkup.push(' ' + key + '="' + value + '"');
78 });
79  
80 var _dont_edit_formatter = false;
81 if (column.editable.hasOwnProperty('noeditFormatter')) {
82 _dont_edit_formatter = column.editable.noeditFormatter(value, row, index);
83 }
84  
85 if (_dont_edit_formatter === false) {
86 return ['<a href="javascript:void(0)"',
87 ' data-name="' + column.field + '"',
88 ' data-pk="' + row[that.options.idField] + '"',
89 ' data-value="' + result + '"',
90 editableDataMarkup.join(''),
91 '>' + '</a>'
92 ].join('');
93 } else {
94 return _dont_edit_formatter;
95 }
96  
97 };
98 });
99 };
100  
101 BootstrapTable.prototype.initBody = function() {
102 var that = this;
103 _initBody.apply(this, Array.prototype.slice.apply(arguments));
104  
105 if (!this.options.editable) {
106 return;
107 }
108  
109 $.each(this.columns, function(i, column) {
110 if (!column.editable) {
111 return;
112 }
113  
114 that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
115 .off('save').on('save', function(e, params) {
116 var data = that.getData(),
117 index = $(this).parents('tr[data-index]').data('index'),
118 row = data[index],
119 oldValue = row[column.field];
120  
121 $(this).data('value', params.submitValue);
122 row[column.field] = params.submitValue;
123 that.trigger('editable-save', column.field, row, oldValue, $(this));
124 that.resetFooter();
125 });
126 that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
127 .off('shown').on('shown', function(e, editable) {
128 var data = that.getData(),
129 index = $(this).parents('tr[data-index]').data('index'),
130 row = data[index];
131  
132 that.trigger('editable-shown', column.field, row, $(this), editable);
133 });
134 that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
135 .off('hidden').on('hidden', function(e, reason) {
136 var data = that.getData(),
137 index = $(this).parents('tr[data-index]').data('index'),
138 row = data[index];
139  
140 that.trigger('editable-hidden', column.field, row, $(this), reason);
141 });
142 });
143 this.trigger('editable-init');
144 };
145  
146 })(jQuery);