ActionsEditor.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. MWF.xApplication.cms.FormDesigner.widget = MWF.xApplication.cms.FormDesigner.widget || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", null, false);
  3. MWF.xApplication.cms.FormDesigner.widget.ActionsEditor = new Class({
  4. Extends: MWF.xApplication.process.FormDesigner.widget.ActionsEditor,
  5. load: function(data){
  6. this.loadActionsArea();
  7. if (!this.options.noCreate) this.loadCreateActionButton();
  8. this.data = data;
  9. if ( !this.data || typeOf(this.data)!="array") this.data = [];
  10. this.loadRestoreActionButton();
  11. this.data.each(function(actionData, idx){
  12. var action = new MWF.xApplication.cms.FormDesigner.widget.ActionsEditor.ButtonAction(this);
  13. action.load(actionData);
  14. this.actions.push(action);
  15. }.bind(this));
  16. },
  17. listRemovedSystemTool : function(){
  18. var list = [];
  19. if( !this.defaultTools ){
  20. MWF.getJSON( "../x_component_cms_FormDesigner/Module/Actionbar/toolbars.json", function(tools){
  21. this.defaultTools = tools;
  22. }.bind(this), false);
  23. }
  24. this.defaultTools.each( function( tool ){
  25. var flag = true;
  26. for( var i=0; i<(this.data || []).length; i++ ){
  27. if( this.data[i].id === tool.id ){
  28. flag = false;
  29. break;
  30. }
  31. }
  32. if(flag)list.push(tool);
  33. }.bind(this));
  34. return list;
  35. },
  36. addButtonAction: function(){
  37. var o = {
  38. "type": "MWFToolBarButton",
  39. "img": "4.png",
  40. "title": "",
  41. "action": "",
  42. "text": "Unnamed",
  43. "actionScript" : "",
  44. "condition": "",
  45. "editShow": true,
  46. "readShow": true
  47. };
  48. var action = new MWF.xApplication.cms.FormDesigner.widget.ActionsEditor.ButtonAction(this);
  49. action.load(o);
  50. this.data.push(o);
  51. this.actions.push(action);
  52. this.fireEvent("change", [{
  53. compareName: " [addAction]",
  54. force: true
  55. }]);
  56. },
  57. restoreButtonAction : function(){
  58. var list = this.listRemovedSystemTool();
  59. if( !list.length )return;
  60. var selectableItems = [];
  61. list.each( function(d){
  62. var title = "";
  63. if( d.text && this.designer.lp.actionBar ){
  64. title = this.designer.lp.actionBar[ d.text.split(".").getLast().replace("}}","") ] || "";
  65. title = title ? (" (" + title + ")") : "";
  66. }
  67. selectableItems.push( {
  68. name : d.text + title,
  69. id : d.id
  70. })
  71. }.bind(this));
  72. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false);
  73. var opt = {
  74. "count": 0,
  75. "title": this.designer.lp.actionbar.selectDefaultTool,
  76. "selectableItems" : selectableItems,
  77. "values": [],
  78. "onComplete": function( array ){
  79. if( !array || array.length == 0 )return;
  80. var actionNameList = [];
  81. array.each( function(tool){
  82. for( var i=0; i<list.length; i++ ){
  83. if( list[i].id === tool.data.id ){
  84. list[i].system = true;
  85. this.data.push( list[i] );
  86. actionNameList.push( list[i].action );
  87. var action = new MWF.xApplication.cms.FormDesigner.widget.ActionsEditor.ButtonAction(this);
  88. action.load(list[i]);
  89. this.actions.push(action);
  90. break;
  91. }
  92. }
  93. }.bind(this));
  94. this.fireEvent("change", [{
  95. compareName: " [addSystemAction]:"+actionNameList,
  96. force: true
  97. }]);
  98. }.bind(this)
  99. };
  100. var selector = new MWF.xApplication.Template.Selector.Custom(this.options.maxObj, opt );
  101. selector.load();
  102. }
  103. });
  104. MWF.xApplication.cms.FormDesigner.widget.ActionsEditor.ButtonAction = new Class({
  105. Extends: MWF.xApplication.process.FormDesigner.widget.ActionsEditor.ButtonAction,
  106. loadNode: function () {
  107. this.node = new Element("div", {"styles": this.css.actionNode}).inject(this.container);
  108. this.titleNode = new Element("div", {"styles": this.css.actionTitleNode}).inject(this.node);
  109. this.iconNode = new Element("div", {"styles": this.css.actionIconNode}).inject(this.titleNode);
  110. this.textNode = new Element("div", {"styles": this.css.actionTextNode, "text": this.data.text}).inject(this.titleNode);
  111. if( this.data.text && this.editor.designer.lp.actionBar){
  112. var title = this.editor.designer.lp.actionBar[ this.data.text.split(".").getLast().replace("}}","") ] || "";
  113. this.textNode.set("title", title || "");
  114. }
  115. this.upButton = new Element("div", {"styles": this.css.actionUpButtonNode, "title": this.editor.designer.lp.actionbar.up}).inject(this.titleNode);
  116. this.propertiesButton = new Element("div", {"styles": this.css.actionPropertiesButtonNode, "title": this.editor.designer.lp.actionbar.property}).inject(this.titleNode);
  117. if (!this.data.properties || Object.keys(this.data.properties).length === 0 ){
  118. this.propertiesButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/property_empty.png)");
  119. }else{
  120. this.propertiesButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/property.png)");
  121. }
  122. this.propertiesNode = new Element("div", {"styles": this.css.actionScriptNode}).inject(this.node);
  123. this.propertiesArea = new MWF.widget.Maplist(this.propertiesNode, {
  124. "title": this.editor.designer.lp.actionbar.setProperties,
  125. "collapse": false,
  126. "onChange": function(){
  127. this.data.properties = this.propertiesArea.toJson();
  128. if (!this.data.properties || Object.keys(this.data.properties).length === 0 ){
  129. this.propertiesButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/property_empty.png)");
  130. }else{
  131. this.propertiesButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/property.png)");
  132. }
  133. this.editor.fireEvent("change", [{
  134. compareName: "."+this.getName() + ".property"
  135. }]);
  136. }.bind(this)
  137. });
  138. this.propertiesArea.load( this.data.properties || {});
  139. if (!this.editor.options.noDelete) this.delButton = new Element("div", {
  140. "styles": this.css.actionDelButtonNode,
  141. "text": "-",
  142. "title" : this.editor.designer.lp.actionbar.delete
  143. }).inject(this.titleNode);
  144. this.conditionButton = new Element("div", {"styles": this.css.actionConditionButtonNode, "title": this.editor.designer.lp.actionbar.hideCondition}).inject(this.titleNode);
  145. if (this.data.condition){
  146. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code.png)");
  147. }else{
  148. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code_empty.png)");
  149. }
  150. if (!this.editor.options.noEditShow && !this.data.system){
  151. this.editButton = new Element("div", {"styles": this.css.actionEditButtonNode, "title": this.editor.designer.lp.actionbar.edithide}).inject(this.titleNode);
  152. if (this.data.editShow){
  153. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit.png)");
  154. }else{
  155. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit_hide.png)");
  156. }
  157. }
  158. if (!this.editor.options.noReadShow && !this.data.system){
  159. this.readButton = new Element("div", {"styles": this.css.actionReadButtonNode, "title": this.editor.designer.lp.actionbar.readhide}).inject(this.titleNode);
  160. if (this.data.readShow){
  161. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read.png)");
  162. }else{
  163. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read_hide.png)");
  164. }
  165. }
  166. var icon = this.editor.path+this.editor.options.style+"/tools/"+this.data.img;
  167. this.iconNode.setStyle("background-image", "url("+icon+")");
  168. if (!this.editor.options.noCode && !this.data.system ) {
  169. this.scriptNode = new Element("div", {"styles": this.css.actionScriptNode}).inject(this.node);
  170. this.scriptArea = new MWF.widget.ScriptArea(this.scriptNode, {
  171. "title": this.editor.designer.lp.actionbar.editScript,
  172. "maxObj": this.editor.designer.formContentNode,
  173. "onChange": function () {
  174. this.data.actionScript = this.scriptArea.editor.getValue();
  175. this.editor.fireEvent("change", [{
  176. compareName: "."+this.getName() + ".actionScript"
  177. }]);
  178. }.bind(this),
  179. "onSave": function () {
  180. this.data.actionScript = this.scriptArea.editor.getValue();
  181. this.editor.fireEvent("change", [{
  182. compareName: "."+this.getName() + ".actionScript"
  183. }]);
  184. this.editor.designer.saveForm();
  185. }.bind(this),
  186. "onPostLoad": function () {
  187. // this.scriptNode.setStyle("display", "none");
  188. }.bind(this),
  189. "helpStyle": "cms"
  190. });
  191. this.scriptArea.load({"code": this.data.actionScript});
  192. }
  193. this.conditionNode = new Element("div", {"styles": this.css.actionScriptNode}).inject(this.node);
  194. this.conditionArea = new MWF.widget.ScriptArea(this.conditionNode, {
  195. "title": this.editor.designer.lp.actionbar.editCondition,
  196. "maxObj": this.editor.designer.formContentNode,
  197. "onChange": function(){
  198. this.data.condition = this.conditionArea.editor.getValue();
  199. if (this.data.condition){
  200. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code.png)");
  201. }else{
  202. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code_empty.png)");
  203. }
  204. this.editor.fireEvent("change", [{
  205. compareName: "."+this.getName() + ".conditionScript"
  206. }]);
  207. }.bind(this),
  208. "onSave": function(){
  209. this.data.condition = this.conditionArea.editor.getValue();
  210. this.editor.fireEvent("change", [{
  211. compareName: "."+this.getName() + ".conditionScript"
  212. }]);
  213. this.editor.designer.saveForm();
  214. }.bind(this),
  215. "onPostLoad": function(){
  216. // this.conditionNode.setStyle("display", "none");
  217. }.bind(this),
  218. "helpStyle" : "cms"
  219. });
  220. this.conditionArea.load({"code": this.data.condition});
  221. this.setEvent();
  222. //this.loadEditNode();
  223. //this.loadChildNode();
  224. //this.setTitleNode();
  225. //this.setEditNode();
  226. },
  227. setEvent: function(){
  228. this.iconMenu = new MWF.widget.Menu(this.iconNode, {
  229. "event": "click",
  230. "style": "actionbarIcon",
  231. "onPostShow" : function (ev) {
  232. ev.stopPropagation();
  233. }
  234. });
  235. this.iconMenu.load();
  236. var _self = this;
  237. for (var i=-6; i<0; i++){
  238. //var icon = this.editor.path+this.editor.options.style+"/tools/"+i+".png";
  239. var icon = "../x_component_cms_FormDesigner/Module/Actionbar/"+this.editor.options.style+"/custom/"+i+".png";
  240. var item = this.iconMenu.addMenuItem("", "click", function(ev){
  241. var src = this.item.getElement("img").get("src");
  242. _self.data.img = src.substr(src.lastIndexOf("/")+1, src.length);
  243. _self.data.customImg = true;
  244. _self.iconNode.setStyle("background-image", "url("+src+")");
  245. _self.editor.fireEvent("change", [{
  246. compareName: "."+_self.getName() + ".img"
  247. }]);
  248. ev.stopPropagation();
  249. }, icon);
  250. item.iconName = i+".png";
  251. }
  252. for (var i=1; i<=136; i++){
  253. //var icon = this.editor.path+this.editor.options.style+"/tools/"+i+".png";
  254. var icon = "../x_component_cms_FormDesigner/Module/Actionbar/"+this.editor.options.style+"/custom/"+i+".png";
  255. var item = this.iconMenu.addMenuItem("", "click", function(ev){
  256. var src = this.item.getElement("img").get("src");
  257. _self.data.img = src.substr(src.lastIndexOf("/")+1, src.length);
  258. _self.data.customImg = true;
  259. _self.iconNode.setStyle("background-image", "url("+src+")");
  260. _self.editor.fireEvent("change", [{
  261. compareName: "."+_self.getName() + ".img"
  262. }]);
  263. ev.stopPropagation();
  264. }, icon);
  265. item.iconName = i+".png";
  266. }
  267. this.upButton.addEvent("click", function(e){
  268. var actions = this.editor.actions;
  269. var dataList = this.editor.data;
  270. var dataIndex = dataList.indexOf( this.data );
  271. var index = actions.indexOf( this );
  272. if( index === 0 || dataIndex === 0 ){
  273. e.stopPropagation();
  274. return;
  275. }
  276. var index_before = index-1;
  277. var action = actions[index_before];
  278. this.node.inject(action.node, "before");
  279. actions[index_before] = actions.splice(index, 1, actions[index_before])[0];
  280. this.editor.actions = actions;
  281. var dataIndex_before = dataIndex - 1;
  282. dataList[dataIndex_before] = dataList.splice(dataIndex, 1, dataList[dataIndex_before])[0];
  283. this.editor.data = dataList;
  284. this.editor.fireEvent("change", [{
  285. compareName: "."+this.getName() + " [up]"
  286. }]);
  287. e.stopPropagation();
  288. }.bind(this));
  289. this.propertiesButton.addEvent("click", function(e){
  290. var dis = this.propertiesNode.getStyle("display");
  291. if (dis=="none"){
  292. this.propertiesNode.setStyle("display", "block");
  293. }else{
  294. this.propertiesNode.setStyle("display", "none");
  295. }
  296. e.stopPropagation();
  297. }.bind(this));
  298. this.textNode.addEvent("click", function(e){
  299. this.textNode.empty();
  300. var editTitleNode = new Element("input", {"styles": this.css.actionEditTextNode, "type": "text", "value": this.data.text}).inject(this.textNode);
  301. editTitleNode.focus();
  302. editTitleNode.select();
  303. var _self = this;
  304. editTitleNode.addEvent("blur", function(){_self.editTitleComplete(this);});
  305. editTitleNode.addEvent("keydown:keys(enter)", function(){_self.editTitleComplete(this);});
  306. editTitleNode.addEvent("click", function(e){e.stopPropagation()});
  307. e.stopPropagation();
  308. }.bind(this));
  309. this.conditionButton.addEvent("click", function(e){
  310. e.stopPropagation();
  311. this.editCondition();
  312. }.bind(this));
  313. if (this.editButton)this.editButton.addEvent("click", function(e){
  314. if (this.data.editShow){
  315. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit_hide.png)");
  316. this.data.editShow = false;
  317. }else{
  318. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit.png)");
  319. this.data.editShow = true;
  320. }
  321. this.editor.fireEvent("change", [{
  322. compareName: "."+this.getName() + ".editShow"
  323. }]);
  324. e.stopPropagation();
  325. }.bind(this));
  326. if (this.readButton)this.readButton.addEvent("click", function(e){
  327. if (this.data.readShow){
  328. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read_hide.png)");
  329. this.data.readShow = false;
  330. }else{
  331. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read.png)");
  332. this.data.readShow = true;
  333. }
  334. this.editor.fireEvent("change", [{
  335. compareName: "."+this.getName() + ".readShow"
  336. }]);
  337. e.stopPropagation();
  338. }.bind(this));
  339. this.titleNode.addEvent("click", function(){
  340. if (this.scriptNode){
  341. var dis = this.scriptNode.getStyle("display");
  342. if (dis=="none"){
  343. this.scriptNode.setStyle("display", "block");
  344. if (this.scriptArea){
  345. this.scriptArea.resizeContentNodeSize();
  346. if (this.scriptArea.editor) this.scriptArea.editor.resize();
  347. if (!this.scriptArea.jsEditor){
  348. this.scriptArea.contentNode.empty();
  349. this.scriptArea.loadEditor({"code": this.data.actionScript});
  350. }
  351. }
  352. }else{
  353. this.scriptNode.setStyle("display", "none");
  354. }
  355. }
  356. }.bind(this));
  357. if (this.delButton) this.delButton.addEvent("click", function(e){
  358. var _self = this;
  359. this.editor.designer.confirm("warn", this.delButton, MWF.APPFD.LP.notice.deleteButtonTitle, MWF.APPFD.LP.notice.deleteButton, 300, 120, function(){
  360. _self.destroy();
  361. this.close();
  362. }, function(){
  363. this.close();
  364. }, null);
  365. e.stopPropagation();
  366. }.bind(this));
  367. }
  368. });