PersonSelector_bak.js 14 KB

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