ApplicationsContent.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. MWF.xApplication.AppMarketV2.ApplicationsContent = new Class({
  2. Implements: [Options, Events],
  3. options: {
  4. "view": "applicationsContent.html"
  5. },
  6. initialize: function(app, container, options){
  7. this.setOptions(options);
  8. this.app = app;
  9. this.container = container;
  10. this.viewPath = this.app.path+this.app.options.style+"/"+this.options.view;
  11. debugger;
  12. this.querydata = {};
  13. this.currentcategory = {"name":"全部","count":0};
  14. this.load();
  15. },
  16. load: function(){
  17. debugger;
  18. this.container.loadHtml(this.viewPath, {"bind": {"lp": this.app.lp}, "module": this}, function(){
  19. this.loadApplication(function(){
  20. this.fireEvent("load");
  21. }.bind(this));
  22. }.bind(this));
  23. },
  24. loadApplication: function(callback){
  25. debugger;
  26. if (!this.isLoading){
  27. if (!this.applicationsContentV){
  28. this.applicationsContentV = new MWF.xApplication.AppMarketV2.ApplicationsContent.Applications(this, {
  29. "onLoad": function(){ if (callback) callback(); }
  30. });
  31. }else{
  32. this.applicationsContentV.load();
  33. }
  34. }
  35. },
  36. focusAppSearch: function(){
  37. this.searchAppNode.addClass("layout_content_taskbar_area_search_box_focus");
  38. this.searchAppNode.addClass("mainColor_border");
  39. this.searchAppIconNode.addClass("icon_search_focus");
  40. },
  41. blurAppSearch: function(){
  42. this.searchAppNode.removeClass("layout_content_taskbar_area_search_box_focus");
  43. this.searchAppNode.removeClass("mainColor_border");
  44. this.searchAppIconNode.removeClass("icon_search_focus");
  45. },
  46. searchAppInputKeyDown: function(e){
  47. if (this.searchAppInputNode.get("value")){
  48. this.searchAppClearNode.addClass("icon_clear");
  49. }else{
  50. this.searchAppClearNode.removeClass("icon_clear");
  51. }
  52. if (e.keyCode===13) this.doAppSearch();
  53. },
  54. clearAppSearch: function(){
  55. this.searchAppInputNode.set("value", "");
  56. this.searchAppClearNode.removeClass("icon_clear");
  57. this.clearSearchResult();
  58. },
  59. doAppSearch: function(){
  60. var key = this.searchAppInputNode.get("value");
  61. if (key){
  62. this.querydata["name"]=key;
  63. if (!this.applicationsContentV){
  64. this.applicationsContentV = new MWF.xApplication.AppMarketV2.ApplicationsContent.Applications(this, {
  65. "onLoad": function(){ if (callback) callback(); }
  66. });
  67. }else{
  68. this.applicationsContentV.load();
  69. }
  70. }else{
  71. this.clearSearchResult();
  72. }
  73. },
  74. clearSearchResult: function(){
  75. this.querydata["name"]="";
  76. if (!this.applicationsContentV){
  77. this.applicationsContentV = new MWF.xApplication.AppMarketV2.ApplicationsContent.Applications(this, {
  78. "onLoad": function(){ if (callback) callback(); }
  79. });
  80. }else{
  81. this.applicationsContentV.load();
  82. }
  83. }
  84. });
  85. MWF.xApplication.AppMarketV2.ApplicationsContent.Applications= new Class({
  86. Implements: [Options, Events],
  87. options: {
  88. "type": "applications"
  89. },
  90. initialize: function(content, options){
  91. this.setOptions(options);
  92. this.content = content;
  93. this.app = this.content.app;
  94. this.actions = this.app.actions;
  95. this.container = this.content.container;
  96. this.page = 1;
  97. this.pageSize = 100;
  98. this.load();
  99. },
  100. load: function(){
  101. debugger;
  102. this.loadAppCategorys();
  103. this.loadApplications();
  104. },
  105. loadAppCategorys: function(){
  106. debugger;
  107. this.actions.MarketAction.listCategory(function(json){
  108. if (json.data && json.data.valueList){
  109. this.showCategorys(json.data.valueList);
  110. }
  111. this.fireEvent("load");
  112. }.bind(this));
  113. },
  114. loadApplications: function(){
  115. debugger;
  116. this.emptyLoadContent();
  117. this.actions.MarketAction.listPaging(this.page, this.pageSize, this.content.querydata,function(json){
  118. if (json.data && json.data.length){
  119. debugger;
  120. this.content.currentcategory["name"] = this.content.querydata.category==""||!(this.content.querydata.category)?"全部":this.content.querydata.category;
  121. this.content.currentcategory["count"] = json.count;
  122. this.showApplications(json.data);
  123. }
  124. this.fireEvent("load");
  125. }.bind(this));
  126. },
  127. reload: function(){
  128. if (!this.content.isLoading) {
  129. this.loadAppCategorys();
  130. this.loadApplications();
  131. }
  132. },
  133. emptyLoadContent: function(){
  134. this.content.appList.empty();
  135. //this.container.removeClass("o2_homepage_area_content_loading").removeClass("icon_loading");
  136. //this.content.noItemNode = new Element("div.o2_appMarket_content_empty_node", {"text": this.app.lp.noRecommend}).inject(this.container);
  137. //var m = (this.content.contentHeight- this.content.noItemNode.getSize().y)/2;
  138. //this.content.noItemNode.setStyle("margin-top", ""+m+"px");
  139. this.content.isLoading = false;
  140. },
  141. showCategorys:function(data){
  142. debugger;
  143. var categorysdiv = this.content.appCategory;
  144. categorysdiv.empty();
  145. this.loadCertainCategory(categorysdiv,"全部")
  146. data.each(function(d,i){
  147. this.loadCertainCategory(categorysdiv,d)
  148. }.bind(this))
  149. },
  150. loadCertainCategory:function(categorysdiv,d){
  151. debugger;
  152. var _self = this;
  153. var categorydiv = new Element("span",{"text":d,"class":"o2_appmarket_appcategory"}).inject(categorysdiv);
  154. categorydiv.store("data",d);
  155. categorydiv.addEvents({
  156. "mouseover":function(){
  157. debugger;
  158. this.addClass("o2_appmarket_appcategory_tab_over");
  159. },
  160. "mouseout":function(){
  161. this.removeClass("o2_appmarket_appcategory_tab_over");
  162. },
  163. "click":function(e){
  164. var d = this.retrieve("data");
  165. this.getParent().getElements(".o2_appmarket_appcategory_current").removeClass("mainColor_color").removeClass("o2_appmarket_appcategory_current").addClass("o2_appmarket_appcategory");
  166. this.removeClass("o2_appmarket_appcategory").addClass("mainColor_color").addClass("o2_appmarket_appcategory_current");
  167. if (d){
  168. if (d=="全部"){
  169. _self.content.querydata["category"]="";
  170. }else{
  171. _self.content.querydata["category"]=d;
  172. }
  173. _self.loadApplications();
  174. }
  175. }
  176. })
  177. },
  178. showApplications: function(data){
  179. debugger;
  180. //show category count
  181. //this.content.appCategory_count.empty();
  182. //new Element("div",{"text":this.content.currentcategory.name+"("+this.content.currentcategory.count+")"}).inject(this.content.appCategory_count);
  183. var appsdiv = this.content.appList;
  184. var appsdivwidth= appsdiv.clientWidth-80;
  185. //appwidth = (appsdivwidth-200)/7;
  186. rowappnum = parseInt(appsdivwidth/285);
  187. rowappmargin = (appsdivwidth/285-rowappnum) * 285 / (rowappnum-1);
  188. if (rowappmargin<10){
  189. rowappnum = rowappnum -1;
  190. rowappmargin = (appsdivwidth/285-rowappnum) * 285 / (rowappnum-1)
  191. }
  192. debugger;
  193. //appsdiv.setStyle("width","calc("+appwidth+"px)");
  194. //appsdiv.setStyle("margin-left","10px");
  195. data.each(function(d, i){
  196. this.loadCertainApplication(appsdiv, d, i,rowappnum,rowappmargin);
  197. }.bind(this));
  198. },
  199. loadCertainApplication: function(appsdiv, d, i,rowappnum,rowappmargin){
  200. debugger;
  201. //app 排列 begin
  202. var applicationdiv = new Element("div",{"class":"o2_appmarket_application"}).inject(appsdiv);
  203. if ((i+1)%rowappnum!=0){
  204. applicationdiv.setStyle("margin-right",rowappmargin+"px");
  205. }else{
  206. applicationdiv.setStyle("margin-right","40px");
  207. }
  208. var applicationicon = new Element("div",{"class":"o2_appmarket_application_icon"}).inject(applicationdiv);
  209. applicationicon.setStyle("background-image", "url(data:image/png;base64,"+d.icon+")");
  210. var applicationinfo = new Element("div",{"class":"o2_appmarket_application_info"}).inject(applicationdiv);
  211. var applicationinfo_name = new Element("div",{"text":d.name,"class":"o2_appmarket_application_info_name"}).inject(applicationinfo);
  212. //var applicationinfo_recommend = new Element("div",{"text":d.recommend,"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  213. //推荐指数改为显示评星
  214. var applicationinfo_star = new Element("div",{"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  215. var grade = d.grade;
  216. var intgrade = parseInt(grade);
  217. var dotgrade = grade - intgrade;
  218. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  219. new Element("img",{"src":this.app.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star)
  220. }
  221. if (dotgrade>=0.5){
  222. new Element("img",{"src":this.app.iconPath+"halffiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  223. intgrade++;
  224. }
  225. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  226. new Element("img",{"src":this.app.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  227. }
  228. var applicationinfo_category = new Element("div",{"text":d.category,"class":"o2_appmarket_application_info_category"}).inject(applicationinfo);
  229. var applicationinfo_bottom = new Element("div",{"class":"o2_appmarket_application_info_bottom"}).inject(applicationinfo);
  230. var applicationinfo_bottom_free = new Element("div",{"text":d.price==0?"Free":d.price+"","class":"o2_appmarket_application_info_bottom_free"}).inject(applicationinfo_bottom);
  231. var applicationinfo_bottom_open = new Element("div",{"class":"o2_appmarket_application_info_bottom_button mainColor_bg"}).inject(applicationinfo_bottom);
  232. var bottomtext =this.app.lp.setup;
  233. if (d.installedVersion && d.installedVersion!=""){
  234. if (d.installedVersion==d.version){
  235. bottomtext = this.app.lp.setupDone;
  236. }else{
  237. bottomtext = this.app.lp.update;
  238. }
  239. }
  240. var applicationinfo_bottom_open_text = new Element("div",{"text":bottomtext,"class":"o2_appmarket_application_info_bottom_button_text"}).inject(applicationinfo_bottom_open);
  241. var _self = this;
  242. applicationicon.store("data", d);
  243. applicationicon.addEvents({
  244. "mouseover": function(){
  245. },
  246. "mouseout": function(){
  247. },
  248. "click": function(e){
  249. var d = this.retrieve("data");
  250. if (d) {
  251. _self.open(e, d);
  252. }
  253. }
  254. })
  255. applicationinfo_bottom_open.store("data",d);
  256. applicationinfo_bottom_open.addEvents({
  257. "click":function(e){
  258. var d = this.retrieve("data");
  259. if (d){
  260. _self.installapp(e,d);
  261. }
  262. }
  263. })
  264. },
  265. installapp:function(e,d){
  266. var p = e.target.getPosition();
  267. var tmpe = {"event": {"x": p.x+40, "y": p.y}};
  268. var confirmtitle = d.installedVersion==""?this.app.lp.confirmsetupTitle:this.app.lp.confirmupdateTitle;
  269. var confirmcontent = d.installedVersion==""?this.app.lp.confirmsetupContent:this.app.lp.confirmupdateContent;
  270. var _self = this;
  271. MWF.xDesktop.confirm("warn", tmpe, confirmtitle, confirmcontent, 300, 120, function(){
  272. _self.app.mask();
  273. //this.createLoading(this.container,true);
  274. //alert("after createLoading")
  275. _self.actions.MarketAction.installOrUpdate(
  276. d.id,
  277. function( json ){
  278. data = json.data;
  279. _self.app.notice(d.name+" "+_self.app.lp.setupSuccess, "success");
  280. _self.app.unmask();
  281. //this.clearLoading()
  282. }.bind(_self),
  283. function( json ){
  284. data = json.data;
  285. debugger;
  286. _self.app.unmask();
  287. //this.clearLoading()
  288. }.bind(_self),
  289. true
  290. );
  291. this.close();
  292. }, function(){
  293. this.close();
  294. }, null, null, "o2");
  295. },
  296. open: function(e, d){
  297. var apppar = {};
  298. apppar["appid"] = d.id;
  299. layout.openApplication(e, "AppMarketV2.Application", apppar);
  300. },
  301. createLoading: function(node,mask){
  302. debugger;
  303. //alert("createloading")
  304. this.app.content.mask({
  305. "destroyOnHide": true,
  306. "style": {
  307. "opacity": 0.7,
  308. "background-color": "#999"
  309. },
  310. "loading": true
  311. });
  312. //if (mask) this.mask.loadNode(node);
  313. },
  314. clearLoading: function(){
  315. /*
  316. if (this.loadingAreaNode){
  317. this.loadingAreaNode.destroy();
  318. this.loadingAreaNode = null;
  319. }
  320. */
  321. this.app.content.unmask();
  322. // this.dlg.button.setStyle("display", "block");
  323. }
  324. });