PersonSelector.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. MWF.xApplication.cms.QueryViewDesigner = MWF.xApplication.cms.QueryViewDesigner || {};
  2. MWF.xApplication.cms.QueryViewDesigner.widget = MWF.xApplication.cms.QueryViewDesigner.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.widget.Category = new Class({
  7. Extends: MWF.widget.Department
  8. });
  9. MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector = new Class({
  10. Implements: [Options, Events],
  11. Extends: MWF.widget.Common,
  12. options: {
  13. "style": "default",
  14. "type": "identity",
  15. "names": []
  16. },
  17. initialize: function(node, app, options){
  18. this.setOptions(options);
  19. this.node = $(node);
  20. this.app = app;
  21. this.path = "/x_component_cms_QueryViewDesigner/widget/$PersonSelector/";
  22. this.cssPath = "/x_component_cms_QueryViewDesigner/widget/$PersonSelector/"+this.options.style+"/css.wcss";
  23. this._loadCss();
  24. this.identitys = [];
  25. this.restActions = new MWF.xAction.org.express.RestActions();
  26. this.name = this.node.get("name");
  27. this.load();
  28. },
  29. load: function(data){
  30. this.node.setStyles(this.css.node);
  31. this.createAddNode();
  32. this.loadIdentitys();
  33. },
  34. loadIdentitys: function(){
  35. var explorer = {
  36. "actions": this.restActions,
  37. "app": {
  38. "lp": this.app.lp
  39. }
  40. };
  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.Duty(d, this.node, explorer, true, function(e){
  46. var _self = this;
  47. var text = this.selector.app.lp.deleteDutyText.replace(/{duty}/g, this.data.name);
  48. this.selector.app.confirm("warm", e, this.selector.app.lp.deleteDutyTitle, text, 300, 120, function(){
  49. _self.selector.fireEvent("removeDuty", [_self]);
  50. this.close();
  51. }, function(){
  52. this.close();
  53. });
  54. e.stopPropagation();
  55. });
  56. dutyItem.selector = this;
  57. dutyItem.explorer = explorer;
  58. this.identitys.push(dutyItem);
  59. }.bind(this));
  60. }else{
  61. this.options.names.each(function(name){
  62. MWF.require("MWF.widget.Identity", function(){
  63. if (this.options.type.toLowerCase()=="identity") this.identitys.push(new MWF.widget.Identity({"name": name.name, "id": name.id}, this.node, explorer));
  64. if (this.options.type.toLowerCase()=="department") this.identitys.push(new MWF.widget.Department({"name": name.name, "id": name.id}, this.node, explorer));
  65. if (this.options.type.toLowerCase()=="company") this.identitys.push(new MWF.widget.Company({"name": name.name, "id": name.id}, this.node, explorer));
  66. if (this.options.type.toLowerCase()=="person") this.identitys.push(new MWF.widget.Person({"name": name.name, "id": name.id}, this.node, explorer));
  67. if (this.options.type.toLowerCase()=="application") this.identitys.push(new MWF.widget.Application({"name": name.name, "id": name.id}, this.node, explorer));
  68. if (this.options.type.toLowerCase()=="category") this.identitys.push(new MWF.widget.Category({"name": name.name, "id": name.id}, this.node, explorer));
  69. if (this.options.type.toLowerCase()=="formfield") this.identitys.push(new MWF.widget.FormField({"name": name, "id": name}, this.node, explorer));
  70. }.bind(this));
  71. }.bind(this));
  72. }
  73. }
  74. },
  75. createAddNode: function(){
  76. this.addNode = new Element("div", {"styles": this.css.addPersonNode}).inject(this.node, "before");
  77. this.addNode.addEvent("click", function(e){
  78. var selecteds = [];
  79. this.identitys.each(function(id){selecteds.push(id.data.id)});
  80. var explorer = {
  81. "actions": this.restActions,
  82. "app": {
  83. "lp": this.app.lp
  84. }
  85. }
  86. var type = this.options.type;
  87. if( type == "application" ){
  88. type = "CMSApplication";
  89. }else if( type == "category" ){
  90. type = "CMSCategory";
  91. }else if( type == "formField" ){
  92. type = "CMSFormField";
  93. }
  94. var options = {
  95. "type": type,
  96. "application": this.options.application,
  97. "fieldType": this.options.fieldType,
  98. "count": (this.options.type.toLowerCase()=="duty")? 1: 0,
  99. "values": selecteds,
  100. "zIndex": 20000,
  101. "form" : this.options.form,
  102. "onComplete": function(items){
  103. this.identitys = [];
  104. if (this.options.type.toLowerCase()!="duty") this.node.empty();
  105. MWF.require("MWF.widget.Identity", function(){
  106. items.each(function(item){
  107. if (this.options.type.toLowerCase()=="identity") this.identitys.push(new MWF.widget.Identity(item.data, this.node, explorer));
  108. if (this.options.type.toLowerCase()=="department") this.identitys.push(new MWF.widget.Department(item.data, this.node, explorer));
  109. if (this.options.type.toLowerCase()=="company") this.identitys.push(new MWF.widget.Company(item.data, this.node, explorer));
  110. if (this.options.type.toLowerCase()=="person") this.identitys.push(new MWF.widget.Person(item.data, this.node, explorer));
  111. if (this.options.type.toLowerCase()=="application") this.identitys.push(new MWF.widget.Application(item.data, this.node, explorer));
  112. if (this.options.type.toLowerCase()=="category") this.identitys.push(new MWF.widget.Category(item.data, this.node, explorer));
  113. if (this.options.type.toLowerCase()=="formfield") this.identitys.push(new MWF.widget.FormField(item.data, this.node, explorer));
  114. }.bind(this));
  115. if (this.options.type.toLowerCase()=="duty") {
  116. items.each(function(item){
  117. new MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector.DutyInput(this, item.data, this.node, explorer, 20000);
  118. }.bind(this));
  119. }
  120. this.fireEvent("change", [this.identitys]);
  121. }.bind(this));
  122. }.bind(this)
  123. };
  124. var selector = new MWF.OrgSelector(this.app.content, options);
  125. }.bind(this));
  126. }
  127. });
  128. MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector.DutyInput = Class({
  129. Implements: [Events],
  130. initialize: function(selector, data, node, explorer, zIndex){
  131. this.itemNode = $(node);
  132. this.data = data;
  133. this.isNew = false;
  134. this.selector = selector;
  135. this.css = this.selector.css;
  136. this.app = this.selector.app;
  137. this.explorer = explorer;
  138. this.zIndex = zIndex;
  139. this.selector.identitys = [];
  140. this.load();
  141. },
  142. load: function(){
  143. this.css.dutyMaskNode["z-index"] = this.zIndex;
  144. this.app.content.mask({
  145. "destroyOnHide": true,
  146. "style": this.css.dutyMaskNode,
  147. });
  148. this.node = new Element("div", {
  149. "styles": this.css.dutyInputArea
  150. });
  151. this.titleNode = new Element("div", {
  152. "styles": this.css.dutyTitleNode
  153. }).inject(this.node);
  154. this.titleActionNode = new Element("div", {
  155. "styles": this.css.dutyTitleActionNode
  156. }).inject(this.titleNode);
  157. this.titleTextNode = new Element("div", {
  158. "styles": this.css.dutyTitleTextNode,
  159. "text": this.app.lp.dutyInputTitle
  160. }).inject(this.titleNode);
  161. this.contentNode = new Element("div", {
  162. "styles": this.css.dutyContentNode
  163. }).inject(this.node);
  164. this.loadContent();
  165. this.actionNode = new Element("div", {
  166. "styles": this.css.dutyActionNode
  167. }).inject(this.node);
  168. this.actionNode.setStyle("text-align", "center");
  169. this.loadAction();
  170. this.node.setStyle("z-index", this.zIndex.toInt()+1);
  171. this.node.inject(this.app.content);
  172. this.node.position({
  173. relativeTo: this.app.content,
  174. position: "center",
  175. edge: "center"
  176. });
  177. var size = this.app.content.getSize();
  178. var nodeSize = this.node.getSize();
  179. this.node.makeDraggable({
  180. "handle": this.titleNode,
  181. "limit": {
  182. "x": [0, size.x-nodeSize.x],
  183. "y": [0, size.y-nodeSize.y]
  184. }
  185. });
  186. this.setEvent();
  187. },
  188. setEvent: function(){
  189. if (this.titleActionNode){
  190. this.titleActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  191. }
  192. this.okActionNode.addEvent("click", function(){
  193. this.selectDuty();
  194. this.close();
  195. }.bind(this));
  196. this.cancelActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  197. },
  198. selectDuty: function(){
  199. var code = this.scriptEditor.editor.editor.getValue();
  200. this.data.code = code;
  201. if (!this.item){
  202. var dutyItem = new MWF.widget.Duty(this.data, this.itemNode, this.explorer, true, function(e){
  203. var _self = this;
  204. var text = this.selector.app.lp.deleteDutyText.replace(/{duty}/g, this.data.name);
  205. this.selector.app.confirm("warm", e, this.selector.app.lp.deleteDutyTitle, text, 300, 120, function(){
  206. _self.selector.fireEvent("removeDuty", [_self]);
  207. this.close();
  208. }, function(){
  209. this.close();
  210. });
  211. e.stopPropagation();
  212. });
  213. dutyItem.selector = this.selector;
  214. dutyItem.explorer = this.explorer;
  215. this.selector.identitys.push(dutyItem);
  216. this.selector.fireEvent("change", [this.selector.identitys]);
  217. }else{
  218. this.selector.identitys.push(this.item);
  219. this.selector.fireEvent("change", [this.selector.identitys]);
  220. }
  221. },
  222. "close": function(){
  223. this.node.destroy();
  224. this.app.content.unmask();
  225. MWF.release(this);
  226. delete this;
  227. },
  228. loadAction: function(){
  229. this.okActionNode = new Element("button", {
  230. "styles": this.css.dutyOkActionNode,
  231. "text": "确 定"
  232. }).inject(this.actionNode);
  233. this.cancelActionNode = new Element("button", {
  234. "styles": this.css.dutyCancelActionNode,
  235. "text": "取 消"
  236. }).inject(this.actionNode);
  237. },
  238. loadContent: function(){
  239. this.contentAreaNode= new Element("div", {"styles": this.css.dutyContentAreaNode}).inject(this.contentNode);
  240. var text = this.app.lp.dutyInput.replace(/{duty}/g, this.data.name);
  241. this.textNode = new Element("div", {"styles": this.css.dutyTextNode, "text": text}).inject(this.contentAreaNode);
  242. this.referenceAreaNode = new Element("div", {"styles": this.css.dutyReferenceAreaNode}).inject(this.contentAreaNode);
  243. this.scriptAreaNode = new Element("div", {"styles": this.css.dutyScriptAreaNode}).inject(this.contentAreaNode);
  244. this.createScriptNode();
  245. this.createReference(this.app.lp.creatorCompany, "return this.workContext.getWork().creatorCompany");
  246. this.createReference(this.app.lp.creatorDepartment, "return this.workContext.getWork().creatorDepartment");
  247. this.createReference(this.app.lp.currentCompany, "return this.workContext.getTask().company");
  248. this.createReference(this.app.lp.currentDepartment, "return this.workContext.getTask().department");
  249. },
  250. createScriptNode: function(){
  251. this.scriptNode = new Element("div", {"styles": this.css.dutyScriptNode}).inject(this.scriptAreaNode);
  252. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText", function(){
  253. this.scriptEditor = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode, "", this.app, {
  254. "height": 316,
  255. "maskNode": this.app.content,
  256. "maxObj": this.app.content
  257. //"onChange": function(code){
  258. // _self.data[node.get("name")] = code;
  259. //}
  260. });
  261. this.scriptEditor.loadEditor(function(){
  262. if (this.data.code) this.scriptEditor.editor.editor.setValue(this.data.code);
  263. }.bind(this));
  264. }.bind(this));
  265. },
  266. createReference: function(text, code){
  267. var node = new Element("div", {"styles": this.css.dutyReferenceItemNode}).inject(this.referenceAreaNode);
  268. node.set("text", text);
  269. node.store("code", code);
  270. var css = this.css.dutyReferenceItemNode;
  271. var overcss = this.css.dutyReferenceItemNode_over;
  272. var downcss = this.css.dutyReferenceItemNode_down;
  273. var _self = this;
  274. node.addEvents({
  275. "mouseover": function(){this.setStyles(overcss);},
  276. "mouseout": function(){this.setStyles(css);},
  277. "mousedown": function(){this.setStyles(downcss);},
  278. "mouseup": function(){this.setStyles(overcss);},
  279. "click": function(){
  280. var code = this.retrieve("code");
  281. var value = _self.scriptEditor.editor.editor.getValue();
  282. if (!value){
  283. _self.scriptEditor.editor.editor.setValue(code);
  284. }else{
  285. value = value + "\n" +code;
  286. _self.scriptEditor.editor.editor.setValue(value);
  287. }
  288. }
  289. });
  290. }
  291. });
  292. MWF.widget.Duty = new Class({
  293. Extends: MWF.widget.Department,
  294. setEvent: function(){
  295. this.node.addEvent("click", function(){
  296. this.modifyDuty();
  297. }.bind(this));
  298. },
  299. modifyDuty: function(){
  300. var dutyInput = new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this.selector, this.data, this.selector.node, this.explorer, 20000);
  301. dutyInput.item = this;
  302. }
  303. });