corrade-nucleus-nucleons – Blame information for rev 24
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | /** |
2 | * @author horken wong <horken.wong@gmail.com> |
||
3 | * @version: v1.0.0 |
||
4 | * https://github.com/horkenw/bootstrap-table |
||
5 | * Click to edit row for bootstrap-table |
||
6 | */ |
||
7 | |||
8 | (function ($) { |
||
9 | 'use strict'; |
||
10 | |||
11 | $.extend($.fn.bootstrapTable.defaults, { |
||
12 | clickEdit: false |
||
13 | }); |
||
14 | |||
15 | function setDivision(node, options){ |
||
16 | var $option = $('<option />'); |
||
17 | if(options){ |
||
18 | $(options).each(function(i, v){ |
||
19 | $option.clone().text(v.idxNum + ' ' +v.name).val(v.idxNum).appendTo(node); |
||
20 | }) |
||
21 | } |
||
22 | else{ |
||
23 | console.log('Please setup options first!!') |
||
24 | } |
||
25 | } |
||
26 | |||
27 | function clikcToEdit(evt, tarNode){ |
||
28 | var txt = [], table = evt, |
||
29 | submit = '<button type="button" class="btn btn-primary btn-sm editable-submit"><i class="glyphicon glyphicon-ok"></i></button>', |
||
30 | cancel = '<button type="button" class="btn btn-default btn-sm editable-cancel"><i class="glyphicon glyphicon-remove"></i></button>'; |
||
31 | |||
32 | var replaceData = function(){ |
||
33 | txt = []; |
||
34 | tarNode.find('td').find('input[type="text"]').each(function(i, td){ |
||
35 | txt.push($(td).eq(0).val()); |
||
36 | }); |
||
37 | tarNode.find('select').each(function(i, td){ |
||
38 | txt.push($('#'+td.id+' option:selected').val()); |
||
39 | }); |
||
40 | $('#table').bootstrapTable('updateRow', { |
||
41 | index: table.$data.thId, |
||
42 | row: { |
||
43 | noOld: txt[0], |
||
44 | area: tarNode.find('select').eq(0).children(':selected').text(), |
||
45 | town: tarNode.find('select').eq(1).children(':selected').text(), |
||
46 | address: txt[1] |
||
47 | } |
||
48 | }); |
||
49 | $('#tooling').remove(); |
||
50 | table.editing = true; |
||
51 | // updateToServerSide(table.$data.itemid, txt); |
||
52 | return false; |
||
53 | }; |
||
54 | |||
55 | var recoveryData = function(){ |
||
56 | $('#table').bootstrapTable('updateRow', { |
||
57 | index: table.$data.thId, |
||
58 | row: {}, |
||
59 | }); |
||
60 | $('#tooling').remove(); |
||
61 | table.editing = true; |
||
62 | return false; |
||
63 | }; |
||
64 | |||
65 | if(table.editing){ |
||
66 | var rootid = 0; |
||
67 | table.editing = false; |
||
68 | table.columns.forEach(function(column, i){ |
||
69 | if (!column.editable) return; |
||
70 | |||
71 | switch(column.editable){ |
||
72 | case 'input': |
||
73 | var div=$('<div class="editable-input col-md-12 col-sm-12 col-xs-12" style="position: relative;"/>'); |
||
74 | txt.push(tarNode.find('td').eq(column.fieldIndex).text()); |
||
75 | div.append($('<input type="text" class="form-control input-sm"/>')); |
||
76 | div.append($('<span class="clear"><i class="fa fa-times-circle-o" aria-hidden="true"></i></span>')); |
||
77 | tarNode.find('td').eq(column.fieldIndex).text('').append(div); |
||
78 | break; |
||
79 | case 'select': |
||
80 | var select=$('<select id="'+column.field+'">'), options = $.selectArray[column.field]; |
||
81 | tarNode.find('td').eq(column.fieldIndex).text('').append(select); |
||
82 | setDivision($('#'+column.field), options); |
||
83 | break; |
||
84 | case 'textarea': |
||
85 | break; |
||
86 | default: |
||
87 | console.log(column.fieldIndex+' '+column.editable); |
||
88 | } |
||
89 | |||
90 | }, evt); |
||
91 | for(var i=0, l=txt.length; i<l; i++){ |
||
92 | tarNode.find('input[type="text"]').eq(i).val(txt[i]); |
||
93 | } |
||
94 | tarNode.find('td').last().append('<div id="tooling" class="editable-buttons"/>'); |
||
95 | $('.clear').on('click', function(){ $(this).parent().find('input').val('');}); |
||
96 | $(submit).on('click', replaceData).appendTo('#tooling'); |
||
97 | $(cancel).on('click', recoveryData).appendTo('#tooling'); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | function updateToServerSide(item, data){ |
||
102 | var itemid = $(item).find('a').attr('href').match(/\d+/g)[0]; |
||
103 | var datas = {'treeId': itemid, 'oldTreeSerialNo': data[0], 'adminDivision': data[2], 'adminUnit': data[3], 'treeAddr': data[1]}; //傳送至伺服器端的Data產生處,需手動修改對應表格 |
||
104 | store( 'data/update', datas) |
||
105 | } |
||
106 | |||
107 | var BootstrapTable = $.fn.bootstrapTable.Constructor, |
||
108 | _initTable = BootstrapTable.prototype.initTable, |
||
109 | _initBody = BootstrapTable.prototype.initBody; |
||
110 | |||
111 | BootstrapTable.prototype.initTable = function(){ |
||
112 | var that = this; |
||
113 | this.$data = {}; |
||
114 | _initTable.apply(this, Array.prototype.slice.apply(arguments)); |
||
115 | |||
116 | if (!this.options.clickEdit) { |
||
117 | return; |
||
118 | } |
||
119 | |||
120 | }; |
||
121 | |||
122 | BootstrapTable.prototype.initBody = function () { |
||
123 | var that = this; |
||
124 | _initBody.apply(this, Array.prototype.slice.apply(arguments)); |
||
125 | |||
126 | if (!this.options.clickEdit) { |
||
127 | return; |
||
128 | } |
||
129 | |||
130 | var table = this.$tableBody.find('table'); |
||
131 | that.editing=true; |
||
132 | |||
133 | table.on('click-row.bs.table', function (e, row, $element, field) { |
||
134 | if(field ==='no') return; //|| field ==='noOld' |
||
135 | this.$data.thId = $element.data().index; |
||
136 | this.$data.itemid = $element.data().uniqueid; |
||
137 | this.$data.divi = parseInt(row.area); |
||
138 | this.$data.town=parseInt(row.town); |
||
139 | clikcToEdit(this, $element); |
||
140 | }.bind(this)); |
||
141 | }; |
||
142 | })(jQuery); |