ActionsEditor.js 16 KB

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