PersonSelector.js 21 KB

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