Newer.js 44 KB

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