DatatableMobile.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class DatatableMobile 数据表格组件(移动端)。表格形式的多行数据编辑组件。
  3. * @o2cn 数据表格移动端
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var datatable = this.form.get("name"); //获取组件
  8. * //方法2
  9. * var datatable = this.target; //在组件事件脚本中获取
  10. * @extends MWF.xApplication.process.Xform.DatatablePC
  11. * @o2category FormComponents
  12. * @since v6.2
  13. * @o2range {Process|CMS|Portal}
  14. * @hideconstructor
  15. */
  16. MWF.xApplication.process.Xform.DatatableMobile = new Class(
  17. /** @lends MWF.xApplication.process.Xform.DatatablePC# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.xApplication.process.Xform.DatatablePC,
  21. loadDatatable: function(){
  22. this.loading = true;
  23. this._loadStyles();
  24. this._loadTitleTr();
  25. this._loadTemplate();
  26. this._createTemplateTable();
  27. this._loadTotalTr();
  28. this.fireEvent("load");
  29. this._loadDatatable(function(){
  30. this._loadImportExportAction();
  31. this.fieldModuleLoaded = true;
  32. this.loading = false;
  33. this.fireEvent("postLoad");
  34. }.bind(this));
  35. },
  36. _removeEl: function(){
  37. if( this.templateNode )this.templateNode.destroy();
  38. if( this.totalDiv ){
  39. this.totalDiv.destroy();
  40. this.totalDiv = null;
  41. }
  42. },
  43. _loadTitleTr: function(){
  44. this.titleTr = this.table.getElement("tr");
  45. var ths = this.titleTr.getElements("th");
  46. if (this.json.border){
  47. ths.setStyles({
  48. "border-bottom": this.json.border,
  49. "border-right": this.json.border
  50. });
  51. }
  52. if (this.json.titleStyles)ths.setStyles(this.json.titleStyles);
  53. //datatable$Title Module
  54. ths.each(function(th, index){
  55. var json = this.form._getDomjson(th);
  56. // th.store("dataTable", this);
  57. th.addClass("mwf_origional");
  58. if (json){
  59. // var module = this.form._loadModule(json, th);
  60. // this.form.modules.push(module);
  61. // if( json.isShow === false )th.hide(); //隐藏列
  62. if((json.total === "number") || (json.total === "count"))this.totalFlag = true;
  63. }
  64. }.bind(this));
  65. },
  66. _loadTemplate: function(){
  67. this.templateJson = {};
  68. var trs = this.table.getElements("tr");
  69. this.templateTr = trs[trs.length-1];
  70. var tds = this.templateTr.getElements("td");
  71. if (this.json.border) {
  72. tds.setStyles({
  73. "border-bottom": this.json.border,
  74. "border-right": this.json.border,
  75. "background": "transparent"
  76. });
  77. }
  78. if (this.json.contentStyles)tds.setStyles(this.json.contentStyles);
  79. //datatable$Data Module
  80. var idx = 0;
  81. tds.each(function(td, index){
  82. var json = this.form._getDomjson(td);
  83. // td.store("dataTable", this);
  84. td.addClass("mwf_origional");
  85. if (json){
  86. // var module = this.form._loadModule(json, td);
  87. // this.form.modules.push(module);
  88. if( json.cellType === "sequence" )td.addClass("mwf_sequence"); //序号列
  89. if( json.isShow === false ){
  90. td.hide(); //隐藏列
  91. }else{
  92. if ((idx%2)===0 && this.json.zebraColor){
  93. td.setStyle("background-color", this.json.zebraColor);
  94. }else if(this.json.backgroundColor){
  95. td.setStyle("background-color", this.json.backgroundColor);
  96. }
  97. idx++;
  98. }
  99. }
  100. }.bind(this));
  101. // var moduleNodes = this.form._getModuleNodes(this.templateTr);
  102. // moduleNodes.each(function (node) {
  103. // if (node.get("MWFtype") !== "form") {
  104. // var json = this.form._getDomjson(node);
  105. // this.templateJson[json.id] = json ;
  106. // }
  107. // }.bind(this));
  108. this.templateTr.hide();
  109. },
  110. _createTemplateTable: function(){
  111. this.templateNode = new Element("div").inject(this.node);
  112. var titleDiv = new Element("div", {"styles": this.json.itemTitleStyles}).inject(this.templateNode);
  113. titleDiv.setStyle("overflow", "hidden");
  114. new Element("div.sequenceDiv", {
  115. "styles": {"float": "left"},
  116. "text": MWF.xApplication.process.Xform.LP.item
  117. }).inject(titleDiv);
  118. new Element("div.mwf_sequence", { "styles": {"float": "left"} }).inject(titleDiv);
  119. new Element("div.mwf_editaction", { "styles": this.form.css.mobileDatagridActionNode }).inject(titleDiv);
  120. var table = new Element("table").inject(this.templateNode);
  121. if (this.json.border) {
  122. table.setStyles({
  123. "border-top": this.json.border,
  124. "border-left": this.json.border
  125. });
  126. }
  127. table.setStyles(this.json.tableStyles);
  128. table.set(this.json.properties);
  129. var ths = this.titleTr.getElements("th");
  130. var tds = this.templateTr.getElements("td");
  131. ths.each(function(th, index){
  132. var newTr = new Element("tr").inject(table);
  133. var thJson = this.form._getDomjson(th);
  134. var newTh = th.clone().inject(newTr);
  135. newTh.set("html", th.get("html"));
  136. newTh.set("MWFId",th.get("id"));
  137. if( thJson.isShow === false )newTr.hide();
  138. var moduleJson;
  139. var td = tds[index];
  140. var newTd = td.clone().inject(newTr);
  141. newTd.set("html", td.get("html"));
  142. newTd.set("MWFId",td.get("id"));
  143. }.bind(this));
  144. this.templateHtml = this.templateNode.get("html");
  145. this.table.hide();
  146. this.templateNode.hide();
  147. },
  148. _loadTotalTr: function(){
  149. if( !this.totalFlag )return;
  150. this.totalDiv = new Element("div.mwf_totaltr", {"styles": {"overflow": "hidden", "margin-bottom": "10px"}}).inject(this.node);
  151. if( this.isShowSectionKey() && !(this.json.totalRowBySection || [] ).contains("module")){
  152. this.totalDiv.hide()
  153. }
  154. if( this.isShowSectionBy() && !(this.json.totalRowBy || [] ).contains("module") ){
  155. this.totalDiv.hide()
  156. }
  157. var titleDiv = new Element("div", {"styles": this.json.itemTitleStyles}).inject(this.totalDiv);
  158. titleDiv.setStyle("overflow", "hidden");
  159. new Element("div.sequenceDiv", {
  160. "styles": {"float": "left"},
  161. "text": MWF.xApplication.process.Xform.LP.amount
  162. }).inject(titleDiv);
  163. this.totalTable = new Element("table").inject(this.totalDiv);
  164. if (this.json.border) {
  165. this.totalTable.setStyles({
  166. "border-top": this.json.border,
  167. "border-left": this.json.border
  168. });
  169. }
  170. this.totalTable.setStyles(this.json.tableStyles);
  171. this.totalTable.set(this.json.properties);
  172. var ths = this.titleTr.getElements("th");
  173. var idx = 0;
  174. //datatable$Title Module
  175. ths.each(function(th, index){
  176. var tr = new Element("tr").inject(this.totalTable);
  177. var json = this.form._getDomjson(th);
  178. if (json){
  179. if ((json.total === "number") || (json.total === "count")){
  180. var datath = new Element("th").inject(tr);
  181. datath.set("text", th.get("text"));
  182. if (this.json.border){
  183. ths.setStyles({
  184. "border-bottom": this.json.border,
  185. "border-right": this.json.border
  186. });
  187. }
  188. datath.setStyles(this.json.titleStyles);
  189. var datatd = new Element("td").inject(tr);
  190. if (this.json.border) {
  191. datatd.setStyles({
  192. "border-bottom": this.json.border,
  193. "border-right": this.json.border,
  194. "background": "transparent"
  195. });
  196. }
  197. datatd.setStyles(this.json.amountStyles);
  198. if( json.isShow === false ){
  199. tr.hide(); //隐藏列
  200. }else{
  201. if ((idx%2)===0 && this.json.zebraColor){
  202. datatd.setStyle("background-color", this.json.zebraColor);
  203. }else if(this.json.backgroundColor){
  204. datatd.setStyle("background-color", this.json.backgroundColor);
  205. }
  206. idx++;
  207. }
  208. this.totalColumns.push({
  209. "th" : datath,
  210. "td" : datatd,
  211. "index": index,
  212. "type": json.total
  213. })
  214. }
  215. }
  216. }.bind(this));
  217. var tds = this.templateTr.getElements("td");
  218. //datatable$Data Module
  219. tds.each(function(td, index){
  220. var json = this.form._getDomjson(td);
  221. if (json){
  222. //总计列
  223. var tColumn = this.totalColumns.find(function(a){ return a.index === index });
  224. if(tColumn){
  225. var moduleNodes = this.form._getModuleNodes(td); //获取总计列内的填写组件
  226. if( moduleNodes.length > 0 ){
  227. tColumn.moduleJson = this.form._getDomjson(moduleNodes[0]);
  228. if(tColumn.type === "number")this.totalNumberModuleIds.push( tColumn.moduleJson.id );
  229. }
  230. }
  231. }
  232. }.bind(this));
  233. },
  234. _getTotalTr: function(){
  235. return this.totalDiv;
  236. },
  237. _createLineNode: function(beforeNode){
  238. var div;
  239. if( beforeNode ) {
  240. div = new Element("div").inject(beforeNode, "after");
  241. }else if( this.totalDiv ){
  242. div = new Element("div").inject(this.totalDiv, "before");
  243. }else{
  244. div = new Element("div").inject(this.node);
  245. }
  246. return div;
  247. },
  248. _checkAddAction: function(){
  249. if( this.data.data && this.data.data.length > 0 ){
  250. if(this.addAction)this.addAction.hide();
  251. return;
  252. }
  253. if( !this.editable || !this.addable ){
  254. if(this.addAction)this.addAction.hide();
  255. return;
  256. }
  257. if( !this.addAction ){
  258. this._createAddAction();
  259. }else{
  260. this.addAction.show();
  261. }
  262. },
  263. _createAddAction: function(){
  264. if( !this.addAction ){
  265. this.addAction = new Element("div", {"styles": this.form.css.gridMobileActionNode}).inject(this.node, "top");
  266. this.addAction.set("text", MWF.xApplication.process.Xform.LP.addLine);
  267. this.addAction.addEvent("click", function(e){
  268. this._addLine();
  269. }.bind(this));
  270. }
  271. },
  272. _loadStyles: function(){
  273. if( this.json.recoveryStyles ){
  274. this.node.setStyles(this.json.recoveryStyles);
  275. }
  276. // if (this.json.border) {
  277. // this.table.setStyles({
  278. // "border-top": this.json.border,
  279. // "border-left": this.json.border
  280. // });
  281. // }
  282. // this.node.setStyles(this.json.styles);
  283. // this.table.setStyles(this.json.tableStyles);
  284. // this.table.set(this.json.properties);
  285. },
  286. _loadSectionLine_EditSection: function(container, data, index, isEdited, isNew){
  287. var sectionLine = new MWF.xApplication.process.Xform.DatatableMobile.SectionLine(container, this, data, {
  288. index : index,
  289. indexText : (index+1).toString(),
  290. isNew: isNew,
  291. isEdited: typeOf(isEdited) === "boolean" ? isEdited : this.editable,
  292. isEditable: this.editable && this.isSectionLineEditable(data),
  293. isDeleteable: this.deleteable && this.isSectionLineEditable(data),
  294. isAddable: this.addable && this.isSectionLineEditable(data)
  295. });
  296. // this.fireEvent("beforeLoadLine", [line]);
  297. sectionLine.load();
  298. // this.fireEvent("afterLoadLine", [line]);
  299. return sectionLine;
  300. },
  301. _loadSectionLine: function(container, data, index, isEdited, isNew){
  302. var sectionLine = new MWF.xApplication.process.Xform.DatatableMobile.SectionLine(container, this, data, {
  303. index : index,
  304. indexText : (index+1).toString(),
  305. isNew: isNew,
  306. isEdited: typeOf(isEdited) === "boolean" ? isEdited : this.editable,
  307. isEditable: this.editable,
  308. isDeleteable: this.deleteable,
  309. isAddable: this.addable,
  310. isMergeRead: this.isMergeRead
  311. });
  312. // this.fireEvent("beforeLoadLine", [line]);
  313. sectionLine.load();
  314. // this.fireEvent("afterLoadLine", [line]);
  315. return sectionLine;
  316. },
  317. _loadLine: function(container, data, index, isEdited, isNew){
  318. var line = new MWF.xApplication.process.Xform.DatatableMobile.Line(container, this, data, {
  319. index : index,
  320. indexText : (index+1).toString(),
  321. isNew: isNew,
  322. isEdited: typeOf(isEdited) === "boolean" ? isEdited : this.editable,
  323. isEditable: this.editable,
  324. isDeleteable: this.deleteable,
  325. isAddable: this.addable,
  326. isMergeRead: this.isMergeRead
  327. });
  328. this.fireEvent("beforeLoadLine", [line]);
  329. line.load();
  330. this.fireEvent("afterLoadLine", [line]);
  331. return line;
  332. },
  333. _loadImportExportAction: function(){
  334. this.impexpNode = this.node.getElement("div.impexpNode");
  335. if( this.impexpNode )this.impexpNode.destroy();
  336. }
  337. });
  338. MWF.xApplication.process.Xform.DatatableMobile$Title = new Class({
  339. Extends: MWF.APP$Module,
  340. _loadUserInterface: function(){
  341. if(this.json.recoveryStyles){
  342. this.node.setStyles(this.json.recoveryStyles);
  343. }
  344. if (this.json.prefixIcon || this.json.suffixIcon){
  345. var text = this.node.get("text");
  346. this.node.empty();
  347. var lineheight = this.node.getStyle("line-height") || "28px";
  348. this.wrapNode = new Element("div", {
  349. "styles": {
  350. "display": "flex",
  351. "align-items": "center"
  352. // "justify-content": "center"
  353. }
  354. }).inject(this.node);
  355. if (this.json.prefixIcon){
  356. this.prefixNode = new Element("div", {"styles": {
  357. "width": "20px",
  358. "min-width": "20px",
  359. "height": lineheight,
  360. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  361. }}).inject(this.wrapNode);
  362. }
  363. this.textNode = new Element("div", {"styles": {
  364. "line-height": lineheight,
  365. "vertical-align": "top",
  366. "padding": "1px"
  367. }, "text": text}).inject(this.wrapNode);
  368. if (this.json.suffixIcon){
  369. this.suffixNode = new Element("div", {"styles": {
  370. "width": "20px",
  371. "min-width": "20px",
  372. "height": lineheight,
  373. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  374. }}).inject(this.wrapNode);
  375. }
  376. }
  377. }
  378. });
  379. MWF.xApplication.process.Xform.DatatableMobile$Data = new Class({
  380. Extends: MWF.APP$Module
  381. });
  382. MWF.xApplication.process.Xform.DatatableMobile.SectionLine = new Class({
  383. Extends: MWF.xApplication.process.Xform.DatatablePC.SectionLine,
  384. _loadLine: function(container, data, index, isEdited, isNew){
  385. var line = new MWF.xApplication.process.Xform.DatatableMobile.Line(container, this.datatable, data, {
  386. indexInSectionLine : index,
  387. indexInSectionLineText : (index+1).toString(),
  388. index: this.datatable.lineList.length,
  389. indexText : (this.datatable.lineList.length + 1).toString(),
  390. isNew: isNew,
  391. isEdited: typeOf(isEdited) === "boolean" ? isEdited : this.options.isEdited,
  392. isEditable: this.options.isEditable,
  393. isDeleteable: this.options.isDeleteable,
  394. isAddable: this.options.isAddable,
  395. isMergeRead: this.options.isMergeRead,
  396. sectionKey: this.sectionKey
  397. }, this);
  398. this.datatable.fireEvent("beforeLoadLine", [line]);
  399. line.load();
  400. this.datatable.fireEvent("afterLoadLine", [line]);
  401. return line;
  402. },
  403. _createLineNode: function( beforeNode ){
  404. var div;
  405. if( beforeNode ){
  406. div = new Element("div").inject(beforeNode, "after");
  407. }else if( this.totalDiv ){
  408. div = new Element("div").inject(this.totalDiv, "before");
  409. }else{
  410. div = this.datatable._createLineNode();
  411. // tr = new Element("tr").inject(this.tBody || this.table);
  412. }
  413. return div;
  414. },
  415. loadSectionKeyNode: function () {
  416. debugger;
  417. var styleName = this.datatable.isShowSectionKey() ? "sectionKeyStyles" : "sectionByStyles";
  418. var sectionKeyStyles = this.datatable._parseStyles( this.datatable.json[styleName] || {} );
  419. var keyNode = new Element("div.mwf_sectionkey", {
  420. styles : sectionKeyStyles
  421. }).inject( this.sectionKeyNode );
  422. this.keyNode = keyNode;
  423. var separator;
  424. if( this.datatable.isShowSectionKey() ){
  425. separator = this.datatable.json.keyContentSeparator;
  426. }else{
  427. separator = this.datatable.json.keyContentSeparatorSectionBy;
  428. }
  429. this.datatable.getSectionKeyWithMerge( this.data, function (key) {
  430. if( o2.typeOf(key) === "string" ){
  431. keyNode.set("text", key + (separator || ""));
  432. }else{
  433. Promise.resolve(key).then(function (k) {
  434. keyNode.set("text", k + (separator || ""));
  435. }.bind(this))
  436. }
  437. }.bind(this));
  438. },
  439. clearSubModules: function(){
  440. if( this.isUnchangedAll )return;
  441. var map = this.unchangedLineMap || {};
  442. var hasUnchangedLine = Object.keys(map).length > 0;
  443. if( !hasUnchangedLine ){
  444. if( this.sectionKeyNode ){
  445. this.sectionKeyNode.destroy();
  446. this.sectionKeyNode = null;
  447. }
  448. }
  449. var lines = [];
  450. Object.values(map).each(function (d) {
  451. lines = lines.concat(d);
  452. });
  453. for (var i=0; i<this.lineList.length; i++){
  454. var l = this.lineList[i];
  455. if(!lines.contains(l)){
  456. l.clearSubModules();
  457. }
  458. }
  459. if( !hasUnchangedLine ) {
  460. if( this.totalDiv ){
  461. this.totalDiv.destroy();
  462. this.totalDiv = null;
  463. }
  464. }
  465. },
  466. _loadTotalTr: function(){
  467. if( !this.datatable.totalFlag )return false;
  468. this.totalDiv = new Element("div.mwf_totaltr", {"styles": {"overflow": "hidden", "margin-bottom": "10px"}}).inject(this.sectionKeyNode, "after");
  469. if( !this.isTotalTrShow() )this.totalDiv.hide();
  470. var titleDiv = new Element("div", {"styles": this.datatable.json.itemTitleStyles}).inject(this.totalDiv);
  471. titleDiv.setStyle("overflow", "hidden");
  472. new Element("div.sequenceDiv", {
  473. "styles": {"float": "left"},
  474. "text": MWF.xApplication.process.Xform.LP.sectionAmount
  475. }).inject(titleDiv);
  476. this.totalTable = new Element("table").inject(this.totalDiv);
  477. if (this.datatable.json.border) {
  478. this.totalTable.setStyles({
  479. "border-top": this.json.border,
  480. "border-left": this.json.border
  481. });
  482. }
  483. this.totalTable.setStyles(this.datatable.json.tableStyles);
  484. this.totalTable.set(this.datatable.json.properties);
  485. var ths = this.datatable.titleTr.getElements("th");
  486. var idx = 0;
  487. //datatable$Title Module
  488. ths.each(function(th, index){
  489. var tr = new Element("tr").inject(this.totalTable);
  490. var json = this.datatable.form._getDomjson(th);
  491. if (json){
  492. if ((json.total === "number") || (json.total === "count")){
  493. var datath = new Element("th").inject(tr);
  494. datath.set("text", th.get("text"));
  495. if (this.datatable.json.border){
  496. ths.setStyles({
  497. "border-bottom": this.datatable.json.border,
  498. "border-right": this.datatable.json.border
  499. });
  500. }
  501. datath.setStyles(this.datatable.json.titleStyles);
  502. var datatd = new Element("td").inject(tr);
  503. if (this.datatable.json.border) {
  504. datatd.setStyles({
  505. "border-bottom": this.datatable.json.border,
  506. "border-right": this.datatable.json.border,
  507. "background": "transparent"
  508. });
  509. }
  510. datatd.setStyles(this.datatable.json.sectionAmountStyles || {});
  511. if( json.isShow === false ){
  512. tr.hide(); //隐藏列
  513. }else{
  514. if ((idx%2)===0 && this.datatable.json.zebraColor){
  515. datatd.setStyle("background-color", this.datatable.json.zebraColor);
  516. }else if(this.datatable.json.backgroundColor){
  517. datatd.setStyle("background-color", this.datatable.json.backgroundColor);
  518. }
  519. idx++;
  520. }
  521. this.totalColumns.push({
  522. "th" : datath,
  523. "td" : datatd,
  524. "index": index,
  525. "type": json.total
  526. })
  527. }
  528. }
  529. }.bind(this));
  530. var tds = this.datatable.templateTr.getElements("td");
  531. //datatable$Data Module
  532. tds.each(function(td, index){
  533. var json = this.form._getDomjson(td);
  534. if (json){
  535. //总计列
  536. var tColumn = this.totalColumns.find(function(a){ return a.index === index });
  537. if(tColumn){
  538. var moduleNodes = this.form._getModuleNodes(td); //获取总计列内的填写组件
  539. if( moduleNodes.length > 0 ){
  540. tColumn.moduleJson = this.form._getDomjson(moduleNodes[0]);
  541. if(tColumn.type === "number")this.totalNumberModuleIds.push( tColumn.moduleJson.id );
  542. }
  543. }
  544. }
  545. }.bind(this));
  546. },
  547. _getTotalTr: function(){
  548. return this.totalDiv;
  549. },
  550. getLastTr: function () {
  551. if( this.totalDiv )return this.totalDiv;
  552. if( this.lineList.length )return this.lineList.getLast().node;
  553. return this.sectionKeyNode;
  554. }
  555. });
  556. MWF.xApplication.process.Xform.DatatableMobile.Line = new Class({
  557. Extends: MWF.xApplication.process.Xform.DatatablePC.Line,
  558. load: function(){
  559. if( !this.datatable.multiEditMode && this.options.isEdited )this.datatable.currentEditedLine = this;
  560. this.node.addClass("mwf_datatable");
  561. this.node.setStyles( Object.merge({"margin-bottom": "10px"}, this.datatable.json.styles||{} )); //"overflow": "hidden",
  562. this.loadModules();
  563. this.loadSequence();
  564. this.createActions();
  565. // this.loadZebraStyle();
  566. // this.loadEditedStyle();
  567. if( !this.datatable.multiEditMode )this.originalData = Object.clone(this.data);
  568. // if(this.options.isNew && this.options.isEdited){
  569. // debugger;
  570. // this.data = this.getData();
  571. // if( !this.datatable.multiEditMode )this.originalData = Object.clone(this.data);
  572. // this.options.isNew = false;
  573. // }
  574. },
  575. createActions: function () {
  576. //不允许编辑,直接返回
  577. if(!this.options.isEditable)return;
  578. var editActionTd = this.node.getElement(".mwf_editaction");
  579. //this.moveActionTd = this.node.getElement(".moveAction");
  580. if(this.datatable.multiEditMode){ //多行编辑模式
  581. if(this.options.isDeleteable)this.createDelAction(editActionTd);
  582. if(this.options.isAddable)this.createAddAction(editActionTd);
  583. }else{ //单行编辑模式
  584. if(this.options.isDeleteable)this.createDelAction(editActionTd);
  585. if(this.options.isEditable)this.createEditAction(editActionTd);
  586. if(this.options.isAddable)this.createAddAction(editActionTd);
  587. this.createCancelEditAction(editActionTd);
  588. this.createCompleteAction(editActionTd);
  589. this.checkActionDisplay();
  590. }
  591. },
  592. checkActionDisplay: function(){
  593. if( this.options.isEdited ){
  594. if( this.addLineAction )this.addLineAction.hide();
  595. if( this.editLineAction )this.editLineAction.hide();
  596. if( this.delLineAction )this.delLineAction.hide();
  597. if( this.completeLineAction )this.completeLineAction.show();
  598. if( this.cancelLineEditAction )this.cancelLineEditAction.show();
  599. }else{
  600. if( this.addLineAction )this.addLineAction.show();
  601. if( this.editLineAction )this.editLineAction.show();
  602. if( this.delLineAction )this.delLineAction.show();
  603. if( this.completeLineAction )this.completeLineAction.hide();
  604. if( this.cancelLineEditAction )this.cancelLineEditAction.hide();
  605. }
  606. },
  607. createEditAction: function(td){
  608. this.editLineAction = new Element("div", {
  609. "styles": this.form.css.mobileDatagridEditActionNode,
  610. "text": MWF.xApplication.process.Xform.LP.edit,
  611. "events": {
  612. "click": function(ev){
  613. if( !this.options.isEdited ){
  614. this.datatable._changeEditedLine(this)
  615. }
  616. ev.stopPropagation();
  617. }.bind(this)
  618. }
  619. }).inject(td);
  620. },
  621. createAddAction: function(td){
  622. this.addLineAction = new Element("div", {
  623. "styles": this.form.css.mobileDatagridAddActionNode,
  624. "text": MWF.xApplication.process.Xform.LP.add,
  625. "events": {
  626. "click": function(ev){
  627. this.datatable._insertLine( ev, this );
  628. ev.stopPropagation();
  629. }.bind(this)
  630. }
  631. }).inject(td);
  632. },
  633. createCompleteAction: function(td){
  634. this.completeLineAction = new Element("div", {
  635. "styles": this.form.css.mobileDatagridCompleteActionNode,
  636. "text": MWF.xApplication.process.Xform.LP.completedEdit,
  637. "events": {
  638. "click": function(ev){
  639. this.datatable._completeLineEdit(ev, true);
  640. ev.stopPropagation();
  641. }.bind(this)
  642. }
  643. }).inject(td);
  644. },
  645. createCancelEditAction: function(td){
  646. this.cancelLineEditAction = new Element("div", {
  647. "styles": this.form.css.mobileDatagridDelActionNode,
  648. "text": MWF.xApplication.process.Xform.LP.cancelEdit,
  649. "events": {
  650. "click": function(ev){
  651. this.datatable._cancelLineEdit(ev, this);
  652. ev.stopPropagation();
  653. }.bind(this)
  654. }
  655. }).inject(td);
  656. },
  657. createDelAction: function(td){
  658. this.delLineAction = new Element("div", {
  659. "styles": this.form.css.mobileDatagridCancelActionNode,
  660. "text": MWF.xApplication.process.Xform.LP["delete"],
  661. "events": {
  662. "click": function(ev){
  663. this.datatable._deleteLine( ev, this );
  664. // if( this.datatable.currentEditedLine === this )this.datatable.currentEditedLine = null;
  665. ev.stopPropagation();
  666. }.bind(this)
  667. }
  668. }).inject(td);
  669. this.delLineAction.show()
  670. }
  671. });