ActionsEditor.js 17 KB

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