Main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.size||0);
  99. text = text.replace("{time}", t);
  100. this.resultInfor.set("text", text);
  101. this.resultInfor.setStyles(this.css.searchResultInfor);
  102. this.result = json.data;
  103. this.createPages();
  104. this.showResult();
  105. }.bind(this));
  106. },
  107. createPages: function(){
  108. this.initPage();
  109. this.resultPageArea.empty();
  110. if (this.result.length){
  111. var v = this.result.length/this.pageCount;
  112. this.pages = (v>v.toInt()) ? v.toInt()+1 : v.toInt();
  113. this.currentPage = 1;
  114. var _self = this;
  115. for (var i=1; i<=this.pages; i++){
  116. var node = new Element("div", {"styles": this.css.pageItem, "text": i}).inject(this.resultPageArea);
  117. node.addEvent("click", function(){
  118. _self.resultPageArea.getElement(":nth-child("+_self.currentPage+")").setStyles(_self.css.pageItem);
  119. _self.gotoPage(this.get("text"));
  120. });
  121. }
  122. }
  123. },
  124. gotoPage: function(i){
  125. this.currentPage = i;
  126. this.showResult();
  127. this.resultArea.scrollTop = 0;
  128. },
  129. showResult: function(){
  130. var startIdx = (this.currentPage-1)*this.pageCount;
  131. var endIdx = this.currentPage*this.pageCount-1;
  132. this.resultPageArea.getElement(":nth-child("+this.currentPage+")").setStyles(this.css.pageItem_current);
  133. this.resultContent.empty();
  134. var n = Math.min(this.result.length-1, endIdx);
  135. for (var i=startIdx; i<=n; i++){
  136. var d = this.result[i];
  137. new MWF.xApplication.Search.ResaultItem(this, d);
  138. }
  139. }
  140. });
  141. MWF.xApplication.Search.ResaultItem = new Class({
  142. initialize: function(app, data){
  143. this.app = app;
  144. this.content = this.app.resultContent;
  145. this.lp = this.app.lp;
  146. this.css = this.app.css;
  147. this.data = data;
  148. this.checkPermission(function(){
  149. this.load();
  150. }.bind(this));
  151. },
  152. checkPermission: function(callback){
  153. if (!this.data.permission){
  154. if (this.data.type==="work"){
  155. MWF.Actions.get("x_processplatform_assemble_surface").getWork(this.data.reference, function(){
  156. this.data.permission = "y";
  157. if (callback) callback();
  158. }.bind(this), function(){
  159. this.data.permission = "n";
  160. if (callback) callback();
  161. }.bind(this))
  162. }
  163. if (this.data.type==="workCompleted"){
  164. MWF.Actions.get("x_processplatform_assemble_surface").getWorkCompleted(this.data.reference, function(){
  165. this.data.permission = "y";
  166. if (callback) callback();
  167. }.bind(this), function(){
  168. this.data.permission = "n";
  169. if (callback) callback();
  170. }.bind(this))
  171. }
  172. if (this.data.type==="cms"){
  173. MWF.Actions.get("x_cms_assemble_control").getDocument(this.data.reference, function(){
  174. this.data.permission = "y";
  175. if (callback) callback();
  176. }.bind(this), function(){
  177. this.data.permission = "n";
  178. if (callback) callback();
  179. }.bind(this))
  180. }
  181. }else{
  182. if (callback) callback();
  183. }
  184. },
  185. load: function(){
  186. this.node = new Element("div", {"styles": this.css.resaultItemNode}).inject(this.content);
  187. this.titleNode = new Element("div", {"styles": this.css.resaultItemTitleNode}).inject(this.node);
  188. this.summaryNode = new Element("div", {"styles": this.css.resaultItemSummaryNode}).inject(this.node);
  189. this.inforNode = new Element("div", {"styles": this.css.resaultItemInforNode}).inject(this.node);
  190. this.loadTitle();
  191. this.loadSummary();
  192. this.loadInfor();
  193. },
  194. loadTitle: function(){
  195. if (this.data.permission==="n"){
  196. this.titleNode.setStyles(this.css.resaultItemTitleNode_gray);
  197. this.titleNode.set("text", (this.data.title) ? this.data.title+" ("+this.lp.refuse+")" : this.lp.nonamed+" ("+this.lp.refuse+")");
  198. }else{
  199. this.titleNode.set("text", this.data.title || this.lp.nonamed);
  200. this.titleNode.addEvents({
  201. "mouseover": function(){this.setStyle("text-decoration", "underline")},
  202. "mouseout": function(){this.setStyle("text-decoration", "none");},
  203. "click": function(e){
  204. this.openItem(e);
  205. }.bind(this)
  206. });
  207. }
  208. },
  209. openItem: function(e){
  210. if (this.data.type==="work"){
  211. layout.desktop.openApplication(e, "process.Work", {"workId": this.data.reference, "appId": this.data.reference, "docTitle": this.data.title || this.lp.nonamed});
  212. }
  213. if (this.data.type==="workCompleted"){
  214. layout.desktop.openApplication(e, "process.Work", {"workCompletedId": this.data.reference, "appId": this.data.reference, "docTitle": this.data.title || this.lp.nonamed});
  215. }
  216. if (this.data.type==="cms"){
  217. layout.desktop.openApplication(e, "cms.Document", {"documentId": this.data.reference, "appId": this.data.reference, "docTitle": this.data.title || this.lp.nonamed});
  218. }
  219. },
  220. loadSummary: function(){
  221. this.summaryNode.set("text", this.data.summary);
  222. },
  223. loadInfor: function(){
  224. var html = "";
  225. if (this.data.applicationName){
  226. html+="<span style='color:#006d21'>"+this.lp.processApplication+"</span><span>"+this.data.applicationName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  227. }
  228. if (this.data.processName){
  229. html+="<span style='color:#006d21'>"+this.lp.process+"</span><span>"+this.data.processName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  230. }
  231. if (this.data.appName){
  232. html+="<span style='color:#006d21'>"+this.lp.cmsApplication+"</span><span>"+this.data.appName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  233. }
  234. if (this.data.categoryName){
  235. html+="<span style='color:#006d21'>"+this.lp.category+"</span><span>"+this.data.categoryName+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  236. }
  237. if (this.data.creatorPerson){
  238. html+="<span style='color:#006d21'>"+this.lp.creatorPerson+"</span><span>"+MWF.name.cn(this.data.creatorPerson)+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  239. }
  240. if (this.data.creatorUnit){
  241. html+="<span style='color:#006d21'>"+this.lp.unit+"</span><span>"+MWF.name.cn(this.data.creatorUnit)+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  242. }
  243. if (this.data.type==="workCompleted"){
  244. html+="<span style='color: #f27b5f'>"+this.lp.completed+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  245. }
  246. if (this.data.lastUpdateTime){
  247. html+="<span>"+this.data.lastUpdateTime+"</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
  248. }
  249. this.inforNode.set("html", html);
  250. }
  251. });