PersonSelector.js 21 KB

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