ScriptIncluder.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
  2. MWF.require("MWF.widget.UUID", null, false);
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. MWF.xApplication.process.FormDesigner.widget.ScriptIncluder = new Class({
  5. Implements: [Options, Events],
  6. Extends: MWF.widget.Common,
  7. options: {
  8. "style": "default",
  9. "maxObj": document.body
  10. },
  11. initialize: function(node, designer, options){
  12. this.setOptions(options);
  13. this.node = $(node);
  14. this.designer = designer;
  15. this.path = "../x_component_process_FormDesigner/widget/$ScriptIncluder/";
  16. this.cssPath = "../x_component_process_FormDesigner/widget/$ScriptIncluder/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.lp = this.designer.lp.scriptIncluder;
  19. this.items = [];
  20. },
  21. load: function(data){
  22. this.editorNode = new Element("div", {"styles": this.css.editorNode}).inject(this.node);
  23. this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.node);
  24. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.node);
  25. this.loadEditorNode();
  26. this.loadActionNode();
  27. this.loadListNode(data);
  28. },
  29. loadEditorNode: function(){
  30. debugger;
  31. var html = "<table width='100%' border='0' cellpadding='5' cellspacing='0' class='editTable'>" +
  32. "<tr><td style='width: 60px; '>"+this.lp.asyncLoad+"</td><td align='left'>"+
  33. "<input type='radio' name='"+(this.designer.appId||"")+"asyncLoadScript' value='true' checked/>"+this.lp.yes+
  34. "<input type='radio' name='"+(this.designer.appId||"")+"asyncLoadScript' value='false'/>"+this.lp.no+
  35. "</td></tr><tr><td>"+this.lp.selectScript+"</td><td><div class='scriptSelectorArea'></div></td></tr></table>";
  36. this.editorNode.set("html", html);
  37. var tds = this.editorNode.getElements("td").setStyles(this.css.editTableTdValue);
  38. this.asyncLoadScript = this.editorNode.getElements("[type='radio']");
  39. this.scriptSelectorArea = this.editorNode.getElement(".scriptSelectorArea");
  40. this.loadScriptSelector();
  41. },
  42. loadScriptSelector: function( data ){
  43. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  44. var _self = this;
  45. if( !data )data = [];
  46. this.scriptSelector = new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(this.scriptSelectorArea, this.designer, {
  47. "type": "Script",
  48. "count": 0,
  49. "names": data,
  50. "onChange": function(ids){
  51. var value = [];
  52. ids.each( function (id) {
  53. var d = id.data;
  54. value.push({
  55. "type" : "script",
  56. "name": d.name,
  57. "alias": d.alias,
  58. "id": d.id,
  59. "appName" : d.appName || d.applicationName,
  60. "appId": d.appId || d.application,
  61. "appType" : d.appType
  62. });
  63. })
  64. this.currentSelectScripts = value;
  65. }.bind(this)
  66. });
  67. }.bind(this));
  68. },
  69. loadActionNode: function(){
  70. this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.actionNode);
  71. this.addAction = new Element("div", {"styles": this.css.addAction, "text": this.designer.lp.validation.add}).inject(this.actionAreaNode);
  72. this.modifyAction = new Element("div", {"styles": this.css.modifyAction_disabled, "text": this.designer.lp.validation.modify}).inject(this.actionAreaNode);
  73. this.addAction.addEvent("click", function(){
  74. this.add();
  75. }.bind(this));
  76. this.modifyAction.addEvent("click", function(){
  77. this.modify();
  78. }.bind(this));
  79. },
  80. getCurrentData: function(){
  81. var async = true;
  82. this.asyncLoadScript.each( function (el) {
  83. if( el.checked ){
  84. async = el.get("value") === "true";
  85. }
  86. });
  87. return {
  88. "async": async,
  89. "scriptList": this.currentSelectScripts || []
  90. };
  91. },
  92. add: function(){
  93. this.hideErrorNode();
  94. var data = this.getCurrentData();
  95. if ( data.scriptList.length === 0 ){
  96. this.showErrorNode(this.lp.selectScriptNotice);
  97. return false;
  98. }
  99. for( var i=0; i<this.items.length; i++ ){
  100. var scriptList = this.items[i].data.scriptList;
  101. for( var j=0; j<scriptList.length; j++ ){
  102. for( var k=0; k< data.scriptList.length; k++ )
  103. if( scriptList[j].id === data.scriptList[i].id ){
  104. this.showErrorNode(this.lp.repeatAddScriptNotice);
  105. return false;
  106. }
  107. }
  108. }
  109. var item = new MWF.xApplication.process.FormDesigner.widget.ScriptIncluder.Item(data, this);
  110. this.items.push(item);
  111. item.selected();
  112. this.empty();
  113. this.fireEvent("change");
  114. },
  115. empty: function(){
  116. this.asyncLoadScript.each( function (el) {
  117. if( el.get("value") === "true" ){
  118. el.set("checked", true)
  119. }
  120. });
  121. if(this.scriptSelector)this.scriptSelector.setData( [] );
  122. this.currentSelectScripts = [];
  123. },
  124. showErrorNode: function(text){
  125. this.errorNode = new Element("div", {"styles": this.css.errorNode}).inject(this.actionNode, "before");
  126. this.errorTextNode = new Element("div", {"styles": this.css.errorTextNode}).inject(this.errorNode);
  127. this.errorTextNode.set("text", text);
  128. this.errorNode.addEvent("click", function(){this.hideErrorNode();}.bind(this));
  129. },
  130. hideErrorNode: function(){
  131. if (this.errorNode) this.errorNode.destroy();
  132. },
  133. modify: function(){
  134. if (this.currentItem){
  135. this.hideErrorNode();
  136. var data = this.getCurrentData();
  137. if ( data.scriptList.length === 0 ){
  138. this.showErrorNode(this.lp.selectScriptNotice);
  139. return false;
  140. }
  141. for( var i=0; i<this.items.length; i++ ){
  142. if( this.currentItem !== this.items[i] ){
  143. var scriptList = this.items[i].data.scriptList;
  144. for( var j=0; j< scriptList.length; j++ ){
  145. for( var k=0; k< data.scriptList.length; k++ )
  146. if( scriptList[j].id === data.scriptList[i].id ){
  147. this.showErrorNode(this.lp.repeatAddScriptNotice);
  148. return false;
  149. }
  150. }
  151. }
  152. }
  153. this.currentItem.reload(data);
  154. this.currentItem.unSelected();
  155. this.disabledModify();
  156. this.empty();
  157. this.fireEvent("change");
  158. }
  159. },
  160. loadListNode: function(data){
  161. if (data){
  162. if (data.length){
  163. data.each(function(itemData){
  164. var item = new MWF.xApplication.process.FormDesigner.widget.ScriptIncluder.Item(itemData, this);
  165. this.items.push(item);
  166. }.bind(this));
  167. }
  168. }
  169. },
  170. enabledModify: function(){
  171. this.modifyAction.setStyles(this.css.modifyAction);
  172. },
  173. disabledModify: function(){
  174. this.modifyAction.setStyles(this.css.modifyAction_disabled);
  175. },
  176. setData: function(data){
  177. this.asyncLoadScript.each( function (el) {
  178. if( el.get("value") === "true" && data.async ){
  179. el.set("checked", true)
  180. }else if( el.get("value") === "false" && !data.async ){
  181. el.set("checked", true)
  182. }
  183. });
  184. if( !this.scriptSelector ){
  185. this.loadScriptSelector( data.scriptList );
  186. }else{
  187. this.scriptSelector.setData( data.scriptList );
  188. }
  189. this.currentSelectScripts = data.scriptList;
  190. },
  191. deleteItem: function(item){
  192. if (this.currentItem == item) item.unSelected();
  193. this.items.erase(item);
  194. item.node.destroy();
  195. MWF.release(item);
  196. this.fireEvent("change");
  197. },
  198. getData: function(){
  199. var data = [];
  200. this.items.each(function(item){
  201. data.push(item.data);
  202. });
  203. return data;
  204. }
  205. });
  206. MWF.xApplication.process.FormDesigner.widget.ScriptIncluder.Item = new Class({
  207. initialize: function(data, editor){
  208. this.data = data;
  209. this.editor = editor;
  210. this.container = this.editor.listNode;
  211. this.css = this.editor.css;
  212. this.lp = this.editor.designer.lp;
  213. this.load();
  214. },
  215. load: function(){
  216. debugger;
  217. this.node = new Element("div", {"styles": this.css.itemNode}).inject(this.container);
  218. this.deleteNode = new Element("div", {"styles": this.css.itemDeleteNode}).inject(this.node);
  219. this.contentNode = new Element("div", {"styles": this.css.itemContentNode}).inject(this.node);
  220. this.asyncNode = new Element("div", {"styles": {}}).inject(this.contentNode);
  221. this.asyncNode.set({
  222. "text": this.data.async ? this.lp.scriptIncluder.asyncLoadScript : this.lp.scriptIncluder.syncLoadScript
  223. });
  224. this.scriptNode = new Element("div", {
  225. styles : this.css.scriptNode
  226. }).inject(this.contentNode);
  227. this.data.scriptList.each( function (scipt) {
  228. new MWF.widget.O2Script(scipt, this.scriptNode)
  229. }.bind(this));
  230. this.contentNode.addEvent("click", function(){
  231. this.selected();
  232. }.bind(this));
  233. this.deleteNode.addEvent("click", function(e){
  234. this.deleteItem(e);
  235. }.bind(this));
  236. },
  237. reload: function(data){
  238. this.data = data;
  239. this.asyncNode.set({
  240. "text": this.data.async ? this.lp.scriptIncluder.asyncLoadScript : this.lp.scriptIncluder.syncLoadScript
  241. });
  242. this.scriptNode.empty();
  243. this.data.scriptList.each( function (scipt) {
  244. new MWF.widget.O2Script(scipt, this.scriptNode)
  245. }.bind(this));
  246. },
  247. selected: function(){
  248. if (this.editor.currentItem) this.editor.currentItem.unSelected();
  249. this.node.setStyles(this.css.itemNode_current);
  250. this.editor.currentItem = this;
  251. this.editor.setData(this.data);
  252. this.editor.enabledModify();
  253. },
  254. unSelected: function(){
  255. this.node.setStyles(this.css.itemNode);
  256. this.editor.currentItem = this;
  257. //this.editor.modifyValidation();
  258. this.editor.disabledModify();
  259. },
  260. deleteItem: function(e){
  261. var _self = this;
  262. this.editor.designer.confirm("warn", e, this.lp.scriptIncluder.delete_title, this.lp.scriptIncluder.delete_text, 300, 120, function(){
  263. _self.destroy();
  264. this.close();
  265. }, function(){
  266. this.close();
  267. });
  268. },
  269. destroy: function(){
  270. this.editor.deleteItem(this);
  271. }
  272. });