PersonSelector.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.ProcessDesigner = MWF.xApplication.process.ProcessDesigner || {};
  3. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  4. MWF.xDesktop.requireApp("Selector", "package", null, false);
  5. MWF.require("MWF.widget.O2Identity", null, false);
  6. MWF.xApplication.process.ProcessDesigner.widget.PersonSelector = new Class({
  7. Implements: [Options, Events],
  8. Extends: MWF.widget.Common,
  9. options: {
  10. "style": "default",
  11. "type": "identity",
  12. "count": 0,
  13. "names": []
  14. },
  15. initialize: function(node, app, options){
  16. this.setOptions(options);
  17. this.node = $(node);
  18. this.app = app;
  19. debugger;
  20. this.path = "../x_component_process_ProcessDesigner/widget/$PersonSelector/";
  21. this.cssPath = "../x_component_process_ProcessDesigner/widget/$PersonSelector/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.identitys = [];
  24. this.restActions = MWF.Actions.get("x_organization_assemble_control");
  25. //this.restActions = new MWF.xApplication.Selector.Actions.RestActions();
  26. this.name = this.node.get("name");
  27. this.load();
  28. },
  29. load: function(){
  30. this.node.setStyles(this.css.node);
  31. this.createAddNode();
  32. this.loadIdentitys();
  33. },
  34. loadIdentitys: function(){
  35. if (this.options.names){
  36. if (this.options.type.toLowerCase()==="duty"){
  37. var dutys = JSON.decode(this.options.names);
  38. dutys.each(function(d){
  39. var dutyItem = new MWF.widget.O2Duty(d, this.node, {
  40. "canRemove": true,
  41. "onRemove": function(item, e){
  42. var _self = this;
  43. var text = this.app.lp.deleteDutyText.replace(/{duty}/g, item.data.name);
  44. this.app.confirm("warm", e, this.app.lp.deleteDutyTitle, text, 300, 120, function(){
  45. _self.identitys.erase(item);
  46. _self.fireEvent("removeDuty", [item]);
  47. this.close();
  48. }, function(){
  49. this.close();
  50. });
  51. e.stopPropagation();
  52. }.bind(this)
  53. });
  54. dutyItem.selector = this;
  55. this.identitys.push(dutyItem);
  56. }.bind(this));
  57. }else{
  58. var names = this.options.names;
  59. if( typeOf(names) === "string" ){
  60. names = JSON.parse( names );
  61. }
  62. names.each(function(name){
  63. if (name){
  64. var data = (typeOf(name)==="string") ? {"name": name, "id": name}: name;
  65. MWF.require("MWF.widget.O2Identity", function(){
  66. if (this.options.type.toLowerCase()==="identity") this.identitys.push(new MWF.widget.O2Identity(data, this.node));
  67. if (this.options.type.toLowerCase()==="unit") this.identitys.push(new MWF.widget.O2Unit(data, this.node));
  68. if (this.options.type.toLowerCase()==="group") this.identitys.push(new MWF.widget.O2Group(data, this.node));
  69. if (this.options.type.toLowerCase()==="person") this.identitys.push(new MWF.widget.O2Person(data, this.node));
  70. if (this.options.type.toLowerCase()==="application") this.identitys.push(new MWF.widget.O2Application(data, this.node));
  71. if (this.options.type.toLowerCase()==="process") this.identitys.push(new MWF.widget.O2Process(data, this.node));
  72. if (this.options.type.toLowerCase()==="formfield") this.identitys.push(new MWF.widget.O2FormField(data, this.node));
  73. if (this.options.type.toLowerCase()==="view") this.identitys.push(new MWF.widget.O2View(data, this.node));
  74. if (this.options.type.toLowerCase()==="cmsview") this.identitys.push(new MWF.widget.O2CMSView(data, this.node));
  75. if (this.options.type.toLowerCase()==="queryview") this.identitys.push(new MWF.widget.O2QueryView(data, this.node));
  76. if (this.options.type.toLowerCase()==="querystat") this.identitys.push(new MWF.widget.O2QueryStat(data, this.node));
  77. if (this.options.type.toLowerCase()==="dutyname") this.identitys.push(new MWF.widget.O2Duty(data, this.node));
  78. if (this.options.type.toLowerCase()==="cmsapplication") this.identitys.push(new MWF.widget.O2CMSApplication(data, this.node));
  79. if (this.options.type.toLowerCase()==="cmscategory") this.identitys.push(new MWF.widget.O2CMSCategory(data, this.node));
  80. if (this.options.type.toLowerCase()==="portalfile") this.identitys.push(new MWF.widget.O2File(data, this.node));
  81. if (this.options.type.toLowerCase()==="processfile") this.identitys.push(new MWF.widget.O2File(data, this.node));
  82. if (this.options.type.toLowerCase()==="script") this.identitys.push(new MWF.widget.O2Other(data, this.node));
  83. }.bind(this));
  84. }
  85. }.bind(this));
  86. }
  87. }
  88. },
  89. createAddNode: function(){
  90. this.addNode = new Element("div", {"styles": this.css.addPersonNode}).inject(this.node, "before");
  91. this.addNode.addEvent("click", function(e){
  92. debugger;
  93. var include = [];
  94. if( this.options.type.toLowerCase()==="formfield" ){
  95. if( this.app.process && this.app.process.routes ){
  96. Object.each( this.app.process.routes, function(route){
  97. if(route.data.selectConfig){
  98. var array = JSON.parse( route.data.selectConfig );
  99. ( array || [] ).each( function( d ){
  100. include.push( { name : d.name, id : d.id, form: "routeSelectConfig" } );
  101. })
  102. }
  103. });
  104. }
  105. }
  106. var selecteds = [];
  107. this.identitys.each(function(id){selecteds.push(id.data)});
  108. var options = {
  109. "type": (this.options.type.toLowerCase()==="dutyname") ? "duty" : this.options.type,
  110. "application": this.options.application,
  111. "fieldType": this.options.fieldType,
  112. "count": (this.options.type.toLowerCase()==="duty")? 1: this.options.count,
  113. "values": selecteds,
  114. "zIndex": 20000,
  115. "isImage": this.options.isImage,
  116. "include" : include,
  117. "onComplete": function(items){
  118. this.identitys = [];
  119. if (this.options.type.toLowerCase()!=="duty") this.node.empty();
  120. MWF.require("MWF.widget.O2Identity", function(){
  121. items.each(function(item){
  122. if (this.options.type.toLowerCase()==="identity") this.identitys.push(new MWF.widget.O2Identity(item.data, this.node));
  123. if (this.options.type.toLowerCase()==="person") this.identitys.push(new MWF.widget.O2Person(item.data, this.node));
  124. if (this.options.type.toLowerCase()==="unit") this.identitys.push(new MWF.widget.O2Unit(item.data, this.node));
  125. if (this.options.type.toLowerCase()==="group") this.identitys.push(new MWF.widget.O2Group(item.data, this.node));
  126. if (this.options.type.toLowerCase()==="application") this.identitys.push(new MWF.widget.O2Application(item.data, this.node));
  127. if (this.options.type.toLowerCase()==="process") this.identitys.push(new MWF.widget.O2Process(item.data, this.node));
  128. if (this.options.type.toLowerCase()==="cmsapplication") this.identitys.push(new MWF.widget.O2CMSApplication(item.data, this.node));
  129. if (this.options.type.toLowerCase()==="cmscategory") this.identitys.push(new MWF.widget.O2CMSCategory(item.data, this.node));
  130. if (this.options.type.toLowerCase()==="formfield") this.identitys.push(new MWF.widget.O2FormField(item.data, this.node));
  131. if (this.options.type.toLowerCase()==="view") this.identitys.push(new MWF.widget.O2View(item.data, this.node));
  132. if (this.options.type.toLowerCase()==="cmsview") this.identitys.push(new MWF.widget.O2CMSView(item.data, this.node));
  133. if (this.options.type.toLowerCase()==="queryview") this.identitys.push(new MWF.widget.O2QueryView(item.data, this.node));
  134. if (this.options.type.toLowerCase()==="querystat") this.identitys.push(new MWF.widget.O2QueryStat(item.data, this.node));
  135. if (this.options.type.toLowerCase()==="dutyname") this.identitys.push(new MWF.widget.O2Duty(item.data, this.node));
  136. if (this.options.type.toLowerCase()==="portalfile") this.identitys.push(new MWF.widget.O2File(item.data, this.node));
  137. if (this.options.type.toLowerCase()==="processfile") this.identitys.push(new MWF.widget.O2File(item.data, this.node));
  138. if (this.options.type.toLowerCase()==="script") this.identitys.push(new MWF.widget.O2Other(item.data, this.node));
  139. }.bind(this));
  140. if (this.options.type.toLowerCase()==="duty") {
  141. items.each(function(item){
  142. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this, item.data, this.node, 20000);
  143. }.bind(this));
  144. }
  145. this.fireEvent("change", [this.identitys]);
  146. }.bind(this));
  147. }.bind(this)
  148. };
  149. if( this.options.title )options.title = this.options.title;
  150. var selector = new MWF.O2Selector(this.app.content, options);
  151. }.bind(this));
  152. }
  153. });
  154. MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput = Class({
  155. Implements: [Events],
  156. initialize: function(selector, data, node, zIndex){
  157. this.itemNode = $(node);
  158. this.data = data;
  159. this.isNew = false;
  160. this.selector = selector;
  161. this.css = this.selector.css;
  162. this.app = this.selector.app;
  163. this.zIndex = zIndex;
  164. this.selector.identitys = [];
  165. this.referenceList = [];
  166. this.load();
  167. },
  168. load: function(){
  169. this.css.dutyMaskNode["z-index"] = this.zIndex;
  170. this.app.content.mask({
  171. "destroyOnHide": true,
  172. "style": this.css.dutyMaskNode,
  173. });
  174. this.node = new Element("div", {
  175. "styles": this.css.dutyInputArea
  176. });
  177. this.titleNode = new Element("div", {
  178. "styles": this.css.dutyTitleNode
  179. }).inject(this.node);
  180. this.titleActionNode = new Element("div", {
  181. "styles": this.css.dutyTitleActionNode
  182. }).inject(this.titleNode);
  183. this.titleTextNode = new Element("div", {
  184. "styles": this.css.dutyTitleTextNode,
  185. "text": this.app.lp.dutyInputTitle
  186. }).inject(this.titleNode);
  187. this.contentNode = new Element("div", {
  188. "styles": this.css.dutyContentNode
  189. }).inject(this.node);
  190. this.loadContent();
  191. this.actionNode = new Element("div", {
  192. "styles": this.css.dutyActionNode
  193. }).inject(this.node);
  194. this.actionNode.setStyle("text-align", "center");
  195. this.loadAction();
  196. this.node.setStyle("z-index", this.zIndex.toInt()+1);
  197. this.node.inject(this.app.content);
  198. this.node.position({
  199. relativeTo: this.app.content,
  200. position: "center",
  201. edge: "center"
  202. });
  203. var size = this.app.content.getSize();
  204. var nodeSize = this.node.getSize();
  205. this.node.makeDraggable({
  206. "handle": this.titleNode,
  207. "limit": {
  208. "x": [0, size.x-nodeSize.x],
  209. "y": [0, size.y-nodeSize.y]
  210. }
  211. });
  212. this.setEvent();
  213. },
  214. setEvent: function(){
  215. if (this.titleActionNode){
  216. this.titleActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  217. }
  218. this.okActionNode.addEvent("click", function(){
  219. this.selectDuty();
  220. this.close();
  221. }.bind(this));
  222. this.cancelActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  223. },
  224. selectDuty: function(){
  225. var code = this.scriptEditor.editor.editor.getValue();
  226. this.data.code = code;
  227. if (!this.item){
  228. var dutyItem = new MWF.widget.O2Duty(this.data, this.itemNode, {
  229. "canRemove": true,
  230. "onRemove": function(item, e){
  231. var _self = item;
  232. var text = item.selector.app.lp.deleteDutyText.replace(/{duty}/g, item.data.name);
  233. item.selector.app.confirm("warm", e, item.selector.app.lp.deleteDutyTitle, text, 300, 120, function(){
  234. _self.selector.identitys.erase(item);
  235. _self.selector.fireEvent("removeDuty", [item]);
  236. this.close();
  237. }, function(){
  238. this.close();
  239. });
  240. e.stopPropagation();
  241. }.bind(this)
  242. });
  243. dutyItem.selector = this.selector;
  244. this.selector.identitys.push(dutyItem);
  245. this.selector.fireEvent("change", [this.selector.identitys]);
  246. }else{
  247. this.selector.identitys.push(this.item);
  248. this.selector.fireEvent("change", [this.selector.identitys]);
  249. }
  250. },
  251. "close": function(){
  252. this.node.destroy();
  253. this.app.content.unmask();
  254. MWF.release(this);
  255. delete this;
  256. },
  257. loadAction: function(){
  258. this.okActionNode = new Element("button", {
  259. "styles": this.css.dutyOkActionNode,
  260. "text": "确 定"
  261. }).inject(this.actionNode);
  262. this.cancelActionNode = new Element("button", {
  263. "styles": this.css.dutyCancelActionNode,
  264. "text": "取 消"
  265. }).inject(this.actionNode);
  266. },
  267. loadContent: function(){
  268. this.contentAreaNode= new Element("div", {"styles": this.css.dutyContentAreaNode}).inject(this.contentNode);
  269. var text = this.app.lp.dutyInput.replace(/{duty}/g, this.data.name);
  270. this.textNode = new Element("div", {"styles": this.css.dutyTextNode, "text": text}).inject(this.contentAreaNode);
  271. this.referenceAreaNode = new Element("div", {"styles": this.css.dutyReferenceAreaNode}).inject(this.contentAreaNode);
  272. this.scriptAreaNode = new Element("div", {"styles": this.css.dutyScriptAreaNode}).inject(this.contentAreaNode);
  273. this.createScriptNode();
  274. // this.areaNode = new Element("div", {"styles": this.css.dutyAreaNode}).inject(this.contentAreaNode);
  275. // this.referenceAreaNode = new Element("div", {"styles": this.css.dutyReferenceAreaNode}).inject(this.areaNode);
  276. // this.contentAreaNode = new Element("div", {"styles": this.css.dutyContentAreaNode}).inject(this.areaNode);
  277. this.createReference(this.app.lp.creatorUnit, "return this.workContext.getWork().creatorUnitDn || this.workContext.getWork().creatorUnit;");
  278. this.createReference(this.app.lp.currentUnit, "return this.workContext.getTask().unitDn || this.workContext.getTask().unit;");
  279. this.createReference(this.app.lp.selectUnit, "", function(){
  280. var options = {
  281. "type": "unit",
  282. "count": 0,
  283. "onComplete": function(items){
  284. var arr = [];
  285. items.each(function (item) {
  286. arr.push("\"" + item.data.distinguishedName + "\"");
  287. })
  288. if(arr.length>1){
  289. this.scriptEditor.editor.editor.setValue("return ["+arr.join(",")+"];");
  290. }else{
  291. this.scriptEditor.editor.editor.setValue("return "+arr.join()+";");
  292. }
  293. }.bind(this)
  294. };
  295. new MWF.O2Selector(this.node, options);
  296. }.bind(this));
  297. // this.createReference(this.app.lp.scriptUnit, "return this.workContext.getWork().creatorDepartment;");
  298. // this.createReference(this.app.lp.creatorCompany, "return this.workContext.getWork().creatorCompany");
  299. // this.createReference(this.app.lp.creatorDepartment, "return this.workContext.getWork().creatorDepartment");
  300. // this.createReference(this.app.lp.currentCompany, "return this.workContext.getTask().company");
  301. // this.createReference(this.app.lp.currentDepartment, "return this.workContext.getTask().department");
  302. },
  303. createScriptNode: function(){
  304. this.scriptNode = new Element("div", {"styles": this.css.dutyScriptNode}).inject(this.scriptAreaNode);
  305. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText", function(){
  306. this.scriptEditor = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode, "", this.app, {
  307. "height": 316,
  308. "maskNode": this.app.content,
  309. "maxObj": this.app.content
  310. //"onChange": function(code){
  311. // _self.data[node.get("name")] = code;
  312. //}
  313. });
  314. this.scriptEditor.loadEditor(function(){
  315. if (this.data.code) this.scriptEditor.editor.editor.setValue(this.data.code);
  316. }.bind(this));
  317. }.bind(this));
  318. },
  319. createReference: function(text, code, action){
  320. var node = new Element("div", {"styles": this.css.dutyReferenceItemNode}).inject(this.referenceAreaNode);
  321. node.set("text", text);
  322. node.store("code", code);
  323. node.store("action", action);
  324. var css = this.css.dutyReferenceItemNode;
  325. var overcss = this.css.dutyReferenceItemNode_over;
  326. var downcss = this.css.dutyReferenceItemNode_down;
  327. var _self = this;
  328. node.addEvents({
  329. "mouseover": function(){if (!this.retrieve("checked")) this.setStyles(overcss);},
  330. "mouseout": function(){if (!this.retrieve("checked")) this.setStyles(css);},
  331. "mousedown": function(){if (!this.retrieve("checked")) this.setStyles(downcss);},
  332. "mouseup": function(){if (!this.retrieve("checked")) this.setStyles(overcss);},
  333. "click": function(){
  334. // _self.checkedReference(this);
  335. var action = node.retrieve("action");
  336. if (action){
  337. action();
  338. }else{
  339. var code = this.retrieve("code");
  340. var value = _self.scriptEditor.editor.editor.getValue();
  341. if (!value){
  342. _self.scriptEditor.editor.editor.setValue(code);
  343. }else{
  344. value = value + "\n" +code;
  345. _self.scriptEditor.editor.editor.setValue(value);
  346. }
  347. }
  348. }
  349. });
  350. //this.referenceList.push(node);
  351. },
  352. // checkedReference: function(node){
  353. // this.referenceList.each(function(node){
  354. // this.unCheckedReference(node);
  355. // }.bind(this));
  356. // node.setStyles(this.css.dutyReferenceItemNode_down);
  357. // node.store("checked", true);
  358. // action = node.retrieve("action");
  359. // if (action) action();
  360. // },
  361. // unCheckedReference: function(node){
  362. // node.setStyles(this.css.dutyReferenceItemNode);
  363. // node.store("checked", false);
  364. // }
  365. });
  366. MWF.widget.O2Duty = new Class({
  367. Extends: MWF.widget.O2Group,
  368. getPersonData: function(){
  369. },
  370. setEvent: function(){
  371. this.node.addEvent("click", function(){
  372. this.modifyDuty();
  373. }.bind(this));
  374. },
  375. modifyDuty: function(){
  376. var dutyInput = new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this.selector, this.data, this.selector.node, 20000);
  377. dutyInput.item = this;
  378. }
  379. });