PersonSelector.js 20 KB

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