PersonSelector.js 14 KB

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