ActionsEditor.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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, {
  201. "event": "click",
  202. "style": "actionbarIcon",
  203. "onPostShow" : function (ev) {
  204. ev.stopPropagation();
  205. }
  206. });
  207. this.iconMenu.load();
  208. var _self = this;
  209. for (var i=-6; i<0; i++){
  210. //var icon = this.editor.path+this.editor.options.style+"/tools/"+i+".png";
  211. var icon = "../x_component_cms_FormDesigner/Module/Actionbar/"+this.editor.options.style+"/custom/"+i+".png";
  212. var item = this.iconMenu.addMenuItem("", "click", function(ev){
  213. var src = this.item.getElement("img").get("src");
  214. _self.data.img = src.substr(src.lastIndexOf("/")+1, src.length);
  215. _self.iconNode.setStyle("background-image", "url("+src+")");
  216. _self.editor.fireEvent("change");
  217. ev.stopPropagation();
  218. }, icon);
  219. item.iconName = i+".png";
  220. }
  221. for (var i=1; i<=134; i++){
  222. //var icon = this.editor.path+this.editor.options.style+"/tools/"+i+".png";
  223. var icon = "../x_component_cms_FormDesigner/Module/Actionbar/"+this.editor.options.style+"/custom/"+i+".png";
  224. var item = this.iconMenu.addMenuItem("", "click", function(ev){
  225. var src = this.item.getElement("img").get("src");
  226. _self.data.img = src.substr(src.lastIndexOf("/")+1, src.length);
  227. _self.iconNode.setStyle("background-image", "url("+src+")");
  228. _self.editor.fireEvent("change");
  229. ev.stopPropagation();
  230. }, icon);
  231. item.iconName = i+".png";
  232. }
  233. this.upButton.addEvent("click", function(e){
  234. var actions = this.editor.actions;
  235. var dataList = this.editor.data;
  236. var dataIndex = dataList.indexOf( this.data );
  237. var index = actions.indexOf( this );
  238. if( index === 0 || dataIndex === 0 ){
  239. e.stopPropagation();
  240. return;
  241. }
  242. var index_before = index-1;
  243. var action = actions[index_before];
  244. this.node.inject(action.node, "before");
  245. actions[index_before] = actions.splice(index, 1, actions[index_before])[0];
  246. this.editor.actions = actions;
  247. var dataIndex_before = dataIndex - 1;
  248. dataList[dataIndex_before] = dataList.splice(dataIndex, 1, dataList[dataIndex_before])[0];
  249. this.editor.data = dataList;
  250. this.editor.fireEvent("change");
  251. e.stopPropagation();
  252. }.bind(this));
  253. this.propertiesButton.addEvent("click", function(e){
  254. var dis = this.propertiesNode.getStyle("display");
  255. if (dis=="none"){
  256. this.propertiesNode.setStyle("display", "block");
  257. }else{
  258. this.propertiesNode.setStyle("display", "none");
  259. }
  260. e.stopPropagation();
  261. }.bind(this));
  262. this.textNode.addEvent("click", function(e){
  263. this.textNode.empty();
  264. var editTitleNode = new Element("input", {"styles": this.css.actionEditTextNode, "type": "text", "value": this.data.text}).inject(this.textNode);
  265. editTitleNode.focus();
  266. editTitleNode.select();
  267. var _self = this;
  268. editTitleNode.addEvent("blur", function(){_self.editTitleComplete(this);});
  269. editTitleNode.addEvent("keydown:keys(enter)", function(){_self.editTitleComplete(this);});
  270. editTitleNode.addEvent("click", function(e){e.stopPropagation()});
  271. e.stopPropagation();
  272. }.bind(this));
  273. this.conditionButton.addEvent("click", function(e){
  274. e.stopPropagation();
  275. this.editCondition();
  276. }.bind(this));
  277. if (this.editButton)this.editButton.addEvent("click", function(e){
  278. if (this.data.editShow){
  279. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit_hide.png)");
  280. this.data.editShow = false;
  281. }else{
  282. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit.png)");
  283. this.data.editShow = true;
  284. }
  285. this.editor.fireEvent("change");
  286. e.stopPropagation();
  287. }.bind(this));
  288. if (this.readButton)this.readButton.addEvent("click", function(e){
  289. if (this.data.readShow){
  290. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read_hide.png)");
  291. this.data.readShow = false;
  292. }else{
  293. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read.png)");
  294. this.data.readShow = true;
  295. }
  296. this.editor.fireEvent("change");
  297. e.stopPropagation();
  298. }.bind(this));
  299. this.titleNode.addEvent("click", function(){
  300. if (this.scriptNode){
  301. var dis = this.scriptNode.getStyle("display");
  302. if (dis=="none"){
  303. this.scriptNode.setStyle("display", "block");
  304. if (this.scriptArea){
  305. this.scriptArea.resizeContentNodeSize();
  306. if (this.scriptArea.editor) this.scriptArea.editor.resize();
  307. if (!this.scriptArea.jsEditor){
  308. this.scriptArea.contentNode.empty();
  309. this.scriptArea.loadEditor({"code": this.data.actionScript});
  310. }
  311. }
  312. }else{
  313. this.scriptNode.setStyle("display", "none");
  314. }
  315. }
  316. }.bind(this));
  317. if (this.delButton) this.delButton.addEvent("click", function(e){
  318. var _self = this;
  319. this.editor.designer.confirm("warn", this.delButton, MWF.APPFD.LP.notice.deleteButtonTitle, MWF.APPFD.LP.notice.deleteButton, 300, 120, function(){
  320. _self.destroy();
  321. this.close();
  322. }, function(){
  323. this.close();
  324. }, null);
  325. e.stopPropagation();
  326. }.bind(this));
  327. }
  328. });