ProjectionEditor.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. MWF.xApplication.cms.ColumnManager.widget = MWF.xApplication.cms.ColumnManager.widget || {};
  2. MWF.xDesktop.requireApp("cms.ColumnManager", "lp."+o2.language,null,false);
  3. MWF.xApplication.cms.ColumnManager.widget.ProjectionEditor = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default",
  8. "maxTypeCount": {
  9. "string": 10,
  10. "long": 2,
  11. "double": 2,
  12. "dateTime": 3
  13. }
  14. },
  15. initialize: function(node, text, options){
  16. this.setOptions(options);
  17. this.node = $(node);
  18. this.data = (text) ? JSON.decode(text) : [];
  19. this.name = node.get("name");
  20. this.path = "../x_component_cms_ColumnManager/widget/$ProjectionEditor/";
  21. this.cssPath = "../x_component_cms_ColumnManager/widget/$ProjectionEditor/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.selectedItems = [];
  24. this.items = {};
  25. },
  26. getData: function(){
  27. return this.data;
  28. },
  29. load: function(){
  30. this.node.set("html", this.getHtml());
  31. this.node.setStyles({
  32. "margin": "0px 40px"
  33. });
  34. this.titleNode = this.node.getFirst("div").setStyles(this.css.titleNode).set("text", MWF.xApplication.cms.ColumnManager.LP.projectionTitle);
  35. this.runAction = new Element("div", {"styles": this.css.runAction, "text": MWF.xApplication.cms.ColumnManager.LP.projectionRunActionNode}).inject(this.titleNode);
  36. this.runAction.addEvent("click", function(e){
  37. var _self = this;
  38. MWF.xDesktop.confirm("infor", e, MWF.xApplication.cms.ColumnManager.LP.projectionRunTitle, MWF.xApplication.cms.ColumnManager.LP.projectionRunText, 300, 120, function(){
  39. _self.runProjection();
  40. this.close();
  41. }, function(){
  42. this.close();
  43. }, null, null, "o2");
  44. }.bind(this));
  45. // this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.node);
  46. // this.titleNode.set("text", MWF.xApplication.cms.ColumnManager.LP.projectionTitle);
  47. this.contentNode = this.titleNode.getNext();
  48. this.tableArea = this.contentNode.getLast("div");
  49. this.actionNode = this.tableArea.getPrevious().setStyles(this.css.actionNode).set("text", "↓ "+MWF.xApplication.cms.ColumnManager.LP.projectionActionNode_add);
  50. var inputs = this.node.getElements("input");
  51. this.nameInput = inputs[0];
  52. this.pathInput = inputs[1];
  53. this.typeSelect = this.node.getElement("select");
  54. // this.tableArea = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  55. var html = "<table cellspacing='0' cellpadding='3px' width='100%' border='0'><tr>" +
  56. "<th>"+MWF.xApplication.cms.ColumnManager.LP.projectionDataName+"</th>" +
  57. "<th>"+MWF.xApplication.cms.ColumnManager.LP.projectionPath+"</th>" +
  58. "<th>"+MWF.xApplication.cms.ColumnManager.LP.projectionType+"</th>" +
  59. "<th>"+MWF.xApplication.cms.ColumnManager.LP.projectionColumnName+"</th>" +
  60. "<th></th>" +
  61. "</tr></table>";
  62. this.tableArea.set("html", html);
  63. this.table = this.tableArea.getElement("table").setStyles(this.css.projectionTable);
  64. this.tableArea.getElements("th").setStyles(this.css.projectionTableTitle);
  65. this.loadProjectionList();
  66. this.actionNode.addEvent("click", this.changeProjectionItem.bind(this));
  67. },
  68. getHtml: function(){
  69. var html =
  70. '<div>'+MWF.xApplication.cms.ColumnManager.LP.mappingData+'</div>'+
  71. '<div style="max-width: 800px;margin-bottom: 40px;">'+
  72. ' <table width="100%" border="0" cellpadding="2" cellspacing="0" class="editTable">'+
  73. ' <tr>'+
  74. ' <td class="editTableTitle">'+MWF.xApplication.cms.ColumnManager.LP.dataName+':</td>'+
  75. ' <td class="editTableValue"><input type="text" value="" class="editTableInput" style="width:90%;"/></td>'+
  76. // ' </tr>'+
  77. // ' <tr>'+
  78. ' <td class="editTableTitle">'+MWF.xApplication.cms.ColumnManager.LP.dataPath+':</td>'+
  79. ' <td class="editTableValue"><input type="text" value="" class="editTableInput" style="width:90%;"/></td>'+
  80. // '</tr>'+
  81. // '<tr>'+
  82. ' <td class="editTableTitle">'+MWF.xApplication.cms.ColumnManager.LP.dataType+':</td>'+
  83. ' <td class="editTableValue"><select>'+
  84. ' <option value="string">string</option>'+
  85. ' <option value="long">long</option>'+
  86. ' <option value="double">double</option>'+
  87. ' <option value="dateTime">dateTime</option>'+
  88. ' </select></td>'+
  89. ' </tr>'+
  90. ' </table>'+
  91. ' <div></div>'+
  92. ' <div></div>'+
  93. '<div>';
  94. return html;
  95. },
  96. runProjection: function(){
  97. o2.Actions.load("x_cms_assemble_control").CategoryInfoAction.executeProjection(this.options.category, null, function(json){
  98. if (json.data.value){
  99. o2.xDesktop.notice("success", {x: "right", y:"top"}, MWF.xApplication.cms.ColumnManager.LP.projectionRunSuccess, this.node);
  100. }else{
  101. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.cms.ColumnManager.LP.projectionRunError, this.node);
  102. }
  103. });
  104. },
  105. changeProjectionItem: function(){
  106. if (this.currentItem) {
  107. this.modifyProjectionItem();
  108. }else{
  109. this.addProjectionItem();
  110. }
  111. },
  112. checkItemData: function(name, path, type, operation){
  113. if (!name || !path){
  114. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.cms.ColumnManager.LP.projectionInputError, this.node);
  115. return false;
  116. }
  117. var count = 0;
  118. for (var i=0; i<this.data.length; i++){
  119. if (this.data[i].type===type) count++;
  120. var flag = false;
  121. if( operation === "add" && count>=this.options.maxTypeCount[type] ){
  122. flag = true;
  123. }
  124. if( operation === "modify" && count>this.options.maxTypeCount[type] ){
  125. flag = true;
  126. }
  127. if (flag){
  128. var txt = MWF.xApplication.cms.ColumnManager.LP.projectionTypeCountError;
  129. txt = txt.replace(/{type}/g, type);
  130. txt = txt.replace(/{count}/g, this.options.maxTypeCount[type]);
  131. o2.xDesktop.notice("error", {x: "right", y:"top"}, txt, this.node);
  132. return false;
  133. }
  134. if (this.data[i].name===name && (!this.currentItem || this.data[i]!=this.currentItem.data)) {
  135. o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.cms.ColumnManager.LP.projectionSameNameError, this.node);
  136. return false;
  137. }
  138. }
  139. return true;
  140. },
  141. checkItemColumn: function(){
  142. var columnNames = {
  143. "string": 0,
  144. "long": 0,
  145. "double": 0,
  146. "boolean": 0,
  147. "date":0,
  148. "time": 0,
  149. "dateTime": 0
  150. };
  151. var rows = this.table.rows;
  152. for (var i=0; i<this.data.length; i++){
  153. columnNames[this.data[i].type]++;
  154. var n = columnNames[this.data[i].type] || 1;
  155. var c = this.data[i].type+"Value"+(n>=10 ? n : "0"+n);
  156. rows[i+1].cells[3].set("text", c);
  157. }
  158. },
  159. modifyProjectionItem: function(){
  160. var name = this.nameInput.get("value");
  161. var path = this.pathInput.get("value");
  162. var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
  163. if (this.checkItemData(name, path, type, "modify")){
  164. this.currentItem.data.name = name;
  165. this.currentItem.data.path = path;
  166. this.currentItem.data.type = type;
  167. this.currentItem.refresh();
  168. this.currentItem.unSelected();
  169. this.checkItemColumn();
  170. this.fireEvent("change");
  171. this.fireEvent("modifyItem");
  172. }
  173. },
  174. addProjectionItem: function(){
  175. var name = this.nameInput.get("value");
  176. var path = this.pathInput.get("value");
  177. var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
  178. if (this.checkItemData(name, path, type, "add")){
  179. var o = { "name": name, "path": path, "type": type };
  180. this.data.push(o);
  181. new MWF.xApplication.cms.ColumnManager.widget.ProjectionEditor.Item(o, this);
  182. this.checkItemColumn();
  183. this.fireEvent("change");
  184. this.fireEvent("addItem");
  185. }
  186. },
  187. loadProjectionList: function(){
  188. this.data.each(function(d, i){
  189. new MWF.xApplication.cms.ColumnManager.widget.ProjectionEditor.Item(d, this);
  190. }.bind(this));
  191. this.checkItemColumn();
  192. }
  193. });
  194. MWF.xApplication.cms.ColumnManager.widget.ProjectionEditor.Item = new Class({
  195. initialize: function(data, editor){
  196. this.editor = editor;
  197. this.data = data;
  198. this.table = this.editor.table;
  199. this.css = this.editor.css;
  200. this.load();
  201. },
  202. load: function(){
  203. this.tr = new Element('tr').inject(this.table);
  204. var td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.name);
  205. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.path);
  206. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.type);
  207. td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.type);
  208. td = this.tr.insertCell().setStyles(this.css.projectionTableTd);
  209. this.delAction = new Element("div", {"styles": this.css.projectionItemAction}).inject(td);
  210. this.setEvent();
  211. },
  212. setEvent: function(){
  213. this.delAction.addEvent("click", function(e){
  214. var txt = MWF.xApplication.cms.ColumnManager.LP.projectionDeleteItem;
  215. txt = txt.replace(/{name}/g, this.data.name);
  216. txt = txt.replace(/{path}/g, this.data.path);
  217. var _self = this;
  218. MWF.xDesktop.confirm("infor", e, MWF.xApplication.cms.ColumnManager.LP.projectionDeleteItemTitle, txt, 300, 120, function(){
  219. _self.destroy();
  220. this.close();
  221. }, function(){
  222. this.close();
  223. }, null, null, "o2");
  224. }.bind(this));
  225. this.tr.addEvents({
  226. "click": function(){
  227. if (this.editor.currentItem) this.editor.currentItem.unSelected();
  228. this.selected();
  229. }.bind(this)
  230. })
  231. },
  232. selected: function(){
  233. this.editor.currentItem = this;
  234. this.tr.setStyles(this.css.projectionTableTr_selected);
  235. this.editor.nameInput.set("value", this.data.name);
  236. this.editor.pathInput.set("value", this.data.path);
  237. var ops = this.editor.typeSelect.options;
  238. for (var i=0; i<ops.length; i++){
  239. if (ops[i].value===this.data.type){
  240. ops[i].set("selected", true);
  241. break;
  242. }
  243. }
  244. this.editor.actionNode.set("text", "↓ "+MWF.xApplication.cms.ColumnManager.LP.projectionActionNode_modify);
  245. },
  246. unSelected: function(){
  247. this.editor.currentItem = null;
  248. this.tr.setStyles(this.css.projectionTableTr);
  249. this.editor.actionNode.set("text", "↓ "+MWF.xApplication.cms.ColumnManager.LP.projectionActionNode_add);
  250. },
  251. refresh: function(){
  252. var tds = this.tr.getElements("td");
  253. tds[0].set("text", this.data.name);
  254. tds[1].set("text", this.data.path);
  255. tds[2].set("text", this.data.type);
  256. },
  257. destroy: function(){
  258. if( this.editor.currentItem === this ){
  259. this.unSelected();
  260. }
  261. this.tr.destroy();
  262. this.editor.data.erase(this.data);
  263. this.editor.checkItemColumn();
  264. this.editor.fireEvent("change");
  265. this.editor.fireEvent("deleteItem");
  266. o2.release(this);
  267. }
  268. });