ActionsEditor.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. if (this.editor.options.iconType==='font'){
  167. this.iconNode.addClass("ooicon-"+this.data.icon);
  168. this.iconNode.setStyles({
  169. "display": "flex",
  170. "align-items": "center",
  171. "justify-content": "center"
  172. });
  173. }else{
  174. var icon = this.editor.path+this.editor.options.style+"/tools/"+this.data.img;
  175. this.iconNode.setStyle("background-image", "url("+icon+")");
  176. }
  177. if (!this.editor.options.noCode && !this.data.system ) {
  178. this.scriptNode = new Element("div", {"styles": this.css.actionScriptNode}).inject(this.node);
  179. this.scriptArea = new MWF.widget.ScriptArea(this.scriptNode, {
  180. "title": this.editor.designer.lp.actionbar.editScript,
  181. "maxObj": this.editor.designer.formContentNode,
  182. "onChange": function () {
  183. this.data.actionScript = this.scriptArea.editor.getValue();
  184. this.editor.fireEvent("change", [{
  185. compareName: "."+this.getName() + ".actionScript"
  186. }]);
  187. }.bind(this),
  188. "onSave": function () {
  189. this.data.actionScript = this.scriptArea.editor.getValue();
  190. this.editor.fireEvent("change", [{
  191. compareName: "."+this.getName() + ".actionScript"
  192. }]);
  193. this.editor.designer.saveForm();
  194. }.bind(this),
  195. "onPostLoad": function () {
  196. // this.scriptNode.setStyle("display", "none");
  197. }.bind(this),
  198. "helpStyle": "cms"
  199. });
  200. this.scriptArea.load({"code": this.data.actionScript});
  201. }
  202. this.conditionNode = new Element("div", {"styles": this.css.actionScriptNode}).inject(this.node);
  203. this.conditionArea = new MWF.widget.ScriptArea(this.conditionNode, {
  204. "title": this.editor.designer.lp.actionbar.editCondition,
  205. "maxObj": this.editor.designer.formContentNode,
  206. "onChange": function(){
  207. this.data.condition = this.conditionArea.editor.getValue();
  208. if (this.data.condition){
  209. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code.png)");
  210. }else{
  211. this.conditionButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/code_empty.png)");
  212. }
  213. this.editor.fireEvent("change", [{
  214. compareName: "."+this.getName() + ".conditionScript"
  215. }]);
  216. }.bind(this),
  217. "onSave": function(){
  218. this.data.condition = this.conditionArea.editor.getValue();
  219. this.editor.fireEvent("change", [{
  220. compareName: "."+this.getName() + ".conditionScript"
  221. }]);
  222. this.editor.designer.saveForm();
  223. }.bind(this),
  224. "onPostLoad": function(){
  225. // this.conditionNode.setStyle("display", "none");
  226. }.bind(this),
  227. "helpStyle" : "cms"
  228. });
  229. this.conditionArea.load({"code": this.data.condition});
  230. this.setEvent();
  231. //this.loadEditNode();
  232. //this.loadChildNode();
  233. //this.setTitleNode();
  234. //this.setEditNode();
  235. },
  236. setEvent: function(){
  237. this.iconMenu = new MWF.widget.Menu(this.iconNode, {
  238. "event": "click",
  239. "style": "actionbarIcon",
  240. "onPostShow" : function (ev) {
  241. ev.stopPropagation();
  242. }
  243. });
  244. this.iconMenu.load();
  245. var _self = this;
  246. if (this.editor.options.iconType==='font'){
  247. o2.JSON.get("/x_desktop/css/v10/ooicon.json", function(json){
  248. const icons = json.glyphs;
  249. icons.forEach(function(i){
  250. var item = this.iconMenu.addMenuItem("", "click", function(ev){
  251. var icon = this.item.iconName;
  252. _self.iconNode.set("class", "ooicon-"+icon);
  253. _self.data.icon = icon;
  254. _self.editor.fireEvent("change", [{
  255. compareName: "."+icon + ".icon"
  256. }]);
  257. ev.stopPropagation();
  258. });
  259. item.item.addClass("ooicon-"+i.font_class);
  260. item.item.setStyles({
  261. "text-align": "center",
  262. "line-height": "28px",
  263. "font-size": "14px"
  264. });
  265. item.item.iconName = i.font_class;
  266. }.bind(this));
  267. }.bind(this));
  268. }else{
  269. for (var i=-6; i<0; i++){
  270. //var icon = this.editor.path+this.editor.options.style+"/tools/"+i+".png";
  271. var icon = "../x_component_cms_FormDesigner/Module/Actionbar/"+this.editor.options.style+"/custom/"+i+".png";
  272. var item = this.iconMenu.addMenuItem("", "click", function(ev){
  273. var src = this.item.getElement("img").get("src");
  274. _self.data.img = src.substr(src.lastIndexOf("/")+1, src.length);
  275. _self.data.customImg = true;
  276. _self.iconNode.setStyle("background-image", "url("+src+")");
  277. _self.editor.fireEvent("change", [{
  278. compareName: "."+_self.getName() + ".img"
  279. }]);
  280. ev.stopPropagation();
  281. }, icon);
  282. item.iconName = i+".png";
  283. }
  284. for (var i=1; i<=136; i++){
  285. //var icon = this.editor.path+this.editor.options.style+"/tools/"+i+".png";
  286. var icon = "../x_component_cms_FormDesigner/Module/Actionbar/"+this.editor.options.style+"/custom/"+i+".png";
  287. var item = this.iconMenu.addMenuItem("", "click", function(ev){
  288. var src = this.item.getElement("img").get("src");
  289. _self.data.img = src.substr(src.lastIndexOf("/")+1, src.length);
  290. _self.data.customImg = true;
  291. _self.iconNode.setStyle("background-image", "url("+src+")");
  292. _self.editor.fireEvent("change", [{
  293. compareName: "."+_self.getName() + ".img"
  294. }]);
  295. ev.stopPropagation();
  296. }, icon);
  297. item.iconName = i+".png";
  298. }
  299. }
  300. this.upButton.addEvent("click", function(e){
  301. var actions = this.editor.actions;
  302. var dataList = this.editor.data;
  303. var dataIndex = dataList.indexOf( this.data );
  304. var index = actions.indexOf( this );
  305. if( index === 0 || dataIndex === 0 ){
  306. e.stopPropagation();
  307. return;
  308. }
  309. var index_before = index-1;
  310. var action = actions[index_before];
  311. this.node.inject(action.node, "before");
  312. actions[index_before] = actions.splice(index, 1, actions[index_before])[0];
  313. this.editor.actions = actions;
  314. var dataIndex_before = dataIndex - 1;
  315. dataList[dataIndex_before] = dataList.splice(dataIndex, 1, dataList[dataIndex_before])[0];
  316. this.editor.data = dataList;
  317. this.editor.fireEvent("change", [{
  318. compareName: "."+this.getName() + " [up]"
  319. }]);
  320. e.stopPropagation();
  321. }.bind(this));
  322. this.propertiesButton.addEvent("click", function(e){
  323. var dis = this.propertiesNode.getStyle("display");
  324. if (dis=="none"){
  325. this.propertiesNode.setStyle("display", "block");
  326. }else{
  327. this.propertiesNode.setStyle("display", "none");
  328. }
  329. e.stopPropagation();
  330. }.bind(this));
  331. this.textNode.addEvent("click", function(e){
  332. this.textNode.empty();
  333. var editTitleNode = new Element("input", {"styles": this.css.actionEditTextNode, "type": "text", "value": this.data.text}).inject(this.textNode);
  334. editTitleNode.focus();
  335. editTitleNode.select();
  336. var _self = this;
  337. editTitleNode.addEvent("blur", function(){_self.editTitleComplete(this);});
  338. editTitleNode.addEvent("keydown:keys(enter)", function(){_self.editTitleComplete(this);});
  339. editTitleNode.addEvent("click", function(e){e.stopPropagation()});
  340. e.stopPropagation();
  341. }.bind(this));
  342. this.conditionButton.addEvent("click", function(e){
  343. e.stopPropagation();
  344. this.editCondition();
  345. }.bind(this));
  346. if (this.editButton)this.editButton.addEvent("click", function(e){
  347. if (this.data.editShow){
  348. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit_hide.png)");
  349. this.data.editShow = false;
  350. }else{
  351. this.editButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/edit.png)");
  352. this.data.editShow = true;
  353. }
  354. this.editor.fireEvent("change", [{
  355. compareName: "."+this.getName() + ".editShow"
  356. }]);
  357. e.stopPropagation();
  358. }.bind(this));
  359. if (this.readButton)this.readButton.addEvent("click", function(e){
  360. if (this.data.readShow){
  361. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read_hide.png)");
  362. this.data.readShow = false;
  363. }else{
  364. this.readButton.setStyle("background-image", "url("+this.editor.path+this.editor.options.style+"/icon/read.png)");
  365. this.data.readShow = true;
  366. }
  367. this.editor.fireEvent("change", [{
  368. compareName: "."+this.getName() + ".readShow"
  369. }]);
  370. e.stopPropagation();
  371. }.bind(this));
  372. this.titleNode.addEvent("click", function(){
  373. if (this.scriptNode){
  374. var dis = this.scriptNode.getStyle("display");
  375. if (dis=="none"){
  376. this.scriptNode.setStyle("display", "block");
  377. if (this.scriptArea){
  378. this.scriptArea.resizeContentNodeSize();
  379. if (this.scriptArea.editor) this.scriptArea.editor.resize();
  380. if (!this.scriptArea.jsEditor){
  381. this.scriptArea.contentNode.empty();
  382. this.scriptArea.loadEditor({"code": this.data.actionScript});
  383. }
  384. }
  385. }else{
  386. this.scriptNode.setStyle("display", "none");
  387. }
  388. }
  389. }.bind(this));
  390. if (this.delButton) this.delButton.addEvent("click", function(e){
  391. var _self = this;
  392. this.editor.designer.confirm("warn", this.delButton, MWF.APPFD.LP.notice.deleteButtonTitle, MWF.APPFD.LP.notice.deleteButton, 300, 120, function(){
  393. _self.destroy();
  394. this.close();
  395. }, function(){
  396. this.close();
  397. }, null);
  398. e.stopPropagation();
  399. }.bind(this));
  400. }
  401. });