ElDropdownItemEditor.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. // o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Common", null, false);
  3. // o2.require("o2.widget.Tree", null, false);
  4. o2.requireApp("process.FormDesigner", "widget.ElTreeEditor", null, false);
  5. MWF.xApplication.process.FormDesigner.widget.ElDropdownItemEditor = new Class({
  6. Extends: MWF.xApplication.process.FormDesigner.widget.ElTreeEditor,
  7. createContent: function(content){
  8. this.contentNode = new Element("div", {
  9. "styles": this.css.contentNode
  10. }).inject(this.container);
  11. this.data = content;
  12. this.resizeContentNodeSize();
  13. this.tree = new MWF.xApplication.process.FormDesigner.widget.ElDropdownItemEditor.Tree(this, this.contentNode, {"style": "editor"});
  14. this.tree.data = this.data;
  15. this.tree.load();
  16. }
  17. });
  18. MWF.xApplication.process.FormDesigner.widget.ElDropdownItemEditor.Tree = new Class({
  19. Extends: MWF.xApplication.process.FormDesigner.widget.ElTreeEditor.Tree,
  20. nodejson: {
  21. "label": "[none]",
  22. "command": "",
  23. "disabled": false,
  24. "divided": false,
  25. "icon":""
  26. },
  27. appendChild: function(obj){
  28. var treeNode = new MWF.xApplication.process.FormDesigner.widget.ElDropdownItemEditor.Tree.Node(this, obj);
  29. if (this.children.length){
  30. treeNode.previousSibling = this.children[this.children.length-1];
  31. treeNode.previousSibling.nextSibling = treeNode;
  32. }else{
  33. this.firstChild = treeNode;
  34. }
  35. treeNode.level = 0;
  36. treeNode.load();
  37. treeNode.node.inject(this.node);
  38. this.children.push(treeNode);
  39. return treeNode;
  40. }
  41. });
  42. MWF.xApplication.process.FormDesigner.widget.ElDropdownItemEditor.Tree.Node = new Class({
  43. Extends: MWF.xApplication.process.FormDesigner.widget.ElTreeEditor.Tree.Node,
  44. options: {
  45. "expand": true
  46. },
  47. createItemActionNode: function(){
  48. this.actionNode = new Element("div", {
  49. "styles": this.tree.css.itemActionNode
  50. }).inject(this.itemNode);
  51. var deleteAction = new Element("div", {
  52. "styles": this.tree.css.itemDeleteActionNode,
  53. "title": o2.LP.process.formAction["delete"],
  54. "events": {
  55. "click": function(e){
  56. this.deleteItem(e);
  57. e.stopPropagation();
  58. }.bind(this)
  59. }
  60. }).inject(this.actionNode);
  61. },
  62. editItemProperties: function(){
  63. if (this.tree.currentEditNode!=this){
  64. if (this.tree.currentEditNode) this.tree.currentEditNode.completeItemProperties();
  65. this.itemNode.setStyle("background", "#DDD");
  66. if (!this.propertyArea){
  67. this.propertyArea = new Element("div", {
  68. style : "border-bottom:1px solid #666"
  69. }).inject(this.itemNode, "after");
  70. this.propertyTable = new Element("table", {
  71. "width": "100%",
  72. "border": "0",
  73. "cellpadding":"5",
  74. "cellspacing":"0",
  75. "class": "editTable"
  76. }).inject(this.propertyArea);
  77. var tr = new Element("tr").inject(this.propertyTable);
  78. var td = new Element("td", { text: "文本" }).inject(tr);
  79. td = new Element("td").inject(tr);
  80. this.labelInput = new Element("input", {
  81. value: this.data.label || "[none]",
  82. events: {
  83. blur: function () {
  84. this.data.label = this.labelInput.get("value");
  85. this.textNode.getElement("div").set("text", this.data.label);
  86. this.tree.editor.fireEvent("change", [{
  87. compareName: "."+this.getLevelName() + ".label"
  88. }]);
  89. }.bind(this)
  90. }
  91. }).inject(td);
  92. tr = new Element("tr").inject(this.propertyTable);
  93. td = new Element("td", { text: "指令" }).inject(tr);
  94. td = new Element("td").inject(tr);
  95. this.idCommand = new Element("input", {
  96. value: this.data.command || "",
  97. events: {
  98. blur: function () {
  99. this.data.command = this.idCommand.get("value");
  100. this.tree.editor.fireEvent("change", [{
  101. compareName: "."+this.getLevelName() + ".command"
  102. }]);
  103. }.bind(this)
  104. }
  105. }).inject(td);
  106. tr = new Element("tr").inject(this.propertyTable);
  107. td = new Element("td", { text: "禁用" }).inject(tr);
  108. td = new Element("td").inject(tr);
  109. var div = new Element( "div").inject(td);
  110. var radio_disabled_1 = new Element( "input", {
  111. "type" : "radio",
  112. "checked" : !!this.data.disabled,
  113. "events" : {
  114. "click": function () {
  115. this.data.disabled = true;
  116. radio_disabled_2.checked = false;
  117. this.tree.editor.fireEvent("change", [{
  118. compareName: "."+this.getLevelName() + ".disabled"
  119. }]);
  120. }.bind(this)
  121. }
  122. }).inject( div );
  123. new Element( "span", { "text" : "是" }).inject(div);
  124. var radio_disabled_2 = new Element( "input", {
  125. "type" : "radio",
  126. "checked" : !this.data.disabled,
  127. "events" : {
  128. "click": function () {
  129. this.data.disabled = false;
  130. radio_disabled_1.checked = false;
  131. this.tree.editor.fireEvent("change", [{
  132. compareName: "."+this.getLevelName() + ".disabled"
  133. }]);
  134. }.bind(this)
  135. }
  136. }).inject( div );
  137. new Element( "span", { "text" : "否" }).inject(div);
  138. tr = new Element("tr").inject(this.propertyTable);
  139. td = new Element("td", { text: "显示分割线" }).inject(tr);
  140. td = new Element("td").inject(tr);
  141. div = new Element( "div").inject(td);
  142. var radio_divided_1 = new Element( "input", {
  143. "type" : "radio",
  144. "checked" : !!this.data.divided,
  145. "events" : {
  146. "click": function(){
  147. this.data.divided = true;
  148. radio_divided_2.checked = false;
  149. this.tree.editor.fireEvent("change", [{
  150. compareName: "."+this.getLevelName() + ".divided"
  151. }]);
  152. }.bind(this)
  153. }
  154. }).inject( div );
  155. new Element( "span", { "text" : "是" }).inject(div);
  156. var radio_divided_2 = new Element( "input", {
  157. "type" : "radio",
  158. "checked" : !this.data.divided,
  159. "events" : {
  160. "click": function () {
  161. this.data.divided = false;
  162. radio_divided_1.checked = false;
  163. this.tree.editor.fireEvent("change", [{
  164. compareName: "."+this.getLevelName() + ".divided"
  165. }]);
  166. }.bind(this)
  167. }
  168. }).inject( div );
  169. new Element( "span", { "text" : "否" }).inject(div);
  170. tr = new Element("tr").inject(this.propertyTable);
  171. td = new Element("td", { text: "图标" }).inject(tr);
  172. td = new Element("td").inject(tr);
  173. var div = new Element("div", {
  174. style: "overflow:hidden;height:30px;line-height:30px;"
  175. }).inject(td);
  176. this.iconNode = new Element("div",{
  177. class : this.data.icon,
  178. style: "float:left; width:30px;height:30px;font-size:20px;margin-top:2px;"
  179. }).inject(div);
  180. new Element("div",{
  181. text : "选择图标",
  182. style: "float:left; padding:0px 20px; height:24px;line-height:24px; border:1px solid #ccc; border-radius:5px;cursor:pointer",
  183. events: {
  184. click: this.loadElSelectIcon.bind(this)
  185. }
  186. }).inject(div);
  187. }
  188. this.propertyArea.setStyle("display", "block");
  189. this.propertyArea.scrollIntoView(false);
  190. this.setActionPosition();
  191. this.isEditProperty = true;
  192. this.tree.currentEditNode = this;
  193. }else{
  194. this.completeItemProperties();
  195. }
  196. },
  197. _loadVue: function(callback){
  198. if (!window.Vue){
  199. o2.loadAll({"css": "../o2_lib/vue/element/index.css", "js": ["vue", "elementui"]}, { "sequence": true }, callback);
  200. }else{
  201. if (callback) callback();
  202. }
  203. },
  204. loadElSelectIcon: function(){
  205. var _self = this;
  206. var icons = ["el-icon-platform-eleme","el-icon-eleme","el-icon-delete-solid","el-icon-delete","el-icon-s-tools","el-icon-setting","el-icon-user-solid","el-icon-user","el-icon-phone","el-icon-phone-outline","el-icon-more","el-icon-more-outline","el-icon-star-on","el-icon-star-off","el-icon-s-goods","el-icon-goods","el-icon-warning","el-icon-warning-outline","el-icon-question","el-icon-info","el-icon-remove","el-icon-circle-plus","el-icon-success","el-icon-error","el-icon-zoom-in","el-icon-zoom-out","el-icon-remove-outline","el-icon-circle-plus-outline","el-icon-circle-check","el-icon-circle-close","el-icon-s-help","el-icon-help","el-icon-minus","el-icon-plus","el-icon-check","el-icon-close","el-icon-picture","el-icon-picture-outline","el-icon-picture-outline-round","el-icon-upload","el-icon-upload2","el-icon-download","el-icon-camera-solid","el-icon-camera","el-icon-video-camera-solid","el-icon-video-camera","el-icon-message-solid","el-icon-bell","el-icon-s-cooperation","el-icon-s-order","el-icon-s-platform","el-icon-s-fold","el-icon-s-unfold","el-icon-s-operation","el-icon-s-promotion","el-icon-s-home","el-icon-s-release","el-icon-s-ticket","el-icon-s-management","el-icon-s-open","el-icon-s-shop","el-icon-s-marketing","el-icon-s-flag","el-icon-s-comment","el-icon-s-finance","el-icon-s-claim","el-icon-s-custom","el-icon-s-opportunity","el-icon-s-data","el-icon-s-check","el-icon-s-grid","el-icon-menu","el-icon-share","el-icon-d-caret","el-icon-caret-left","el-icon-caret-right","el-icon-caret-bottom","el-icon-caret-top","el-icon-bottom-left","el-icon-bottom-right","el-icon-back","el-icon-right","el-icon-bottom","el-icon-top","el-icon-top-left","el-icon-top-right","el-icon-arrow-left","el-icon-arrow-right","el-icon-arrow-down","el-icon-arrow-up","el-icon-d-arrow-left","el-icon-d-arrow-right","el-icon-video-pause","el-icon-video-play","el-icon-refresh","el-icon-refresh-right","el-icon-refresh-left","el-icon-finished","el-icon-sort","el-icon-sort-up","el-icon-sort-down","el-icon-rank","el-icon-loading","el-icon-view","el-icon-c-scale-to-original","el-icon-date","el-icon-edit","el-icon-edit-outline","el-icon-folder","el-icon-folder-opened","el-icon-folder-add","el-icon-folder-remove","el-icon-folder-delete","el-icon-folder-checked","el-icon-tickets","el-icon-document-remove","el-icon-document-delete","el-icon-document-copy","el-icon-document-checked","el-icon-document","el-icon-document-add","el-icon-printer","el-icon-paperclip","el-icon-takeaway-box","el-icon-search","el-icon-monitor","el-icon-attract","el-icon-mobile","el-icon-scissors","el-icon-umbrella","el-icon-headset","el-icon-brush","el-icon-mouse","el-icon-coordinate","el-icon-magic-stick","el-icon-reading","el-icon-data-line","el-icon-data-board","el-icon-pie-chart","el-icon-data-analysis","el-icon-collection-tag","el-icon-film","el-icon-suitcase","el-icon-suitcase-1","el-icon-receiving","el-icon-collection","el-icon-files","el-icon-notebook-1","el-icon-notebook-2","el-icon-toilet-paper","el-icon-office-building","el-icon-school","el-icon-table-lamp","el-icon-house","el-icon-no-smoking","el-icon-smoking","el-icon-shopping-cart-full","el-icon-shopping-cart-1","el-icon-shopping-cart-2","el-icon-shopping-bag-1","el-icon-shopping-bag-2","el-icon-sold-out","el-icon-sell","el-icon-present","el-icon-box","el-icon-bank-card","el-icon-money","el-icon-coin","el-icon-wallet","el-icon-discount","el-icon-price-tag","el-icon-news","el-icon-guide","el-icon-male","el-icon-female","el-icon-thumb","el-icon-cpu","el-icon-link","el-icon-connection","el-icon-open","el-icon-turn-off","el-icon-set-up","el-icon-chat-round","el-icon-chat-line-round","el-icon-chat-square","el-icon-chat-dot-round","el-icon-chat-dot-square","el-icon-chat-line-square","el-icon-message","el-icon-postcard","el-icon-position","el-icon-turn-off-microphone","el-icon-microphone","el-icon-close-notification","el-icon-bangzhu","el-icon-time","el-icon-odometer","el-icon-crop","el-icon-aim","el-icon-switch-button","el-icon-full-screen","el-icon-copy-document","el-icon-mic","el-icon-stopwatch","el-icon-medal-1","el-icon-medal","el-icon-trophy","el-icon-trophy-1","el-icon-first-aid-kit","el-icon-discover","el-icon-place","el-icon-location","el-icon-location-outline","el-icon-location-information","el-icon-add-location","el-icon-delete-location","el-icon-map-location","el-icon-alarm-clock","el-icon-timer","el-icon-watch-1","el-icon-watch","el-icon-lock","el-icon-unlock","el-icon-key","el-icon-service","el-icon-mobile-phone","el-icon-bicycle","el-icon-truck","el-icon-ship","el-icon-basketball","el-icon-football","el-icon-soccer","el-icon-baseball","el-icon-wind-power","el-icon-light-rain","el-icon-lightning","el-icon-heavy-rain","el-icon-sunrise","el-icon-sunrise-1","el-icon-sunset","el-icon-sunny","el-icon-cloudy","el-icon-partly-cloudy","el-icon-cloudy-and-sunny","el-icon-moon","el-icon-moon-night","el-icon-dish","el-icon-dish-1","el-icon-food","el-icon-chicken","el-icon-fork-spoon","el-icon-knife-fork","el-icon-burger","el-icon-tableware","el-icon-sugar","el-icon-dessert","el-icon-ice-cream","el-icon-hot-water","el-icon-water-cup","el-icon-coffee-cup","el-icon-cold-drink","el-icon-goblet","el-icon-goblet-full","el-icon-goblet-square","el-icon-goblet-square-full","el-icon-refrigerator","el-icon-grape","el-icon-watermelon","el-icon-cherry","el-icon-apple","el-icon-pear","el-icon-orange","el-icon-coffee","el-icon-ice-tea","el-icon-ice-drink","el-icon-milk-tea","el-icon-potato-strips","el-icon-lollipop","el-icon-ice-cream-square","el-icon-ice-cream-round"];
  207. var area = new Element("div", {
  208. "styles": {
  209. "height": "390px",
  210. "overflow": "auto",
  211. "font-size": "24px",
  212. "opacity": 0
  213. }
  214. }).inject($(document.body));
  215. icons.forEach(function(i){
  216. if (_self.data.icon==i){
  217. area.appendHTML("<i style=\"background-color: #999999; padding:5px}\" @click='selected' data-icon=\""+i+"\" class=\""+i+" mainColor_bg\"></i>");
  218. }else{
  219. area.appendHTML("<i style='cursor: pointer; padding:5px' @click='selected' data-icon=\""+i+"\" class='"+i+"'></i>");
  220. }
  221. });
  222. var dlg = o2.DL.open({
  223. "title": "选择图标",
  224. "isTitle": true,
  225. "width": 400,
  226. "height": 500,
  227. "content": area,
  228. "buttonList": [
  229. {
  230. "type": "ok",
  231. "text": "关闭",
  232. "action": function(){this.close();}
  233. }
  234. ],
  235. "onPostLoad": function () {
  236. area.setStyle("opacity", 1);
  237. this._loadVue(function(){
  238. new Vue({
  239. methods:{
  240. selected: function(e){
  241. var iNode = (e.target || e.srcElement);
  242. if (iNode && iNode.hasClass("mainColor_bg")){
  243. iNode.removeClass("mainColor_bg");
  244. _self.iconNode.removeClass(_self.data.icon);
  245. _self.data.icon = "";
  246. _self.tree.editor.fireEvent("change", [{
  247. compareName: "."+_self.getLevelName() + ".icon"
  248. }]);
  249. dlg.close()
  250. }else{
  251. this.$el.getElements("i").forEach(function(el){
  252. if (el.hasClass("mainColor_bg")) el.removeClass("mainColor_bg");
  253. });
  254. if (iNode){
  255. iNode.addClass("mainColor_bg");
  256. var iconName = iNode.dataset["icon"];
  257. _self.iconNode.removeClass(_self.data.icon).addClass(iconName);
  258. _self.data.icon = iconName;
  259. _self.tree.editor.fireEvent("change", [{
  260. compareName: "."+_self.getLevelName() + ".icon"
  261. }]);
  262. dlg.close();
  263. }
  264. }
  265. }
  266. }
  267. }).$mount(area);
  268. }.bind(this));
  269. }.bind(this)
  270. })
  271. },
  272. editItem: function(node, okCallBack){
  273. var text = node.get("text");
  274. node.set("html", "");
  275. var div = new Element("div", {
  276. "styles": this.tree.css.editInputDiv,
  277. });
  278. var input = new Element("input", {
  279. "styles": this.tree.css.editInput,
  280. "type": "text",
  281. "value": text
  282. }).inject(div);
  283. var w = o2.getTextSize(text+"a").x;
  284. input.setStyle("width", w);
  285. div.setStyle("width", w);
  286. div.inject(node);
  287. input.select();
  288. input.addEvents({
  289. "keydown": function(e){
  290. var x = o2.getTextSize(input.get("value")+"a").x;
  291. e.target.setStyle("width", x);
  292. e.target.getParent().setStyle("width", x);
  293. if (e.code==13){
  294. this.isEnterKey = true;
  295. e.target.blur();
  296. }
  297. }.bind(this),
  298. "blur": function(e){
  299. var flag = this.editItemComplate(node, e.target);
  300. if (okCallBack) okCallBack(flag);
  301. }.bind(this),
  302. "click": function(e){
  303. e.stopPropagation();
  304. }.bind(this)
  305. });
  306. },
  307. editItemComplate: function(node, input){
  308. var text = input.get("value");
  309. // if (node == this.keyNode){
  310. if (!text){
  311. text = "[none]";
  312. }
  313. this.data.label = text;
  314. // }
  315. var addNewItem = false;
  316. if (this.isEnterKey){
  317. if (this.isNewItem){
  318. addNewItem = true;
  319. }
  320. this.editOkAddNewItem = false;
  321. }
  322. this.isNewItem = false;
  323. node.set("html", text);
  324. if( this.labelInput )this.labelInput.set("value", text);
  325. this.tree.editor.fireEvent("change", [{
  326. compareName: "."+this.getLevelName() + ".label"
  327. }]);
  328. return true;
  329. }
  330. });