PersonSelector.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. MWF.xApplication.process.ViewDesigner = MWF.xApplication.process.ViewDesigner || {};
  2. MWF.xApplication.process.ViewDesigner.widget = MWF.xApplication.process.ViewDesigner.widget || {};
  3. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  4. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  5. MWF.require("MWF.widget.Identity", null, false);
  6. MWF.xApplication.process.ViewDesigner.widget.PersonSelector = new Class({
  7. Implements: [Options, Events],
  8. Extends: MWF.widget.Common,
  9. options: {
  10. "style": "default",
  11. "type": "identity",
  12. "names": []
  13. },
  14. initialize: function(node, app, options){
  15. this.setOptions(options);
  16. this.node = $(node);
  17. this.app = app;
  18. this.path = "/x_component_process_ViewDesigner/widget/$PersonSelector/";
  19. this.cssPath = "/x_component_process_ViewDesigner/widget/$PersonSelector/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.identitys = [];
  22. this.restActions = new MWF.xAction.org.express.RestActions();
  23. this.name = this.node.get("name");
  24. this.load();
  25. },
  26. load: function(data){
  27. this.node.setStyles(this.css.node);
  28. this.createAddNode();
  29. this.loadIdentitys();
  30. },
  31. loadIdentitys: function(){
  32. var explorer = {
  33. "actions": this.restActions,
  34. "app": {
  35. "lp": this.app.lp
  36. }
  37. };
  38. if (this.options.names){
  39. if (this.options.type.toLowerCase()=="duty"){
  40. var dutys = JSON.decode(this.options.names);
  41. dutys.each(function(d){
  42. var dutyItem = new MWF.widget.Duty(d, this.node, explorer, true, function(e){
  43. var _self = this;
  44. var text = this.selector.app.lp.deleteDutyText.replace(/{duty}/g, this.data.name);
  45. this.selector.app.confirm("warm", e, this.selector.app.lp.deleteDutyTitle, text, 300, 120, function(){
  46. _self.selector.fireEvent("removeDuty", [_self]);
  47. this.close();
  48. }, function(){
  49. this.close();
  50. });
  51. e.stopPropagation();
  52. });
  53. dutyItem.selector = this;
  54. dutyItem.explorer = explorer;
  55. this.identitys.push(dutyItem);
  56. }.bind(this));
  57. }else{
  58. this.options.names.each(function(name){
  59. MWF.require("MWF.widget.Identity", function(){
  60. if (this.options.type.toLowerCase()=="identity") this.identitys.push(new MWF.widget.Identity({"name": name.name, "id": name.id}, this.node, explorer));
  61. if (this.options.type.toLowerCase()=="department") this.identitys.push(new MWF.widget.Department({"name": name.name, "id": name.id}, this.node, explorer));
  62. if (this.options.type.toLowerCase()=="company") this.identitys.push(new MWF.widget.Company({"name": name.name, "id": name.id}, this.node, explorer));
  63. if (this.options.type.toLowerCase()=="person") this.identitys.push(new MWF.widget.Person({"name": name.name, "id": name.id}, this.node, explorer));
  64. if (this.options.type.toLowerCase()=="application") this.identitys.push(new MWF.widget.Application({"name": name.name, "id": name.id}, this.node, explorer));
  65. if (this.options.type.toLowerCase()=="process") this.identitys.push(new MWF.widget.Process({"name": name.name, "id": name.id}, this.node, explorer));
  66. if (this.options.type.toLowerCase()=="formfield") this.identitys.push(new MWF.widget.FormField({"name": name, "id": name}, this.node, explorer));
  67. }.bind(this));
  68. }.bind(this));
  69. }
  70. }
  71. },
  72. createAddNode: function(){
  73. this.addNode = new Element("div", {"styles": this.css.addPersonNode}).inject(this.node, "before");
  74. this.addNode.addEvent("click", function(e){
  75. var selecteds = [];
  76. this.identitys.each(function(id){selecteds.push(id.data.id)});
  77. debugger;
  78. var explorer = {
  79. "actions": this.restActions,
  80. "app": {
  81. "lp": this.app.lp
  82. }
  83. }
  84. var options = {
  85. "type": this.options.type,
  86. "application": this.options.application,
  87. "fieldType": this.options.fieldType,
  88. "count": (this.options.type.toLowerCase()=="duty")? 1: 0,
  89. "values": selecteds,
  90. "zIndex": 20000,
  91. "onComplete": function(items){
  92. this.identitys = [];
  93. if (this.options.type.toLowerCase()!="duty") this.node.empty();
  94. MWF.require("MWF.widget.Identity", function(){
  95. items.each(function(item){
  96. if (this.options.type.toLowerCase()=="identity") this.identitys.push(new MWF.widget.Identity(item.data, this.node, explorer));
  97. if (this.options.type.toLowerCase()=="department") this.identitys.push(new MWF.widget.Department(item.data, this.node, explorer));
  98. if (this.options.type.toLowerCase()=="company") this.identitys.push(new MWF.widget.Company(item.data, this.node, explorer));
  99. if (this.options.type.toLowerCase()=="person") this.identitys.push(new MWF.widget.Person(item.data, this.node, explorer));
  100. if (this.options.type.toLowerCase()=="application") this.identitys.push(new MWF.widget.Application(item.data, this.node, explorer));
  101. if (this.options.type.toLowerCase()=="process") this.identitys.push(new MWF.widget.Process(item.data, this.node, explorer));
  102. if (this.options.type.toLowerCase()=="formfield") this.identitys.push(new MWF.widget.FormField(item.data, this.node, explorer));
  103. }.bind(this));
  104. if (this.options.type.toLowerCase()=="duty") {
  105. items.each(function(item){
  106. new MWF.xApplication.process.ViewDesigner.widget.PersonSelector.DutyInput(this, item.data, this.node, explorer, 20000);
  107. }.bind(this));
  108. }
  109. this.fireEvent("change", [this.identitys]);
  110. }.bind(this));
  111. }.bind(this)
  112. };
  113. var selector = new MWF.OrgSelector(this.app.content, options);
  114. }.bind(this));
  115. }
  116. });
  117. MWF.xApplication.process.ViewDesigner.widget.PersonSelector.DutyInput = Class({
  118. Implements: [Events],
  119. initialize: function(selector, data, node, explorer, zIndex){
  120. this.itemNode = $(node);
  121. this.data = data;
  122. this.isNew = false;
  123. this.selector = selector;
  124. this.css = this.selector.css;
  125. this.app = this.selector.app;
  126. this.explorer = explorer;
  127. this.zIndex = zIndex;
  128. this.selector.identitys = [];
  129. this.load();
  130. },
  131. load: function(){
  132. this.css.dutyMaskNode["z-index"] = this.zIndex;
  133. this.app.content.mask({
  134. "destroyOnHide": true,
  135. "style": this.css.dutyMaskNode,
  136. });
  137. this.node = new Element("div", {
  138. "styles": this.css.dutyInputArea
  139. });
  140. this.titleNode = new Element("div", {
  141. "styles": this.css.dutyTitleNode
  142. }).inject(this.node);
  143. this.titleActionNode = new Element("div", {
  144. "styles": this.css.dutyTitleActionNode
  145. }).inject(this.titleNode);
  146. this.titleTextNode = new Element("div", {
  147. "styles": this.css.dutyTitleTextNode,
  148. "text": this.app.lp.dutyInputTitle
  149. }).inject(this.titleNode);
  150. this.contentNode = new Element("div", {
  151. "styles": this.css.dutyContentNode
  152. }).inject(this.node);
  153. this.loadContent();
  154. this.actionNode = new Element("div", {
  155. "styles": this.css.dutyActionNode
  156. }).inject(this.node);
  157. this.actionNode.setStyle("text-align", "center");
  158. this.loadAction();
  159. this.node.setStyle("z-index", this.zIndex.toInt()+1);
  160. this.node.inject(this.app.content);
  161. this.node.position({
  162. relativeTo: this.app.content,
  163. position: "center",
  164. edge: "center"
  165. });
  166. var size = this.app.content.getSize();
  167. var nodeSize = this.node.getSize();
  168. this.node.makeDraggable({
  169. "handle": this.titleNode,
  170. "limit": {
  171. "x": [0, size.x-nodeSize.x],
  172. "y": [0, size.y-nodeSize.y]
  173. }
  174. });
  175. this.setEvent();
  176. },
  177. setEvent: function(){
  178. if (this.titleActionNode){
  179. this.titleActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  180. }
  181. this.okActionNode.addEvent("click", function(){
  182. this.selectDuty();
  183. this.close();
  184. }.bind(this));
  185. this.cancelActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  186. },
  187. selectDuty: function(){
  188. var code = this.scriptEditor.editor.editor.getValue();
  189. this.data.code = code;
  190. if (!this.item){
  191. var dutyItem = new MWF.widget.Duty(this.data, this.itemNode, this.explorer, true, function(e){
  192. var _self = this;
  193. var text = this.selector.app.lp.deleteDutyText.replace(/{duty}/g, this.data.name);
  194. this.selector.app.confirm("warm", e, this.selector.app.lp.deleteDutyTitle, text, 300, 120, function(){
  195. _self.selector.fireEvent("removeDuty", [_self]);
  196. this.close();
  197. }, function(){
  198. this.close();
  199. });
  200. e.stopPropagation();
  201. });
  202. dutyItem.selector = this.selector;
  203. dutyItem.explorer = this.explorer;
  204. this.selector.identitys.push(dutyItem);
  205. this.selector.fireEvent("change", [this.selector.identitys]);
  206. }else{
  207. this.selector.identitys.push(this.item);
  208. this.selector.fireEvent("change", [this.selector.identitys]);
  209. }
  210. },
  211. "close": function(){
  212. this.node.destroy();
  213. this.app.content.unmask();
  214. MWF.release(this);
  215. delete this;
  216. },
  217. loadAction: function(){
  218. this.okActionNode = new Element("button", {
  219. "styles": this.css.dutyOkActionNode,
  220. "text": "确 定"
  221. }).inject(this.actionNode);
  222. this.cancelActionNode = new Element("button", {
  223. "styles": this.css.dutyCancelActionNode,
  224. "text": "取 消"
  225. }).inject(this.actionNode);
  226. },
  227. loadContent: function(){
  228. this.contentAreaNode= new Element("div", {"styles": this.css.dutyContentAreaNode}).inject(this.contentNode);
  229. var text = this.app.lp.dutyInput.replace(/{duty}/g, this.data.name);
  230. this.textNode = new Element("div", {"styles": this.css.dutyTextNode, "text": text}).inject(this.contentAreaNode);
  231. this.referenceAreaNode = new Element("div", {"styles": this.css.dutyReferenceAreaNode}).inject(this.contentAreaNode);
  232. this.scriptAreaNode = new Element("div", {"styles": this.css.dutyScriptAreaNode}).inject(this.contentAreaNode);
  233. this.createScriptNode();
  234. this.createReference(this.app.lp.creatorCompany, "return this.workContext.getWork().creatorCompany");
  235. this.createReference(this.app.lp.creatorDepartment, "return this.workContext.getWork().creatorDepartment");
  236. this.createReference(this.app.lp.currentCompany, "return this.workContext.getTask().company");
  237. this.createReference(this.app.lp.currentDepartment, "return this.workContext.getTask().department");
  238. },
  239. createScriptNode: function(){
  240. this.scriptNode = new Element("div", {"styles": this.css.dutyScriptNode}).inject(this.scriptAreaNode);
  241. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText", function(){
  242. this.scriptEditor = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode, "", this.app, {
  243. "height": 316,
  244. "maskNode": this.app.content,
  245. "maxObj": this.app.content
  246. //"onChange": function(code){
  247. // _self.data[node.get("name")] = code;
  248. //}
  249. });
  250. this.scriptEditor.loadEditor(function(){
  251. if (this.data.code) this.scriptEditor.editor.editor.setValue(this.data.code);
  252. }.bind(this));
  253. }.bind(this));
  254. },
  255. createReference: function(text, code){
  256. var node = new Element("div", {"styles": this.css.dutyReferenceItemNode}).inject(this.referenceAreaNode);
  257. node.set("text", text);
  258. node.store("code", code);
  259. var css = this.css.dutyReferenceItemNode;
  260. var overcss = this.css.dutyReferenceItemNode_over;
  261. var downcss = this.css.dutyReferenceItemNode_down;
  262. var _self = this;
  263. node.addEvents({
  264. "mouseover": function(){this.setStyles(overcss);},
  265. "mouseout": function(){this.setStyles(css);},
  266. "mousedown": function(){this.setStyles(downcss);},
  267. "mouseup": function(){this.setStyles(overcss);},
  268. "click": function(){
  269. var code = this.retrieve("code");
  270. var value = _self.scriptEditor.editor.editor.getValue();
  271. if (!value){
  272. _self.scriptEditor.editor.editor.setValue(code);
  273. }else{
  274. value = value + "\n" +code;
  275. _self.scriptEditor.editor.editor.setValue(value);
  276. }
  277. }
  278. });
  279. }
  280. });
  281. MWF.widget.Duty = new Class({
  282. Extends: MWF.widget.Department,
  283. setEvent: function(){
  284. this.node.addEvent("click", function(){
  285. this.modifyDuty();
  286. }.bind(this));
  287. },
  288. modifyDuty: function(){
  289. var dutyInput = new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this.selector, this.data, this.selector.node, this.explorer, 20000);
  290. dutyInput.item = this;
  291. }
  292. });