Starter.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. MWF.require("MWF.widget.Mask", null, false);
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.Index = MWF.xApplication.cms.Index || {};
  4. MWF.xApplication.cms.Index.Starter = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "ignoreDrafted" : false
  10. },
  11. initialize: function(columnData, categoryData, app, options){
  12. this.setOptions(options);
  13. this.path = "/x_component_cms_Index/$Starter/";
  14. this.cssPath = "/x_component_cms_Index/$Starter/"+this.options.style+"/css.wcss";
  15. this._loadCss();
  16. MWF.xDesktop.requireApp("cms.Index", "$Starter."+MWF.language, null, false);
  17. this.lp = MWF.xApplication.cms.Index.Starter.lp;
  18. this.columnData = columnData;
  19. this.categoryData = categoryData;
  20. this.app = app;
  21. },
  22. load: function( ){
  23. if( this.options.ignoreDrafted ){
  24. this._load();
  25. this.fireEvent( "postLoad" );
  26. }else if(this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  27. this._load();
  28. this.fireEvent( "postLoad" );
  29. }else{
  30. var fielter = {
  31. "categoryIdList": [this.categoryData.id ],
  32. "creatorList": [layout.desktop.session.user.distinguishedName]
  33. };
  34. this.getDocumentAction( function(){
  35. this.documentAction.listDraftNext("(0)", 1, fielter, function(json){
  36. if( json.data.length > 0 ){
  37. this._openDocument(json.data[0].id);
  38. this.fireEvent( "postLoad" );
  39. }else{
  40. this._load();
  41. this.fireEvent( "postLoad" );
  42. }
  43. }.bind(this));
  44. }.bind(this));
  45. }
  46. },
  47. _load: function(){
  48. this.createMarkNode();
  49. this.createAreaNode();
  50. this.createStartNode();
  51. this.areaNode.inject(this.markNode, "after");
  52. this.areaNode.fade("in");
  53. $("form_startSubject").focus();
  54. this.setStartNodeSize();
  55. this.setStartNodeSizeFun = this.setStartNodeSize.bind(this);
  56. this.app.addEvent("resize", this.setStartNodeSizeFun);
  57. },
  58. _openDocument: function(id,el){
  59. var _self = this;
  60. var appId = "cms.Document"+id;
  61. if (_self.app.desktop.apps[appId]){
  62. _self.app.desktop.apps[appId].setCurrent();
  63. }else {
  64. var options = {
  65. "readonly" :false,
  66. "documentId": id,
  67. "appId": appId,
  68. "postPublish" : function(){
  69. //if(_self.creater.view )_self.creater.view.reload();
  70. this.fireEvent( "postPublish" );
  71. }.bind(this)
  72. };
  73. this.app.desktop.openApplication(el, "cms.Document", options);
  74. }
  75. },
  76. createMarkNode: function(){
  77. this.markNode = new Element("div#mark", {
  78. "styles": this.css.markNode,
  79. "events": {
  80. "mouseover": function(e){e.stopPropagation();},
  81. "mouseout": function(e){e.stopPropagation();}
  82. }
  83. }).inject(this.app.content);
  84. },
  85. createAreaNode: function(){
  86. this.areaNode = new Element("div#area", {
  87. "styles": this.css.areaNode
  88. });
  89. },
  90. createStartNode: function(){
  91. this.createNode = new Element("div", {
  92. "styles": this.css.createNode
  93. }).inject(this.areaNode);
  94. this.createNewNode = new Element("div", {
  95. "styles": this.css.createNewNode
  96. }).inject(this.createNode);
  97. this.formNode = new Element("div", {
  98. "styles": this.css.formNode
  99. }).inject(this.createNode);
  100. var categoryName = this.categoryData.name || this.categoryData.categoryName;
  101. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  102. "<tr><td colSpan=\"2\" style=\"height: 60px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  103. this.lp.start+" - "+categoryName+"</td></tr>" +
  104. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.department+":</td>" +
  105. "<td style=\"; text-align: left;\" id=\"form_startDepartment\"></td></tr>" +
  106. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.identity+":</td>" +
  107. "<td style=\"; text-align: left;\"><div id=\"form_startIdentity\"></div></td></tr>" +
  108. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.date+":</td>" +
  109. "<td style=\"; text-align: left;\"><div id=\"form_startDate\"></div></td></tr>" +
  110. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.subject+":</td>" +
  111. "<td style=\"; text-align: left;\"><input type=\"text\" id=\"form_startSubject\" " +
  112. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  113. "height: 26px;\"/></td></tr>" +
  114. "</table>";
  115. this.formNode.set("html", html);
  116. this.setStartFormContent();
  117. this.cancelActionNode = new Element("div", {
  118. "styles": this.css.cancelActionNode,
  119. "text": this.lp.cancel
  120. }).inject(this.formNode);
  121. this.startOkActionNode = new Element("div", {
  122. "styles": this.css.startOkActionNode,
  123. "text": this.lp.ok
  124. }).inject(this.formNode);
  125. this.cancelActionNode.addEvent("click", function(e){
  126. this.cancelStart(e);
  127. }.bind(this));
  128. this.startOkActionNode.addEvent("click", function(e){
  129. this.okStart(e);
  130. }.bind(this));
  131. },
  132. setStartFormContent: function(){
  133. this.dateArea = this.formNode.getElementById("form_startDate");
  134. var d = new Date();
  135. this.dateArea.set("text", d.format("%Y-%m-%d %H:%M"));
  136. this.departmentSelArea = this.formNode.getElementById("form_startDepartment");
  137. this.identityArea = this.formNode.getElementById("form_startIdentity");
  138. //this.getOrgAction(function(){
  139. //if (!this.app.desktop.user.id){
  140. // this.orgAction.listPersonByKey(function(json){
  141. // if (json.data.length) this.app.desktop.user.id = json.data[0].id
  142. // this.loadDepartments();
  143. // }.bind(this), null, this.app.desktop.user.name);
  144. //}else{
  145. // this.loadDepartments();
  146. //}
  147. this.loadDepartments();
  148. //}.bind(this));
  149. },
  150. loadDepartments: function(){
  151. //if (this.app.desktop.session.user.name){
  152. // this.orgAction.listIdentityByPerson(function(json){
  153. // var selected = (json.data.length==1) ? true : false;
  154. // json.data.each(function(id){
  155. // var departSel = new MWF.xApplication.cms.Index.Starter.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  156. // if (selected) departSel.selected();
  157. // }.bind(this));
  158. // }.bind(this), null, this.app.desktop.session.user.name)
  159. //}
  160. MWF.Actions.get("x_organization_assemble_personal").getPerson(function(json){
  161. var identities1 = (json.data && json.data.woIdentityList) ? json.data.woIdentityList : [];
  162. var identities = [];
  163. identities1.each( function(i){
  164. if( i.distinguishedName )identities.push(i);
  165. }.bind(this));
  166. var selected = (identities.length==1) ? true : false;
  167. identities.each(function(id){
  168. var departSel = new MWF.xApplication.cms.Index.Starter.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  169. if (selected) departSel.selected();
  170. }.bind(this));
  171. }.bind(this), null )
  172. },
  173. //getOrgAction: function(callback){
  174. // if (!this.orgAction){
  175. // MWF.require("MWF.xAction.org.express.RestActions", function(){
  176. // this.orgAction = new MWF.xAction.org.express.RestActions();
  177. // if (callback) callback();
  178. // }.bind(this));
  179. // }else{
  180. // if (callback) callback();
  181. // }
  182. //},
  183. setStartNodeSize: function(){
  184. var size = this.app.content.getSize();
  185. var allSize = this.app.content.getSize();
  186. this.markNode.setStyles({
  187. "width": ""+allSize.x+"px",
  188. "height": ""+allSize.y+"px"
  189. });
  190. this.areaNode.setStyles({
  191. "width": ""+size.x+"px",
  192. "height": ""+size.y+"px"
  193. });
  194. var hY = size.y*0.8;
  195. var mY = size.y*0.2/2;
  196. if( hY > 500 )hY = 500;
  197. this.createNode.setStyles({
  198. "height": ""+hY+"px",
  199. "margin-top": ""+mY+"px"
  200. });
  201. var iconSize = this.createNewNode.getSize();
  202. var formHeight = hY*0.7;
  203. if (formHeight>250) formHeight = 250;
  204. var formMargin = hY*0.3/2-iconSize.y;
  205. this.formNode.setStyles({
  206. "height": ""+formHeight+"px",
  207. "margin-top": ""+formMargin+"px"
  208. });
  209. },
  210. cancelStart: function(e){
  211. var _self = this;
  212. if ($("form_startSubject").get("value")){
  213. this.app.confirm("warn", e, this.lp.start_cancel_title, this.lp.start_cancel, "320px", "100px", function(){
  214. _self.markNode.destroy();
  215. _self.areaNode.destroy();
  216. this.close();
  217. },function(){
  218. this.close();
  219. }, null, this.app.content);
  220. }else{
  221. this.markNode.destroy();
  222. this.areaNode.destroy();
  223. }
  224. },
  225. okStart: function(){
  226. if( this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  227. this._createProcessDocument();
  228. }else{
  229. this._createDocument();
  230. }
  231. },
  232. _createDocument: function(e){
  233. var title = $("form_startSubject").get("value");
  234. this.getDocumentAction();
  235. var data = {
  236. "id" : this.documentAction.getUUID(),
  237. "isNewDocument" : true,
  238. "title": title,
  239. "creatorIdentity": this.identityArea.get("value"),
  240. "appId" :this.categoryData.appId,
  241. "categoryId" : this.categoryData.id,
  242. "form" : this.categoryData.formId,
  243. "formName" :this.categoryData.formName,
  244. "docStatus" : "draft",
  245. "categoryName" : this.categoryData.name || this.categoryData.categoryName,
  246. "categoryAlias" : this.categoryData.alias || this.categoryData.categoryAlias,
  247. "attachmentList" : []
  248. };
  249. if (!data.title){
  250. $("form_startSubject").setStyle("border-color", "red");
  251. $("form_startSubject").focus();
  252. this.app.notice(this.lp.inputSubject, "error");
  253. }else if (!data.creatorIdentity){
  254. this.departmentSelArea.setStyle("border-color", "red");
  255. this.app.notice(this.lp.selectStartId, "error");
  256. }else{
  257. this.mask = new MWF.widget.Mask({"style": "desktop"});
  258. this.mask.loadNode(this.areaNode);
  259. this.getDocumentAction(function(){
  260. this.documentAction.addDocument( data, function(json){
  261. this.mask.hide();
  262. this.markNode.destroy();
  263. this.areaNode.destroy();
  264. this._openDocument( json.data.id );
  265. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  266. //this.app.refreshAll();
  267. this.app.notice(this.lp.Started, "success");
  268. // this.app.processConfig();
  269. }.bind(this), null);
  270. }.bind(this));
  271. }
  272. },
  273. getDocumentAction: function(callback){
  274. if (!this.documentAction){
  275. //MWF.xDesktop.requireApp("cms.Index", "Actions.RestActions", function(){
  276. this.documentAction = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Index.Actions.RestActions();
  277. if (callback) callback();
  278. //}.bind(this));
  279. }else{
  280. if (callback) callback();
  281. }
  282. },
  283. _createProcessDocument:function(e){
  284. var title = $("form_startSubject").get("value");
  285. var processId = this.categoryData.workflowFlag;
  286. var data = {
  287. "title":$("form_startSubject").get("value"),
  288. "identity": this.identityArea.get("value")
  289. };
  290. if (!data.title){
  291. $("form_startSubject").setStyle("border-color", "red");
  292. $("form_startSubject").focus();
  293. this.app.notice(this.lp.inputSubject, "error");
  294. }else if (!data.identity){
  295. this.departmentSelArea.setStyle("border-color", "red");
  296. this.app.notice(this.lp.selectStartId, "error");
  297. }else{
  298. var workData = {
  299. cmsDocument : {
  300. "isNewDocument" : true,
  301. "title": title,
  302. "creatorIdentity": data.identity,
  303. "appId" :this.categoryData.appId,
  304. "categoryId" : this.categoryData.id,
  305. //"form" : this.categoryData.formId,
  306. //"formName" :this.categoryData.formName,
  307. "docStatus" : "draft",
  308. "categoryName" : this.categoryData.name || this.categoryData.categoryName,
  309. "categoryAlias" : this.categoryData.alias || this.categoryData.categoryAlias,
  310. "createTime": new Date().format("db"),
  311. "attachmentList" : []
  312. }
  313. };
  314. this.mask = new MWF.widget.Mask({"style": "desktop"});
  315. this.mask.loadNode(this.areaNode);
  316. this.getDocumentAction(function(){
  317. MWF.Actions.get("x_processplatform_assemble_surface").startWork( function( json ){
  318. this.mask.hide();
  319. this.markNode.destroy();
  320. this.areaNode.destroy();
  321. this.afterStartProcess( json.data, data.title, this.categoryData.workflowName, workData );
  322. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  323. //this.app.refreshAll();
  324. this.app.notice(this.lp.Started, "success");
  325. }.bind(this), null, processId, data)
  326. }.bind(this));
  327. }
  328. },
  329. afterStartProcess: function(data, title, processName, workData){
  330. var workInfors = [];
  331. var currentTask = [];
  332. data.each(function(work){
  333. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  334. workInfors.push(this.getStartWorkInforObj(work));
  335. }.bind(this));
  336. var workId = currentTask[0];
  337. MWF.Actions.get("x_processplatform_assemble_surface").saveData(function(){
  338. if (currentTask.length==1){
  339. var options = {"workId": workId};
  340. this.app.desktop.openApplication(null, "process.Work", options);
  341. this.createStartWorkResault(workInfors, title, processName, false);
  342. }else{
  343. this.createStartWorkResault(workInfors, title, processName, true);
  344. }
  345. }.bind(this), null, workId, workData)
  346. },
  347. getStartWorkInforObj: function(work){
  348. var users = [];
  349. var currentTask = "";
  350. work.taskList.each(function(task, idx){
  351. users.push(task.person+"("+task.department + ")");
  352. if (work.currentTaskIndex==idx) currentTask = task.id;
  353. }.bind(this));
  354. return {"activity": work.fromActivityName, "users": users, "currentTask": currentTask};
  355. },
  356. createStartWorkResault: function(workInfors, title, processName, isopen){
  357. var content = "";
  358. workInfors.each(function(infor){
  359. content += "<div><b>"+this.lp.nextActivity+"<font style=\"color: #ea621f\">"+infor.activity+"</font>, "+this.lp.nextUser+"<font style=\"color: #ea621f\">"+infor.users.join(", ")+"</font></b>";
  360. if (infor.currentTask && isopen){
  361. content += "&nbsp;&nbsp;&nbsp;&nbsp;<span value=\""+infor.currentTask+"\">"+this.lp.deal+"</span></div>";
  362. }else{
  363. content += "</div>";
  364. }
  365. }.bind(this));
  366. var msg = {
  367. "subject": this.lp.processStarted,
  368. "content": "<div>"+this.lp.processStartedMessage+"“["+processName+"]"+title+"”</div>"+content
  369. };
  370. var tooltip = layout.desktop.message.addTooltip(msg);
  371. var item = layout.desktop.message.addMessage(msg);
  372. this.setStartWorkResaultAction(tooltip);
  373. this.setStartWorkResaultAction(item);
  374. },
  375. setStartWorkResaultAction: function(item){
  376. var node = item.node.getElements("span");
  377. node.setStyles(this.css.dealStartedWorkAction);
  378. var _self = this;
  379. node.addEvent("click", function(e){
  380. var options = {"taskId": this.get("value")};
  381. _self.app.desktop.openApplication(e, "process.Work", options);
  382. });
  383. }
  384. });
  385. MWF.xApplication.cms.Index.Starter.DepartmentSel = new Class({
  386. initialize: function(data, starter, container, idArea){
  387. this.data = data;
  388. this.starter = starter;
  389. this.container = container;
  390. this.idArea = idArea;
  391. this.css = this.starter.css;
  392. this.isSelected = false;
  393. this.load();
  394. },
  395. load: function(){
  396. this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  397. //this.starter.orgAction.getDepartmentByIdentity(function(department){
  398. // this.node.set("text", department.data.name);
  399. //}.bind(this), null, this.data.name);
  400. var unit = this.data.woUnit ? this.data.woUnit.name : this.lp.unnamedUnit;
  401. this.node.set("text",this.data.woUnit.name);
  402. this.node.addEvents({
  403. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  404. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  405. "click": function(){
  406. this.selected();
  407. }.bind(this)
  408. });
  409. },
  410. selected: function(){
  411. if (!this.isSelected){
  412. if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  413. this.node.setStyles(this.css.departSelNode_selected);
  414. this.isSelected = true;
  415. this.starter.currentDepartment = this;
  416. this.idArea.set({
  417. "text": this.data.name,
  418. "value": this.data.distinguishedName
  419. });
  420. }
  421. },
  422. unSelected: function(){
  423. if (this.isSelected){
  424. if (this.starter.currentDepartment) this.starter.currentDepartment = null;;
  425. this.node.setStyles(this.css.departSelNode);
  426. this.isSelected = false;
  427. }
  428. }
  429. });