PersonSelector.js 14 KB

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