Newer.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.Index = MWF.xApplication.cms.Index || {};
  4. //MWF.xDesktop.requireApp("cms.Index", "Actions.RestActions", null, false);
  5. MWF.require("MWF.xAction.org.express.RestActions", null, false);
  6. MWF.require("MWF.widget.Mask", null, false);
  7. MWF.xApplication.cms.Index.Newer = new Class({
  8. Extends: MPopupForm,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "popupStyle" : "o2platform",
  13. "width": "850",
  14. "height": "510",
  15. "hasTop": true,
  16. "hasIcon": false,
  17. "hasTopContent" : true,
  18. "hasBottom": false,
  19. //"title": MWF.xApplication.cms.Index.LP.createDocument,
  20. "draggable": true,
  21. "closeAction": true,
  22. "latest" : true,
  23. "ignoreTitle" : false,
  24. "ignoreDrafted" : false,
  25. "selectColumnEnable" : true,
  26. "restrictToColumn" : false,
  27. "documentData" : null,
  28. "identity" : null,
  29. "searchEnable": true,
  30. "zIndex": "",
  31. //autoSave : "",
  32. //saveOnClose : "",
  33. "categoryFlag" : "", //category id or name
  34. "columnFlag" : "",//column id or name
  35. "appFlag" : "" //column id or name
  36. },
  37. initialize: function (columnData, categoryData, app, view, options) {
  38. debugger;
  39. this.path = "../x_component_cms_Index/$Newer/";
  40. this.cssPath = "../x_component_cms_Index/$Newer/"+this.options.style+"/css.wcss";
  41. this._loadCss();
  42. MWF.xDesktop.requireApp("cms.Index", "$Newer.lp."+MWF.language, null, false);
  43. this.lp = MWF.xApplication.cms.Index.Newer.lp;
  44. this.options.title = this.lp.createDocument;
  45. this.orginOptions = {};
  46. if(o2.typeOf(options)==="object"){
  47. this.orginOptions = Object.clone(options);
  48. }
  49. this.setOptions(options);
  50. this.columnData = columnData;
  51. this.categoryData = categoryData;
  52. this.app = app;
  53. this.view = view;
  54. this.container = this.app.content;
  55. if( !this.columnData ){
  56. this.initData();
  57. }
  58. this.parseConfig();
  59. this.documentAction = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Index.Actions.RestActions();
  60. //this.orgAction = new MWF.xAction.org.express.RestActions();
  61. },
  62. initData : function(){
  63. var appId = this.options.appFlag || this.options.columnFlag;
  64. if( !this.columnData && appId){
  65. MWF.Actions.get("x_cms_assemble_control").getColumn( appId, function( json ){
  66. this.columnData = json.data
  67. }.bind(this), null, false)
  68. }
  69. var categoryId = this.options.categoryFlag;
  70. if( !this.categoryData && categoryId ){
  71. MWF.Actions.get("x_cms_assemble_control").getCategory( categoryId, function(js){
  72. this.categoryData = js.data;
  73. if( !this.columnData ){
  74. MWF.Actions.get("x_cms_assemble_control").getColumn( this.categoryData.appId, function( json ){
  75. this.columnData = json.data;
  76. }.bind(this), null, false)
  77. }
  78. }.bind(this), null, false)
  79. }
  80. },
  81. parseConfig: function(){
  82. if( this.columnData ) {
  83. this.columnData.config = this.columnData.config || {};
  84. if (typeOf(this.columnData.config) === "string") {
  85. this.columnData.config = JSON.parse(this.columnData.config || "{}");
  86. } else {
  87. this.columnData.config = Object.clone(this.columnData.config || {});
  88. }
  89. var options = this.orginOptions;
  90. if (typeOf(options.ignoreTitle) !== "boolean" && typeOf(this.columnData.config.ignoreTitle) === "boolean") {
  91. this.options.ignoreTitle = this.columnData.config.ignoreTitle;
  92. }
  93. if (typeOf(options.latest) !== "boolean" && typeOf(this.columnData.config.latest) === "boolean") {
  94. this.options.latest = this.columnData.config.latest;
  95. }
  96. if (typeOf(options.saveOnClose) !== "boolean" && typeOf(this.columnData.config.saveDraftOnClose) === "boolean") {
  97. this.options.saveOnClose = this.columnData.config.saveDraftOnClose;
  98. }
  99. }
  100. },
  101. load : function(){
  102. this.initData();
  103. this.identityList = this.getIdentities();
  104. if( !this.categoryData ) { //如果未限定分类
  105. this._load();
  106. this.fireEvent("postLoad");
  107. }else if(this.categoryData.workflowAppId && this.categoryData.workflowFlag ){ //发起审批流程
  108. this._load();
  109. this.fireEvent( "postLoad" );
  110. }else if( this.options.ignoreDrafted ){
  111. this._load();
  112. this.fireEvent( "postLoad" );
  113. }else{
  114. var fielter = {
  115. "categoryIdList": [this.categoryData.id ],
  116. "creatorList": [layout.desktop.session.user.distinguishedName]
  117. };
  118. debugger
  119. this.documentAction.listDraftNext("(0)", 1, fielter, function(json){
  120. if( json.data.length > 0 ){
  121. var handle = this._openDocument(json.data[0].id);
  122. this.fireEvent("started", [json.data[0].id, json.data[0], handle]);
  123. this.fireEvent( "postLoad" );
  124. }else{
  125. this._load();
  126. this.fireEvent( "postLoad" );
  127. }
  128. }.bind(this));
  129. }
  130. },
  131. _load : function(){
  132. if( this.categoryData && this.isIgnoreTitle() && this.identityList.length == 1 ) { //信息需要输入标题,数据不需要输入标题
  133. this.okStart();
  134. }else{
  135. this.isNew = true;
  136. this.isEdited = true;
  137. this._open();
  138. this.checkSubject();
  139. if( this.options.selectColumnEnable ){
  140. this.openSel();
  141. }
  142. }
  143. },
  144. openSel : function(){
  145. this.formTopTextNode.set("text", this.lp.selCategory);
  146. if( this.sel ){
  147. this.sel.load();
  148. }else{
  149. this.sel = new MWF.xApplication.cms.Index.Newer.CategorySel(this.app, this.formContentNode, this, this.columnData, this.categoryData, {
  150. restrictToColumn : this.options.restrictToColumn
  151. });
  152. this.sel.load();
  153. }
  154. },
  155. _loadCss: function(){
  156. var key = encodeURIComponent(this.cssPath);
  157. if (MWF.widget.css[key]){
  158. this.css = MWF.widget.css[key];
  159. }else{
  160. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+COMMON.version : this.cssPath+"?v="+COMMON.version;
  161. var r = new Request.JSON({
  162. url: this.cssPath,
  163. secure: false,
  164. async: false,
  165. method: "get",
  166. noCache: false,
  167. onSuccess: function(responseJSON, responseText){
  168. this.css = responseJSON;
  169. MWF.widget.css[key] = responseJSON;
  170. }.bind(this),
  171. onError: function(text, error){
  172. alert(error + text);
  173. }
  174. });
  175. r.send();
  176. }
  177. },
  178. _createTableContent: function () {
  179. if( this.options.zIndex ){
  180. this.formMaskNode.setStyle('z-index', this.options.zIndex);
  181. this.formAreaNode.setStyle('z-index', this.options.zIndex);
  182. }
  183. var categoryName = this.categoryData ? ( this.categoryData.name || this.categoryData.categoryName ) : this.lp.selectCategory;
  184. var html = "";
  185. if( this.options.selectColumnEnable ){
  186. this.selectArea = new Element("div",{styles:this.css.selectArea}).inject( this.formTableArea );
  187. this.selectContainer = new Element("div",{styles:this.css.selectContainer}).inject( this.selectArea );
  188. //html = "<table width='100%' height='90%' border='0' cellPadding='0' cellSpacing='0'>" +
  189. //"<tr>" +
  190. //"<td style='height: 40px; line-height: 40px; text-align: left; width: 40%' id='form_startColumn'></td>" +
  191. //"<td style='text-align: left;' id='form_startCategory'></td>" +
  192. //"</tr>" +
  193. //"</table>"
  194. html = "<div id='form_startColumn' style='float:left'></div><div id='form_startCategory' style='float:left'></div>";
  195. this.selectContainer.set("html", html);
  196. this.setSelectContent();
  197. }
  198. this.inputContainer = new Element("div",{styles:this.css.inputContainer}).inject( this.formTableArea );
  199. html = "<table width='100%' height='90%' border='0' cellPadding='0' cellSpacing='0'; >" +
  200. "<tr><td colSpan='2' style='height: 60px; line-height: 60px; text-align: center; font-size: 24px; ' id='form_startTitle'>" +
  201. this.lp.start+" - "+categoryName+"</td></tr>" +
  202. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333;min-width: 100px;'>"+this.lp.department+":</td>" +
  203. "<td style='; text-align: left;' id='form_startDepartment'></td></tr>" +
  204. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'>"+this.lp.identity+":</td>" +
  205. "<td style='; text-align: left;'><div id='form_startIdentity'></div></td></tr>" +
  206. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'>"+this.lp.date+":</td>" +
  207. "<td style='; text-align: left;'><div id='form_startDate'></div></td></tr>" +
  208. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'>"+this.lp.subject+":</td>" +
  209. "<td style='; text-align: left;'><input type='text' id='form_startSubject' " +
  210. "style='width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;'/></td></tr>" +
  211. "<tr><td style='height: 38px; line-height: 38px; text-align: left; font-size:16px;color:#333'></td>" +
  212. "<td style='text-align: left;' id='form_startAction'></td></tr>" +
  213. "</table>";
  214. this.inputContainer.set("html", html);
  215. this.setStartFormContent();
  216. this.startActionContainer = this.inputContainer.getElementById("form_startAction");
  217. this.startTitleNode = this.inputContainer.getElementById("form_startTitle");
  218. this.startOkActionNode = new Element("div", {
  219. "styles": this.css.startOkActionNode,
  220. "text": this.lp.ok
  221. }).inject(this.startActionContainer);
  222. this.startOkActionNode.addClass("mainColor_bg");
  223. this.startOkActionNode.addClass("mainColor_border");
  224. this.cancelActionNode = new Element("div", {
  225. "styles": this.css.cancelActionNode,
  226. "text": this.lp.cancel
  227. }).inject(this.startActionContainer);
  228. this.cancelActionNode.addEvent("click", function(e){
  229. this.cancelStart(e);
  230. }.bind(this));
  231. this.startOkActionNode.addEvent("click", function(e){
  232. this.okStart(e);
  233. }.bind(this));
  234. },
  235. isIgnoreTitle : function(){
  236. if( this.options.ignoreTitle )return true;
  237. return this.categoryData && ( ![this.lp.documentTypeInfor, "信息"].contains(this.categoryData.documentType));
  238. },
  239. checkSubject: function(){
  240. if( this.categoryData ){
  241. if( this.isIgnoreTitle() ){
  242. if(this.subjectInput)this.subjectInput.getParent("tr").setStyle("display","none");
  243. }else{
  244. if(this.subjectInput)this.subjectInput.getParent("tr").setStyle("display","");
  245. }
  246. }
  247. },
  248. setSelectContent: function(){
  249. this.columnContainer = this.selectContainer.getElementById("form_startColumn");
  250. this.columnContainer.setStyles( this.css.columnContainer );
  251. this.selectContainer.addEvents({
  252. mouseover : function(){
  253. this.columnSelectNode.setStyles( this.css.columnSelectNode_over );
  254. }.bind(this),
  255. mouseout : function(){
  256. this.columnSelectNode.setStyles( this.css.columnSelectNode );
  257. }.bind(this),
  258. click : function(){
  259. this.openSel();
  260. }.bind(this)
  261. });
  262. this.columnIconNode = new Element("img", {styles : this.css.columnIconNode }).inject( this.columnContainer );
  263. if( this.columnData ){
  264. if (this.columnData.appIcon){
  265. this.columnIconNode.set("src", "data:image/png;base64,"+this.columnData.appIcon+"");
  266. }else{
  267. this.columnIconNode.set("src", "../x_component_cms_Index/$Main/default/icon/column.png");
  268. }
  269. }else{
  270. this.columnIconNode.set("src","../x_component_cms_Index/$Main/default/icon/all_40.png");
  271. }
  272. this.columnTextNode = new Element("div", {
  273. styles : this.css.columnTextNode,
  274. text : this.lp.all
  275. } ).inject( this.columnContainer );
  276. this.columnSelectNode = new Element("div", {styles : this.css.columnSelectNode }).inject( this.columnContainer );
  277. this.categoryContainer = this.selectContainer.getElementById("form_startCategory");
  278. this.categoryContainer.setStyles( this.css.categoryContainer );
  279. this.categoryTextNode = new Element("div", {
  280. styles : this.css.categoryTextNode,
  281. text : this.lp.clickForSelect
  282. }).inject( this.categoryContainer );
  283. },
  284. setCurrentColumn: function( column ){
  285. if( this.currentColumn && this.currentColumn != column ){
  286. this.currentColumn.node.setStyles( this.css.columnItemNode );
  287. this.currentColumn.node.removeClass("mainColor_color");
  288. this.currentColumn.options.isCurrent = false;
  289. }
  290. this.currentColumn = column;
  291. },
  292. setCurrentCategory: function( category ){
  293. debugger;
  294. if( this.currentCategory && this.currentCategory != category ){
  295. this.currentCategory.node.setStyles( this.css.categoryItemNode );
  296. this.currentCategory.node.removeClass("mainColor_color");
  297. this.currentCategory.node.removeClass("mainColor_border");
  298. this.currentCategory.options.isCurrent = false;
  299. }
  300. this.currentCategory = category;
  301. var fielter = {
  302. "categoryIdList": [ category.data.id ],
  303. "creatorList": [layout.desktop.session.user.distinguishedName]
  304. };
  305. this.documentAction.getColumn( category.data.appId , function( json ) {
  306. this.columnData = json.data;
  307. this.parseConfig();
  308. this.documentAction.listDraftNext("(0)", 1, fielter, function (j) {
  309. if (j.data && j.data.length > 0 && this.options.latest) {
  310. //this._openDocument(j.data[0].id);
  311. var handle = this._openDocument( j.data[0].id );
  312. this.fireEvent("started", [j.data[0].id, j.data[0], handle]);
  313. this.close();
  314. } else {
  315. if (this.columnData.appIcon) {
  316. this.columnIconNode.set("src", "data:image/png;base64," + this.columnData.appIcon + "");
  317. } else {
  318. this.columnIconNode.set("src", "../x_component_cms_Index/$Main/default/icon/column.png");
  319. }
  320. this.columnTextNode.set("text", this.columnData.appName);
  321. this.formTopTextNode.set("text", this.lp.createDocument);
  322. this.categoryData = category.data;
  323. this.checkSubject();
  324. this.categoryTextNode.set("text", this.categoryData.categoryName);
  325. this.startTitleNode.set("text", this.lp.start + " - " + this.categoryData.categoryName);
  326. if(this.sel){
  327. this.sel.closeArea();
  328. }
  329. if (this.isIgnoreTitle() && this.identityList.length == 1) {
  330. this.okStart();
  331. }
  332. }
  333. }.bind(this));
  334. }.bind(this));
  335. },
  336. setStartFormContent: function(){
  337. this.dateArea = this.formTableArea.getElementById("form_startDate");
  338. var d = new Date();
  339. this.dateArea.set("text", d.format("%Y-%m-%d %H:%M"));
  340. this.departmentSelArea = this.formTableArea.getElementById("form_startDepartment");
  341. this.identityArea = this.formTableArea.getElementById("form_startIdentity");
  342. this.subjectInput = this.formTableArea.getElementById("form_startSubject");
  343. this.loadDepartments();
  344. },
  345. getIdentities: function(){
  346. var identities = [];
  347. MWF.Actions.get("x_organization_assemble_personal").getPerson(function(json){
  348. var identities1 = (json.data && json.data.woIdentityList) ? json.data.woIdentityList : [];
  349. var identityList = typeOf( this.options.identity ) === "array" ? this.options.identity : [this.options.identity];
  350. identityList = identityList.filter(function( i ){ return !!i });
  351. identities1.each( function(i){
  352. if( identityList.length ){
  353. for( var j=0; j<identityList.length; j++ ){
  354. var identity = identityList[j] || "";
  355. var dn = (typeOf(identity)==="string") ? identity : identity.distinguishedName;
  356. if( dn && i.distinguishedName===dn ){
  357. i.index = j;
  358. identities.push(i);
  359. return;
  360. }
  361. }
  362. // if( this.options.identity == i.distinguishedName ){
  363. // if( i.distinguishedName )identities.push(i);
  364. // }
  365. }else{
  366. if( i.distinguishedName )identities.push(i);
  367. }
  368. }.bind(this));
  369. if(identityList.length){
  370. identities.sort( function (a, b) {
  371. return a.index - b.index;
  372. });
  373. }
  374. }.bind(this), null, false );
  375. return identities;
  376. },
  377. loadDepartments: function(){
  378. //MWF.Actions.get("x_organization_assemble_personal").getPerson(function(json){
  379. // var identities1 = (json.data && json.data.woIdentityList) ? json.data.woIdentityList : [];
  380. // var identities = [];
  381. // identities1.each( function(i){
  382. // if( i.distinguishedName )identities.push(i);
  383. // }.bind(this));
  384. // var selected = (identities.length==1) ? true : false;
  385. // identities.each(function(id){
  386. // var departSel = new MWF.xApplication.cms.Index.Newer.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  387. // if (selected) departSel.selected();
  388. // }.bind(this));
  389. //}.bind(this), null )
  390. var identities = this.identityList || this.getIdentities() || [];
  391. var selected = (identities.length==1) ? true : false;
  392. identities.each(function(id){
  393. var departSel = new MWF.xApplication.cms.Index.Newer.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  394. if (selected) departSel.selected();
  395. }.bind(this));
  396. },
  397. cancelStart: function(e){
  398. var _self = this;
  399. if ( this.subjectInput && this.subjectInput.get("value")){
  400. this.app.confirm("warn", e, this.lp.start_cancel_title, this.lp.start_cancel, "320", "120", function(){
  401. _self.close();
  402. this.close();
  403. },function(){
  404. this.close();
  405. });
  406. }else{
  407. this.close();
  408. }
  409. },
  410. okStart: function(){
  411. if( !this.categoryData ){
  412. this.app.notice(this.lp.selectCategory, "error");
  413. }else{
  414. if( this.categoryData.workflowAppId && this.categoryData.workflowFlag ){
  415. this._createProcessDocument();
  416. }else{
  417. this._createDocument();
  418. }
  419. }
  420. },
  421. _createDocument: function(e){
  422. var title = this.subjectInput ? this.subjectInput.get("value") : "";
  423. if( !title && this.options.documentData ){
  424. title = this.options.documentData.title || this.options.documentData.subject || "";
  425. }
  426. var identity = "";
  427. var identityList = typeOf( this.options.identity ) === "array" ? this.options.identity : [this.options.identity];
  428. identityList = identityList.filter(function( i ){ return !!i });
  429. if( identityList.length === 1 && identityList[0] ){
  430. identity = typeOf( identityList[0] ) === "string" ? identityList[0] : identityList[0].distinguishedName;
  431. }else if( this.identityArea ){
  432. identity = this.identityArea.get("value");
  433. }else if( this.identityList.length > 0 ){
  434. identity = this.identityList[0].distinguishedName;
  435. }
  436. var data = {
  437. "id" : this.documentAction.getUUID(),
  438. "isNewDocument" : true,
  439. "title": title,
  440. "creatorIdentity": identity,
  441. "identity" : identity,
  442. "appId" :this.categoryData.appId,
  443. "categoryId" : this.categoryData.id,
  444. "form" : this.categoryData.formId,
  445. "formName" :this.categoryData.formName,
  446. "docStatus" : "draft",
  447. "categoryName" : this.categoryData.name || this.categoryData.categoryName,
  448. "categoryAlias" : this.categoryData.alias || this.categoryData.categoryAlias,
  449. "attachmentList" : []
  450. };
  451. if( this.options.documentData ){
  452. data.docData = this.options.documentData;
  453. }
  454. if (!data.title && !this.isIgnoreTitle()){
  455. if(this.subjectInput)this.subjectInput.setStyle("border-color", "red");
  456. if(this.subjectInput)this.subjectInput.focus();
  457. this.app.notice(this.lp.inputSubject, "error");
  458. }else if (!data.creatorIdentity){
  459. this.departmentSelArea.setStyle("border-color", "red");
  460. this.app.notice(this.lp.selectStartId, "error");
  461. }else{
  462. if( this.isIgnoreTitle() && !data.title )data.title = this.lp.untitled;
  463. if( this.formAreaNode ){
  464. this.mask = new MWF.widget.Mask({"style": "desktop"});
  465. this.mask.loadNode(this.formAreaNode);
  466. }
  467. this.documentAction.addDocument( data, function(json){
  468. if( this.mask )this.mask.hide();
  469. //this.markNode.destroy();
  470. debugger;
  471. var handle = this._openDocument( json.data.id );
  472. this.fireEvent("started", [json.data.id, data, handle]);
  473. this.close();
  474. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  475. //this.app.refreshAll();
  476. this.app.notice(this.lp.Started, "success");
  477. // this.app.processConfig();
  478. }.bind(this), function(xhr, text, error){
  479. if( xhr && xhr.response && typeOf(xhr.response)==="string" ){
  480. try{
  481. var eObj = JSON.parse(xhr.response);
  482. this.app.notice( eObj.message, "error");
  483. }catch (e) {}
  484. }
  485. if( this.mask )this.mask.hide();
  486. }.bind(this));
  487. }
  488. },
  489. _openDocument: function(id,el){
  490. var _self = this;
  491. var appId = "cms.Document"+id;
  492. if (_self.app.desktop && _self.app.desktop.apps && _self.app.desktop.apps[appId]){
  493. _self.app.desktop.apps[appId].setCurrent();
  494. return _self.app.desktop.apps[appId];
  495. }else {
  496. var options = {
  497. "readonly" :false,
  498. "documentId": id,
  499. "appId": appId,
  500. "onPostPublish" : function( args ){
  501. this.fireEvent( "postPublish", args );
  502. }.bind(this),
  503. "onAfterPublish" : function ( args ) {
  504. if(_self.view && _self.view.reload )_self.view.reload();
  505. _self.fireEvent( "afterPublish", args );
  506. }
  507. };
  508. if( typeOf(this.options.autoSave) == "boolean" )options.autoSave = this.options.autoSave;
  509. if( typeOf(this.options.saveOnClose) == "boolean" )options.saveOnClose = this.options.saveOnClose;
  510. if( layout.inBrowser ){
  511. debugger;
  512. if( !window.o2RefreshCMSView ){
  513. window.o2CreateCMSDocumentCount = ( window.o2CreateCMSDocumentCount || 0 ) + 1;
  514. window.o2RefreshCMSView = function () {
  515. try{
  516. if(_self.view && _self.view.reload )_self.view.reload();
  517. }catch (e) {}
  518. if( window.o2CreateCMSDocumentCount )window.o2CreateCMSDocumentCount--;
  519. if( !window.o2CreateCMSDocumentCount || window.o2CreateCMSDocumentCount<0 ){
  520. window.o2RefreshCMSView = null;
  521. }
  522. }.bind(this)
  523. }
  524. return this.app.desktop.openApplication(el, "cms.Document", options);
  525. }else{
  526. return this.app.desktop.openApplication(el, "cms.Document", options);
  527. }
  528. }
  529. },
  530. _createProcessDocument:function(e){
  531. var title = this.subjectInput ? this.subjectInput.get("value") : "";
  532. if( !title && this.options.documentData ){
  533. title = this.options.documentData.title || this.options.documentData.subject || "";
  534. }
  535. var identity = "";
  536. if( this.options.identity ){
  537. identity = this.options.identity;
  538. }else if( this.identityArea ){
  539. identity = this.identityArea.get("value");
  540. }else if( this.identityList.length > 0 ){
  541. identity = this.identityList[0].distinguishedName;
  542. }
  543. var processId = this.categoryData.workflowFlag;
  544. var data = {
  545. "title":title,
  546. "identity": identity
  547. };
  548. if (!data.title && !this.isIgnoreTitle() ){
  549. this.subjectInput.setStyle("border-color", "red");
  550. this.subjectInput.focus();
  551. this.app.notice(this.lp.inputSubject, "error");
  552. }else if (!data.identity){
  553. this.departmentSelArea.setStyle("border-color", "red");
  554. this.app.notice(this.lp.selectStartId, "error");
  555. }else{
  556. if( this.isIgnoreTitle() && !title )title = this.lp.untitled; //"无标题";
  557. var workData;
  558. if( this.options.documentData ){
  559. workData = Object.clone(this.options.documentData);
  560. }else{
  561. workData = {};
  562. }
  563. workData.cmsDocument = {
  564. "isNewDocument" : true,
  565. "title": title,
  566. "creatorIdentity": data.identity,
  567. "identity": data.identity,
  568. "appId" :this.categoryData.appId,
  569. "categoryId" : this.categoryData.id,
  570. //"form" : this.categoryData.formId,
  571. //"formName" :this.categoryData.formName,
  572. "docStatus" : "draft",
  573. "categoryName" : this.categoryData.name,
  574. "categoryAlias" : this.categoryData.alias,
  575. "createTime": new Date().format("db"),
  576. "attachmentList" : []
  577. };
  578. if( this.formAreaNode ){
  579. this.mask = new MWF.widget.Mask({"style": "desktop"});
  580. this.mask.loadNode(this.formAreaNode);
  581. }
  582. MWF.Actions.get("x_processplatform_assemble_surface").startWork( function( json ){
  583. if(this.mask)this.mask.hide();
  584. //this.markNode.destroy();
  585. this.close();
  586. this.afterStartProcess( json.data, data.title, this.categoryData.workflowName, workData );
  587. //this.fireEvent("started", [json.data, title, this.categoryData.name]);
  588. //this.app.refreshAll();
  589. this.app.notice(this.lp.Started, "success");
  590. }.bind(this), null, processId, data)
  591. }
  592. },
  593. afterStartProcess: function(data, title, processName, workData){
  594. if (data.work){
  595. this.startProcessDraft(data, title, processName, workData);
  596. }else{
  597. this.startProcessInstance(data, title, processName, workData);
  598. }
  599. },
  600. startProcessDraft: function(data, title, processName, workData){
  601. var work = data.work;
  602. if(workData){
  603. delete workData.identity;
  604. delete workData.attachmentList;
  605. }
  606. var options = {
  607. "draft": work,
  608. "draftData": workData,
  609. "appId": "process.Work"+(new o2.widget.UUID).toString(),
  610. "desktopReload": false
  611. };
  612. var win = this.app.desktop.openApplication(null, "process.Work", options);
  613. this.fireEvent("started", ["", workData, win]);
  614. },
  615. startProcessInstance: function(data, title, processName, workData){
  616. var workInfors = [];
  617. var currentTask = [];
  618. data.each(function(work){
  619. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  620. workInfors.push(this.getStartWorkInforObj(work));
  621. }.bind(this));
  622. var workId = currentTask[0];
  623. MWF.Actions.get("x_processplatform_assemble_surface").saveData(function(){
  624. if (currentTask.length==1){
  625. var options = {"workId": workId};
  626. var handle = this.app.desktop.openApplication(null, "process.Work", options);
  627. this.fireEvent("started", [workId, workData, handle]);
  628. this.createStartWorkResault(workInfors, title, processName, false);
  629. }else{
  630. this.fireEvent("started", [workId, workData]);
  631. this.createStartWorkResault(workInfors, title, processName, true);
  632. }
  633. }.bind(this), null, workId, workData)
  634. },
  635. getStartWorkInforObj: function(work){
  636. var users = [];
  637. var currentTask = "";
  638. work.taskList.each(function(task, idx){
  639. users.push(task.identity.split("@")[0]+"("+task.unit.split("@")[0] + ")");
  640. if (work.currentTaskIndex==idx) currentTask = task.id;
  641. }.bind(this));
  642. return {"activity": work.fromActivityName, "users": users, "currentTask": currentTask};
  643. },
  644. createStartWorkResault: function(workInfors, title, processName, isopen){
  645. var content = "";
  646. workInfors.each(function(infor){
  647. 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>";
  648. if (infor.currentTask && isopen){
  649. content += "&nbsp;&nbsp;&nbsp;&nbsp;<span value='"+infor.currentTask+"'>"+this.lp.deal+"</span></div>";
  650. }else{
  651. content += "</div>";
  652. }
  653. }.bind(this));
  654. var msg = {
  655. "subject": this.lp.processStarted,
  656. "content": "<div>"+this.lp.processStartedMessage+"“["+processName+"]"+title+"”</div>"+content
  657. };
  658. var tooltip = layout.desktop.message.addTooltip(msg);
  659. var item = layout.desktop.message.addMessage(msg);
  660. this.setStartWorkResaultAction(tooltip);
  661. this.setStartWorkResaultAction(item);
  662. },
  663. setStartWorkResaultAction: function(item){
  664. var node = item.node.getElements("span");
  665. node.setStyles(this.css.dealStartedWorkAction);
  666. var _self = this;
  667. node.addEvent("click", function(e){
  668. var options = {"taskId": this.get("value")};
  669. _self.app.desktop.openApplication(e, "process.Work", options);
  670. });
  671. }
  672. });
  673. MWF.xApplication.cms.Index.Newer.DepartmentSel = new Class({
  674. initialize: function(data, starter, container, idArea){
  675. this.data = data;
  676. this.starter = starter;
  677. this.container = container;
  678. this.idArea = idArea;
  679. this.css = this.starter.css;
  680. this.isSelected = false;
  681. this.load();
  682. },
  683. load: function(){
  684. this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  685. //this.starter.documentAction.listDepartmentWithIdentity(function(department){
  686. // var unitList = department.data && department.data.unitList ? department.data.unitList : [""];
  687. // this.node.set("text", unitList[0]);
  688. //}.bind(this), null, { "identityList" : [ this.data.distinguishedName ] } );
  689. var unit = this.data.woUnit ? this.data.woUnit.name : this.lp.unnamedUnit;
  690. this.node.set("text",this.data.woUnit.name);
  691. this.node.addEvents({
  692. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  693. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  694. "click": function(){
  695. this.selected();
  696. }.bind(this)
  697. });
  698. },
  699. selected: function(){
  700. if (!this.isSelected){
  701. if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  702. this.node.setStyles(this.css.departSelNode_selected);
  703. this.isSelected = true;
  704. this.starter.currentDepartment = this;
  705. this.idArea.set({
  706. "text": this.data.name,
  707. "value": this.data.distinguishedName
  708. });
  709. }
  710. },
  711. unSelected: function(){
  712. if (this.isSelected){
  713. if (this.starter.currentDepartment) this.starter.currentDepartment = null;
  714. this.node.setStyles(this.css.departSelNode);
  715. this.isSelected = false;
  716. }
  717. }
  718. });
  719. MWF.xApplication.cms.Index.Newer.CategorySel = new Class({
  720. Extends: MWF.widget.Common,
  721. Implements: [Options, Events],
  722. options: {
  723. "style": "default",
  724. "restrictToColumn" : false
  725. },
  726. initialize: function(app, node, newer, columnData, categoryData, options){
  727. this.setOptions(options);
  728. this.node = node;
  729. this.newer = newer;
  730. this.lp = newer.lp;
  731. this.css = newer.css;
  732. this.action = newer.documentAction;
  733. this.columnData = columnData;
  734. this.categoryData = categoryData;
  735. },
  736. load: function(){
  737. if (!this.areaNode){
  738. this.createArea();
  739. }else{
  740. if(this.searchNode)this.searchNode.show();
  741. }
  742. this.areaNode.fade("1");
  743. },
  744. closeArea: function(){
  745. if (this.searchNode){
  746. this.searchNode.hide();
  747. }
  748. if (this.areaNode) this.areaNode.fade("out");
  749. },
  750. createArea: function(){
  751. if( this.newer.options.searchEnable ){
  752. this.searchNode = new Element("div").inject( this.newer.formTopContentNode );
  753. this.searchInputNode = new Element("input", {
  754. "styles": this.css.formTopSearchInputNode,
  755. "placeholder": this.lp.searchPlacholder,
  756. "events": {
  757. "keydown": function(e){ if (e.code===13) this.searchCategory(); }.bind(this)
  758. }
  759. }).inject( this.searchNode );
  760. this.searchActionNode = new Element("div", {
  761. "styles": this.css.formTopSearchActionNode,
  762. "events": {
  763. "click": function(e){ this.searchCategory(); }.bind(this)
  764. }
  765. }).inject( this.searchNode );
  766. }
  767. this.areaNode = new Element("div.categorySelAreaNode", {"styles": this.css.categorySelAreaNode}).inject(this.node );
  768. this.areaNode.addEvent("click", function(e){
  769. //this.closeArea();
  770. }.bind(this));
  771. this.columnContainer = new Element("div", {"styles": this.css.selColumnAreaNode}).inject( this.areaNode );
  772. this.columnScrollNode = new Element("div.columnScrollNode", {"styles": this.css.selColumnScrollNode}).inject(this.columnContainer);
  773. this.setScrollBar( this.columnScrollNode );
  774. this.columnContentNode = new Element("div.selColumnContentNode", {"styles": this.css.selColumnContentNode}).inject(this.columnScrollNode);
  775. this.categoryContainer = new Element("div", {"styles": this.css.selCategoryAreaNode}).inject( this.areaNode );
  776. this.categoryScrollNode = new Element("div", {"styles": this.css.selCategoryScrollNode}).inject(this.categoryContainer);
  777. this.setScrollBar( this.categoryScrollNode );
  778. this.categoryContentNode = new Element("div", {"styles": this.css.selCategoryContentNode}).inject(this.categoryScrollNode);
  779. if( this.options.restrictToColumn && this.columnData ){
  780. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(this.columnData, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  781. "needGetCategorys": true,
  782. "isCurrent": true,
  783. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  784. "restrictToColumn" : this.options.restrictToColumn
  785. });
  786. }else{
  787. this.listColumns();
  788. }
  789. },
  790. searchCategory: function(){
  791. var value = this.searchInputNode.get("value");
  792. if( value ){
  793. ( this.newer.categoryList || [] ).each(function(category){
  794. if (category.data.categoryName.indexOf(value)!==-1){
  795. category.node.show();
  796. }else{
  797. category.node.hide();
  798. }
  799. })
  800. }else{
  801. ( this.newer.categoryList || [] ).each(function(category){
  802. category.node.show();
  803. })
  804. }
  805. },
  806. listColumns: function(){
  807. var c = { wrapOutCategoryList : [] };
  808. this.action.listColumnByPublish(function(json){
  809. json.data.each(function(column){
  810. if(!column.name)column.name = column.appName;
  811. if( column.wrapOutCategoryList && column.wrapOutCategoryList.length ){
  812. column.wrapOutCategoryList.each(function(category){
  813. c.wrapOutCategoryList.push(category);
  814. }.bind(this));
  815. }
  816. }.bind(this));
  817. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(c, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  818. "needGetCategorys": false,
  819. "isAll" : true,
  820. "isCurrent" : this.columnData ? false : true,
  821. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  822. "restrictToColumn" : this.options.restrictToColumn
  823. });
  824. json.data.each( function(column) {
  825. if(!column.name)column.name = column.appName;
  826. new MWF.xApplication.cms.Index.Newer.CategorySel.Column(column, this.app, this.newer, this.columnContentNode, this.categoryContentNode, {
  827. "needGetCategorys": false,
  828. "isCurrent": ( this.columnData && this.columnData.id == column.id) ? true : false,
  829. "currentCategory" : this.categoryData ? this.categoryData.id : "",
  830. "restrictToColumn" : this.options.restrictToColumn
  831. });
  832. }.bind(this) )
  833. }.bind(this));
  834. }
  835. });
  836. MWF.xApplication.cms.Index.Newer.CategorySel.Column = new Class({
  837. Implements: [Options],
  838. options: {
  839. "needGetCategorys": false,
  840. "isAll" : false,
  841. "isCurrent" : false,
  842. "currentCategory" : "",
  843. "restrictToColumn" : false
  844. },
  845. initialize: function(data, app, newer, container, categoryContainer, options ){
  846. this.setOptions( options );
  847. this.data = data;
  848. this.app = app;
  849. this.newer = newer;
  850. this.lp = newer.lp;
  851. this.css = newer.css;
  852. this.action = newer.documentAction;
  853. this.container = container;
  854. this.categoryContainer = categoryContainer;
  855. this.load();
  856. },
  857. load: function(){
  858. this.node = new Element("div", {"styles": this.css.columnItemNode}).inject(this.container);
  859. var iconNode = this.iconNode = new Element("img",{
  860. "styles" : this.css.columnItemIconNode
  861. }).inject(this.node);
  862. if( this.options.isAll ){
  863. this.iconNode.set("src", "../x_component_cms_Index/$Main/default/icon/all_40.png")
  864. }else if (this.data.appIcon){
  865. this.iconNode.set("src", "data:image/png;base64,"+this.data.appIcon+"");
  866. }else{
  867. this.iconNode.set("src", "../x_component_cms_Index/$Main/default/icon/column.png")
  868. }
  869. this.textNode = new Element("div", {"styles": this.css.columnItemTextNode}).inject(this.node);
  870. if( this.options.isAll ){
  871. this.textNode.set("text", this.lp.all);
  872. }else{
  873. this.textNode.set("text", (this.data.name || this.data.appName) );
  874. }
  875. if( this.options.isAll ){
  876. //new Element("div", {"styles": this.css.columnSelectNode}).inject(this.node);
  877. }
  878. this.node.addEvents({
  879. "mouseover" : function(){ if( !this.options.isCurrent )this.node.setStyles( this.css.columnItemNode_over ) }.bind(this),
  880. "mouseout" : function(){ if( !this.options.isCurrent )this.node.setStyles( this.css.columnItemNode ) }.bind(this),
  881. "click" : function(){ this.setCurrent(); }.bind(this)
  882. });
  883. if( this.options.isCurrent )this.setCurrent();
  884. },
  885. setCurrent: function(){
  886. this.options.isCurrent = true;
  887. this.node.setStyles( this.css.columnItemNode_current );
  888. this.node.addClass("mainColor_color");
  889. this.newer.setCurrentColumn( this );
  890. this.loadCategory();
  891. },
  892. loadCategory: function(){
  893. this.categoryContainer.empty();
  894. this.newer.categoryList = [];
  895. if( this.options.needGetCategorys ){
  896. this.action.listCategoryByPublisher(this.data.id,function(json){
  897. if (json.data.length){
  898. var isSetCurrentImmediately = ( json.data.length == 1 && ( this.options.restrictToColumn || this.options.isAll ) );
  899. json.data.each(function(category){
  900. var category = new MWF.xApplication.cms.Index.Newer.CategorySel.Category(category, this, this.categoryContainer, {
  901. isCurrent : ( this.options.currentCategory == category.id ) || isSetCurrentImmediately
  902. });
  903. this.newer.categoryList.push(category);
  904. }.bind(this));
  905. }else{
  906. this.node.setStyle("display", "none");
  907. }
  908. }.bind(this), null, this.data.id);
  909. }else{
  910. if( this.data.wrapOutCategoryList && this.data.wrapOutCategoryList.length ){
  911. var isSetCurrentImmediately = ( this.data.wrapOutCategoryList.length == 1 && ( this.options.restrictToColumn || this.options.isAll ) );
  912. this.data.wrapOutCategoryList.each(function(category){
  913. var category = new MWF.xApplication.cms.Index.Newer.CategorySel.Category(category, this, this.categoryContainer,{
  914. isCurrent : ( this.options.currentCategory == category.id ) || isSetCurrentImmediately
  915. });
  916. this.newer.categoryList.push(category);
  917. }.bind(this));
  918. }else{
  919. this.node.setStyle("display", "none");
  920. }
  921. }
  922. }
  923. });
  924. MWF.xApplication.cms.Index.Newer.CategorySel.Category = new Class({
  925. Implements: [Options],
  926. options: {
  927. "isCurrent" : false
  928. },
  929. initialize: function(data, column, container, options){
  930. this.setOptions( options );
  931. this.data = data;
  932. this.column = column;
  933. this.app = this.column.app;
  934. this.newer = this.column.newer;
  935. this.container = container;
  936. this.css = this.newer.css;
  937. this.load();
  938. },
  939. load: function(){
  940. if( !this.data.name )this.data.name = this.data.categoryName;
  941. this.node = new Element("div.categoryItem", {"styles": this.css.categoryItemNode}).inject(this.container);
  942. if( this.options.isCurrent )this.node.setStyles( this.css.categoryItemNode_over );
  943. this.textNode = new Element("div", {"styles": this.css.categoryItemTextNode}).inject(this.node);
  944. this.textNode.set({
  945. "text": this.data.categoryName
  946. });
  947. var _self = this;
  948. this.node.addEvents({
  949. "mouseover": function(e){if( !this.options.isCurrent )this.node.setStyles(this.css.categoryItemNode_over); }.bind(this),
  950. "mouseout": function(e){if( !this.options.isCurrent )this.node.setStyles(this.css.categoryItemNode);}.bind(this),
  951. "click": function(e){
  952. this.setCurrent();
  953. }.bind(this)
  954. });
  955. if( this.options.isCurrent )this.setCurrent();
  956. },
  957. setCurrent: function(){
  958. this.options.isCurrent = true;
  959. this.node.setStyles( this.css.categoryItemNode_current );
  960. this.node.addClass("mainColor_color");
  961. this.node.addClass("mainColor_border");
  962. this.newer.setCurrentCategory( this );
  963. }
  964. });