ActionsEditor.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
  2. MWF.require("MWF.widget.ScriptArea", null, false);
  3. MWF.xApplication.process.FormDesigner.widget.ActionsEditor = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default",
  8. "maxObj": document.body,
  9. "noCreate": false,
  10. "noDelete": false,
  11. "noCode": false,
  12. "noHide": false
  13. },
  14. initialize: function(node, designer, module, options){
  15. this.setOptions(options);
  16. this.node = $(node);
  17. this.module = module;
  18. this.designer = designer;
  19. this.path = "/x_component_process_FormDesigner/widget/$ActionsEditor/";
  20. this.cssPath = "/x_component_process_FormDesigner/widget/$ActionsEditor/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.actions = [];
  23. this.currentEditItem = null;
  24. this.createActionsAreaNode();
  25. },
  26. createActionsAreaNode: function(){
  27. this.actionsContainer = new Element("div", {
  28. "styles": this.css.actionsContainer
  29. }).inject(this.node);
  30. // var size = this.node.getUsefulSize();
  31. // this.eventsContainer.setStyle("height", size.y);
  32. },
  33. load: function(data){
  34. this.loadActionsArea();
  35. if (!this.options.noCreate) this.loadCreateActionButton();
  36. this.data = data;
  37. if (this.data){
  38. if (typeOf(this.data)!="array") this.data = [];
  39. this.data.each(function(actionData, idx){
  40. if (actionData.type!="MWFToolBarSeparator"){
  41. var action = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor.ButtonAction(this);
  42. action.load(actionData);
  43. this.actions.push(action);
  44. }
  45. }.bind(this));
  46. }
  47. },
  48. loadActionsArea: function(){
  49. if (!this.options.noCreate){
  50. this.actionTitleArea = new Element("div", {
  51. "styles": this.css.actionTitleArea
  52. }).inject(this.actionsContainer);
  53. }
  54. this.actionArea = new Element("div", {
  55. "styles": this.css.actionArea
  56. }).inject(this.actionsContainer);
  57. },
  58. loadCreateActionButton: function(){
  59. this.createActionButtonButton = new Element("div", {
  60. "styles": this.css.createActionButton,
  61. "text": "+"
  62. }).inject(this.actionTitleArea);
  63. this.createActionButtonButton.addEvent("click", function(){
  64. this.addButtonAction();
  65. }.bind(this));
  66. },
  67. addButtonAction: function(){
  68. var o = {
  69. "type": "MWFToolBarButton",
  70. "img": "4.png",
  71. "title": "",
  72. "action": "",
  73. "text": "Unnamed",
  74. "actionScript" : "",
  75. "condition": "",
  76. "editShow": true,
  77. "readShow": true
  78. };
  79. var action = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor.ButtonAction(this);
  80. action.load(o);
  81. this.data.push(o);
  82. this.actions.push(action);
  83. this.fireEvent("change");
  84. }
  85. });
  86. MWF.xApplication.process.FormDesigner.widget.ActionsEditor.ButtonAction = new Class({
  87. initialize: function (editor) {
  88. this.editor = editor;
  89. this.css = this.editor.css;
  90. this.container = this.editor.actionArea
  91. },
  92. load: function (data) {
  93. this.data = data;
  94. this.loadNode();
  95. var form = this.editor.designer.form || this.editor.designer.page;
  96. if (form.scriptDesigner){
  97. this.scriptItem = form.scriptDesigner.addScriptItem(this.data, "actionScript", this.editor.module, "action.tools", this.data.text);
  98. }
  99. var text = this.data.text;
  100. Object.defineProperty(this.data, "text", {
  101. configurable : true,
  102. enumerable : true,
  103. "get": function(){return text;},
  104. "set": function(v){
  105. if (this.scriptItem){
  106. this.scriptItem.par = v;
  107. this.scriptItem.resetText();
  108. }
  109. text = v;
  110. }.bind(this)
  111. });
  112. },
  113. loadNode: function () {
  114. this.node = new Element("div", {"styles": this.css.actionNode}).inject(this.container);
  115. this.titleNode = new Element("div", {"styles": this.css.actionTitleNode}).inject(this.node);
  116. this.iconNode = new Element("div", {"styles": this.css.actionIconNode}).inject(this.titleNode);
  117. this.textNode = new Element("div", {"styles": this.css.actionTextNode, "text": this.data.text}).inject(this.titleNode);
  118. if (!this.editor.options.noDelete) this.delButton = new Element("div", {"styles": this.css.actionDelButtonNode, "text": "-"}).inject(this.titleNode);
  119. this.conditionButton = new Element("div", {"styles": this.css.actionConditionButtonNode, "title": this.editor.designer.lp.actionbar.hideCondition}).inject(this.titleNode);
  120. if (this.data.condition){
  121. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code.png)");
  122. }else{
  123. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code_empty.png)");
  124. }
  125. if (!this.editor.options.noEditShow){
  126. this.editButton = new Element("div", {"styles": this.css.actionEditButtonNode, "title": this.editor.designer.lp.actionbar.edithide}).inject(this.titleNode);
  127. if (this.data.editShow){
  128. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit.png)");
  129. }else{
  130. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit_hide.png)");
  131. }
  132. }
  133. if (!this.editor.options.noReadShow){
  134. this.readButton = new Element("div", {"styles": this.css.actionReadButtonNode, "title": this.editor.designer.lp.actionbar.readhide}).inject(this.titleNode);
  135. if (this.data.readShow){
  136. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read.png)");
  137. }else{
  138. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read_hide.png)");
  139. }
  140. }
  141. var icon = this.editor.path+this.editor.options.style+"/tools/"+this.data.img;
  142. this.iconNode.setStyle("background-image", "url("+icon+")");
  143. if (!this.editor.options.noCode){
  144. this.scriptNode = new Element("div", {"styles": this.css.actionScriptNode}).inject(this.node);
  145. this.scriptArea = new MWF.widget.ScriptArea(this.scriptNode, {
  146. "title": this.editor.designer.lp.actionbar.editScript,
  147. "maxObj": this.editor.designer.formContentNode,
  148. "key": "actionScript",
  149. "onChange": function(){
  150. this.data.actionScript = this.scriptArea.editor.getValue();
  151. this.editor.fireEvent("change");
  152. }.bind(this),
  153. "onSave": function(){
  154. this.data.actionScript = this.scriptArea.editor.getValue();
  155. this.editor.fireEvent("change");
  156. this.editor.designer.saveForm();
  157. }.bind(this),
  158. "onPostLoad": function(){
  159. // this.scriptNode.setStyle("display", "none");
  160. }.bind(this)
  161. });
  162. this.scriptArea.load({"code": this.data.actionScript});
  163. }
  164. this.conditionNode = new Element("div", {"styles": this.css.actionScriptNode}).inject(this.node);
  165. this.conditionArea = new MWF.widget.ScriptArea(this.conditionNode, {
  166. "title": this.editor.designer.lp.actionbar.editCondition,
  167. "maxObj": this.editor.designer.formContentNode,
  168. "onChange": function(){
  169. this.data.condition = this.conditionArea.editor.getValue();
  170. if (this.data.condition){
  171. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code.png)");
  172. }else{
  173. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code_empty.png)");
  174. }
  175. this.editor.fireEvent("change");
  176. }.bind(this),
  177. "onSave": function(){
  178. this.data.condition = this.conditionArea.editor.getValue();
  179. this.editor.fireEvent("change");
  180. this.editor.designer.saveForm();
  181. }.bind(this),
  182. "onPostLoad": function(){
  183. // this.conditionNode.setStyle("display", "none");
  184. }.bind(this)
  185. });
  186. this.conditionArea.load({"code": this.data.condition});
  187. this.setEvent();
  188. //this.loadEditNode();
  189. //this.loadChildNode();
  190. //this.setTitleNode();
  191. //this.setEditNode();
  192. },
  193. setEvent: function(){
  194. this.iconMenu = new MWF.widget.Menu(this.iconNode, {"event": "click", "style": "actionbarIcon"});
  195. this.iconMenu.load();
  196. var _self = this;
  197. for (var i=1; i<=121; i++){
  198. var icon = this.editor.path+this.editor.options.style+"/tools/"+i+".png";
  199. var item = this.iconMenu.addMenuItem("", "click", function(){
  200. var src = this.item.getElement("img").get("src");
  201. _self.data.img = src.substr(src.lastIndexOf("/")+1, src.length);
  202. _self.iconNode.setStyle("background-image", "url("+src+")");
  203. _self.editor.fireEvent("change");
  204. }, icon);
  205. item.iconName = i+".png";
  206. }
  207. this.textNode.addEvent("click", function(e){
  208. this.textNode.empty();
  209. var editTitleNode = new Element("input", {"styles": this.css.actionEditTextNode, "type": "text", "value": this.data.text}).inject(this.textNode);
  210. editTitleNode.focus();
  211. editTitleNode.select();
  212. var _self = this;
  213. editTitleNode.addEvent("blur", function(){_self.editTitleComplete(this);});
  214. editTitleNode.addEvent("keydown:keys(enter)", function(){_self.editTitleComplete(this);});
  215. editTitleNode.addEvent("click", function(e){e.stopPropagation()});
  216. e.stopPropagation();
  217. }.bind(this));
  218. this.conditionButton.addEvent("click", function(e){
  219. e.stopPropagation();
  220. this.editCondition();
  221. }.bind(this));
  222. if (this.editButton) this.editButton.addEvent("click", function(e){
  223. if (this.data.editShow){
  224. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit_hide.png)");
  225. this.data.editShow = false;
  226. }else{
  227. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit.png)");
  228. this.data.editShow = true;
  229. }
  230. this.editor.fireEvent("change");
  231. e.stopPropagation();
  232. }.bind(this));
  233. if (this.readButton) this.readButton.addEvent("click", function(e){
  234. if (this.data.readShow){
  235. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read_hide.png)");
  236. this.data.readShow = false;
  237. }else{
  238. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read.png)");
  239. this.data.readShow = true;
  240. }
  241. this.editor.fireEvent("change");
  242. e.stopPropagation();
  243. }.bind(this));
  244. this.titleNode.addEvent("click", function(){
  245. if (this.scriptNode){
  246. var dis = this.scriptNode.getStyle("display");
  247. if (dis=="none"){
  248. this.scriptNode.setStyle("display", "block");
  249. if (this.scriptArea){
  250. this.scriptArea.resizeContentNodeSize();
  251. if (this.scriptArea.editor) this.scriptArea.editor.resize();
  252. if (!this.scriptArea.jsEditor){
  253. this.scriptArea.contentNode.empty();
  254. this.scriptArea.loadEditor({"code": this.data.actionScript});
  255. }
  256. }
  257. }else{
  258. this.scriptNode.setStyle("display", "none");
  259. }
  260. }
  261. }.bind(this));
  262. if (this.delButton) this.delButton.addEvent("click", function(e){
  263. var _self = this;
  264. this.editor.designer.confirm("warn", this.delButton, MWF.APPFD.LP.notice.deleteButtonTitle, MWF.APPFD.LP.notice.deleteButton, 300, 120, function(){
  265. _self.destroy();
  266. this.close();
  267. }, function(){
  268. this.close();
  269. }, null);
  270. e.stopPropagation();
  271. }.bind(this));
  272. },
  273. editCondition: function(){
  274. var dis = this.conditionNode.getStyle("display");
  275. if (dis=="none"){
  276. this.conditionNode.setStyle("display", "block");
  277. if (this.conditionArea){
  278. this.conditionArea.resizeContentNodeSize();
  279. if (this.conditionArea.editor) this.conditionArea.editor.resize();
  280. if (!this.conditionArea.jsEditor){
  281. this.conditionArea.contentNode.empty();
  282. this.conditionArea.loadEditor({"code": this.data.condition});
  283. }
  284. }
  285. }else{
  286. this.conditionNode.setStyle("display", "none");
  287. }
  288. },
  289. destroy: function(){
  290. this.editor.data.erase(this.data);
  291. this.editor.actions.erase(this);
  292. this.editor.fireEvent("change");
  293. this.node.destroy();
  294. var form = this.editor.designer.form || this.editor.designer.page;
  295. if (form.scriptDesigner){
  296. form.scriptDesigner.deleteScriptItem(this.editor.module, "action.tools", this.data.text);
  297. }
  298. MWF.release(this.scriptArea);
  299. MWF.release(this);
  300. },
  301. editTitleComplete: function(el){
  302. this.data.text = el.get("value");
  303. this.data.title = el.get("value");
  304. el.destroy();
  305. this.textNode.empty();
  306. this.textNode.set("text", this.data.text);
  307. this.editor.fireEvent("change");
  308. }
  309. });