Main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. MWF.xApplication.Search.options.multitask = false;
  2. MWF.xApplication.Search.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style1": "default",
  7. "style": "default",
  8. "name": "Search",
  9. "icon": "icon.png",
  10. "width": "1200",
  11. "height": "700",
  12. "isResize": true,
  13. "isMax": true,
  14. "pageCount": 15,
  15. "key": "",
  16. "title": MWF.xApplication.Search.LP.title
  17. },
  18. onQueryLoad: function(){
  19. this.lp = MWF.xApplication.Search.LP;
  20. if (this.status && this.status.key) this.options.key = this.status.key;
  21. },
  22. initPage: function(){
  23. this.pageCount = this.options.pageCount;
  24. this.pages = 1;
  25. this.currentPage = 1;
  26. },
  27. recordStatus: function(){
  28. if (this.input){
  29. var v = this.input.getValue();
  30. return {"key": v};
  31. }
  32. return {};
  33. },
  34. loadApplication: function(callback){
  35. this.result = [];
  36. this.items = [];
  37. this.initPage();
  38. this.createLayout();
  39. if (callback) callback();
  40. },
  41. createLayout: function(){
  42. this.searchArea = new Element("div", {"styles": this.css.searchArea}).inject(this.content);
  43. this.resultArea = new Element("div", {"styles": this.css.resultArea}).inject(this.content);
  44. this.setSearchAreaSize();
  45. this.setSearchAreaSizeFun = this.setSearchAreaSize.bind(this);
  46. this.addEvent("resize", this.setSearchAreaSizeFun);
  47. this.createResultInfor();
  48. this.createResultContent();
  49. this.createResultPageArea();
  50. this.createSearchBar();
  51. },
  52. setSearchAreaSize: function(){
  53. var searchSize = this.searchArea.getSize();
  54. var contentSize = this.content.getSize();
  55. var y = contentSize.y-searchSize.y;
  56. this.resultArea.setStyle("height", ""+y+"px");
  57. },
  58. createSearchBar: function(){
  59. this.searchBarNode = new Element("div", {"styles": this.css.searchBarNode}).inject(this.searchArea);
  60. this.logoNode = new Element("div", {"styles": this.css.logoNode}).inject(this.searchBarNode);
  61. this.searchInputActionArea = new Element("div", {"styles": this.css.searchInputActionArea}).inject(this.searchBarNode);
  62. MWF.require("MWF.widget.SearchInput", function(){
  63. this.input = new MWF.widget.SearchInput({
  64. "onSearch": function(key){
  65. this.search(key)
  66. }.bind(this)
  67. });
  68. this.input.inject(this.searchInputActionArea);
  69. if (this.options.key){
  70. this.input.setValue(this.options.key);
  71. this.input.doSearch();
  72. }
  73. }.bind(this));
  74. },
  75. createResultInfor: function(){
  76. this.resultInfor = new Element("div", {
  77. "styles": this.css.resultInfor,
  78. "text": this.lp.infor
  79. }).inject(this.resultArea);
  80. },
  81. createResultContent: function(){
  82. this.resultContent = new Element("div", {
  83. "styles": this.css.resultContent
  84. }).inject(this.resultArea);
  85. },
  86. createResultPageArea: function(){
  87. this.resultPageArea = new Element("div", {
  88. "styles": this.css.resultPageArea
  89. }).inject(this.resultArea);
  90. },
  91. search: function(key){
  92. var startDate = new Date();
  93. MWF.Actions.get("x_query_assemble_surface").search(key, function(json){
  94. var endDate = new Date();
  95. var t = endDate.getTime()-startDate.getTime();
  96. t = ((t/1000)*100).toInt()/100;
  97. var text = this.lp.searchInfor;
  98. text = text.replace("{count}", json.data.count||0);
  99. text = text.replace("{time}", t);
  100. this.resultInfor.set("text", text);
  101. this.resultInfor.setStyles(this.css.searchResultInfor);
  102. this.resultPageArea.empty();
  103. this.resultContent.empty();
  104. this.result = json.data.valueList;
  105. if (json.data.count){
  106. this.createPages();
  107. this.showResult();
  108. }
  109. }.bind(this));
  110. },
  111. createPages: function(){
  112. this.initPage();
  113. this.resultPageArea.empty();
  114. if (this.result.length){
  115. var v = this.result.length/this.pageCount;
  116. this.pages = (v>v.toInt()) ? v.toInt()+1 : v.toInt();
  117. this.currentPage = 1;
  118. var _self = this;
  119. for (var i=1; i<=this.pages; i++){
  120. var node = new Element("div", {"styles": this.css.pageItem, "text": i}).inject(this.resultPageArea);
  121. node.addEvent("click", function(){
  122. _self.resultPageArea.getElement(":nth-child("+_self.currentPage+")").setStyles(_self.css.pageItem);
  123. _self.gotoPage(this.get("text"));
  124. });
  125. }
  126. }
  127. },
  128. gotoPage: function(i){
  129. this.currentPage = i;
  130. this.showResult();
  131. this.resultArea.scrollTop = 0;
  132. },
  133. showResult: function(){
  134. var startIdx = (this.currentPage-1)*this.pageCount;
  135. var endIdx = this.currentPage*this.pageCount-1;
  136. this.resultPageArea.getElement(":nth-child("+this.currentPage+")").setStyles(this.css.pageItem_current);
  137. this.resultContent.empty();
  138. var n = Math.min(this.result.length-1, endIdx);
  139. var ids = this.result.slice(startIdx, n+1);
  140. MWF.Actions.get("x_query_assemble_surface").listSearchEntry({
  141. "entryList": ids
  142. }, function(json){
  143. var datas = json.data;
  144. datas.each(function(d){
  145. new MWF.xApplication.Search.ResaultItem(this, d);
  146. }.bind(this));
  147. }.bind(this));
  148. // for (var i=startIdx; i<=n; i++){
  149. // var d = this.result[i];
  150. // new MWF.xApplication.Search.ResaultItem(this, d);
  151. // }
  152. }
  153. });
  154. MWF.xApplication.Search.ResaultItem = new Class({
  155. initialize: function(app, data){
  156. this.app = app;
  157. this.content = this.app.resultContent;
  158. this.lp = this.app.lp;
  159. this.css = this.app.css;
  160. this.data = data;
  161. this.checkPermission(function(){
  162. this.load();
  163. }.bind(this));
  164. },
  165. checkPermission: function(callback){
  166. if (!this.data.permission){
  167. if (this.data.type==="work"){
  168. MWF.Actions.get("x_processplatform_assemble_surface").getWorkControl(this.data.reference, function(){
  169. this.data.permission = "y";
  170. if (callback) callback();
  171. }.bind(this), function(){
  172. this.data.permission = "n";
  173. if (callback) callback();
  174. return true;
  175. }.bind(this))
  176. }
  177. if (this.data.type==="workCompleted"){
  178. MWF.Actions.get("x_processplatform_assemble_surface").getWorkControl(this.data.reference, function(){
  179. this.data.permission = "y";
  180. if (callback) callback();
  181. }.bind(this), function(){
  182. this.data.permission = "n";
  183. if (callback) callback();
  184. return true;
  185. }.bind(this))
  186. }
  187. if (this.data.type==="cms"){
  188. //getDocumentControl
  189. MWF.Actions.get("x_cms_assemble_control").getDocumentControl(this.data.reference, function(json){
  190. if (json.data.control.allowVisit){
  191. this.data.permission = "y";
  192. }else{
  193. this.data.permission = "n";
  194. }
  195. //this.data.permission = "y";
  196. if (callback) callback();
  197. }.bind(this), function(){
  198. this.data.permission = "n";
  199. if (callback) callback();
  200. return true;
  201. }.bind(this))
  202. }
  203. }else{
  204. if (callback) callback();
  205. }
  206. },
  207. load: function(){
  208. this.node = new Element("div", {"styles": this.css.resaultItemNode}).inject(this.content);
  209. this.titleNode = new Element("div", {"styles": this.css.resaultItemTitleNode}).inject(this.node);
  210. this.summaryNode = new Element("div", {"styles": this.css.resaultItemSummaryNode}).inject(this.node);
  211. this.inforNode = new Element("div", {"styles": this.css.resaultItemInforNode}).inject(this.node);
  212. this.loadTitle();
  213. this.loadSummary();
  214. this.loadInfor();
  215. },
  216. loadTitle: function(){
  217. if (this.data.permission==="n"){
  218. this.titleNode.setStyles(this.css.resaultItemTitleNode_gray);
  219. this.titleNode.set("text", (this.data.title) ? this.data.title+" ("+this.lp.refuse+")" : this.lp.nonamed+" ("+this.lp.refuse+")");
  220. }else{
  221. this.titleNode.set("text", this.data.title || this.lp.nonamed);
  222. this.titleNode.addEvents({
  223. "mouseover": function(){this.setStyle("text-decoration", "underline")},
  224. "mouseout": function(){this.setStyle("text-decoration", "none");},
  225. "click": function(e){
  226. this.openItem(e);
  227. }.bind(this)
  228. });
  229. }
  230. },
  231. openItem: function(e){
  232. if (this.data.type==="work"){
  233. layout.desktop.openApplication(e, "process.Work", {"workId": this.data.reference, "appId": this.data.reference, "docTitle": this.data.title || this.lp.nonamed});
  234. }
  235. if (this.data.type==="workCompleted"){
  236. layout.desktop.openApplication(e, "process.Work", {"workCompletedId": this.data.reference, "appId": this.data.reference, "docTitle": this.data.title || this.lp.nonamed});
  237. }
  238. if (this.data.type==="cms"){
  239. layout.desktop.openApplication(e, "cms.Document", {"documentId": this.data.reference, "appId": this.data.reference, "docTitle": this.data.title || this.lp.nonamed});
  240. }
  241. },
  242. loadSummary: function(){
  243. this.summaryNode.set("text", this.data.summary);
  244. },
  245. loadInfor: function(){
  246. var html = "";
  247. if (this.data.applicationName){
  248. html+="<span style='color:#006d21'>"+this.lp.processApplication+"</span><span>"+this.data.applicationName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  249. }
  250. if (this.data.processName){
  251. html+="<span style='color:#006d21'>"+this.lp.process+"</span><span>"+this.data.processName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  252. }
  253. if (this.data.appName){
  254. html+="<span style='color:#006d21'>"+this.lp.cmsApplication+"</span><span>"+this.data.appName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  255. }
  256. if (this.data.categoryName){
  257. html+="<span style='color:#006d21'>"+this.lp.category+"</span><span>"+this.data.categoryName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  258. }
  259. if (this.data.creatorPerson){
  260. html+="<span style='color:#006d21'>"+this.lp.creatorPerson+"</span><span>"+MWF.name.cn(this.data.creatorPerson)+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  261. }
  262. if (this.data.creatorUnit){
  263. html+="<span style='color:#006d21'>"+this.lp.unit+"</span><span>"+MWF.name.cn(this.data.creatorUnit)+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  264. }
  265. if (this.data.type==="workCompleted"){
  266. html+="<span style='color: #f27b5f'>"+this.lp.completed+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  267. }
  268. if (this.data.lastUpdateTime){
  269. html+="<span>"+this.data.lastUpdateTime+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  270. }
  271. this.inforNode.set("html", html);
  272. }
  273. });