Starter.js 22 KB

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