ApplicationsContent.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. this.loadAppCategorys();
  102. this.loadApplications();
  103. },
  104. loadAppCategorys: function(){
  105. this.actions.MarketAction.listCategory(function(json){
  106. if (json.data && json.data.valueList){
  107. this.showCategorys(json.data.valueList);
  108. }
  109. this.fireEvent("load");
  110. }.bind(this));
  111. },
  112. loadApplications: function(){
  113. this.emptyLoadContent();
  114. this.actions.MarketAction.listPaging(this.page, this.pageSize, this.content.querydata,function(json){
  115. if (json.data && json.data.length){
  116. this.content.currentcategory["name"] = this.content.querydata.category==""||!(this.content.querydata.category)?"全部":this.content.querydata.category;
  117. this.content.currentcategory["count"] = json.count;
  118. this.showApplications(json.data);
  119. }
  120. this.fireEvent("load");
  121. }.bind(this));
  122. },
  123. reload: function(){
  124. if (!this.content.isLoading) {
  125. this.loadAppCategorys();
  126. this.loadApplications();
  127. }
  128. },
  129. emptyLoadContent: function(){
  130. this.content.appList.empty();
  131. //this.container.removeClass("o2_homepage_area_content_loading").removeClass("icon_loading");
  132. //this.content.noItemNode = new Element("div.o2_appMarket_content_empty_node", {"text": this.app.lp.noRecommend}).inject(this.container);
  133. //var m = (this.content.contentHeight- this.content.noItemNode.getSize().y)/2;
  134. //this.content.noItemNode.setStyle("margin-top", ""+m+"px");
  135. this.content.isLoading = false;
  136. },
  137. showCategorys:function(data){
  138. var categorysdiv = this.content.appCategory;
  139. categorysdiv.empty();
  140. this.loadCertainCategory(categorysdiv,"全部")
  141. data.each(function(d,i){
  142. this.loadCertainCategory(categorysdiv,d)
  143. }.bind(this))
  144. },
  145. loadCertainCategory:function(categorysdiv,d){
  146. var _self = this;
  147. var categorydiv = new Element("span",{"text":d,"class":"o2_appmarket_appcategory"}).inject(categorysdiv);
  148. categorydiv.store("data",d);
  149. if (_self.content.querydata["category"]){
  150. if ((_self.content.querydata["category"]=="" && d=="全部")||(_self.content.querydata["category"]==d)){
  151. categorydiv.removeClass("o2_appmarket_appcategory").addClass("mainColor_color").addClass("o2_appmarket_appcategory_current");
  152. }
  153. }
  154. categorydiv.addEvents({
  155. "mouseover":function(){
  156. this.addClass("o2_appmarket_appcategory_tab_over");
  157. },
  158. "mouseout":function(){
  159. this.removeClass("o2_appmarket_appcategory_tab_over");
  160. },
  161. "click":function(e){
  162. var d = this.retrieve("data");
  163. this.getParent().getElements(".o2_appmarket_appcategory_current").removeClass("mainColor_color").removeClass("o2_appmarket_appcategory_current").addClass("o2_appmarket_appcategory");
  164. this.removeClass("o2_appmarket_appcategory").addClass("mainColor_color").addClass("o2_appmarket_appcategory_current");
  165. if (d){
  166. if (d=="全部"){
  167. _self.content.querydata["category"]="";
  168. }else{
  169. _self.content.querydata["category"]=d;
  170. }
  171. _self.loadApplications();
  172. }
  173. }
  174. })
  175. },
  176. showApplications: function(data){
  177. //show category count
  178. //this.content.appCategory_count.empty();
  179. //new Element("div",{"text":this.content.currentcategory.name+"("+this.content.currentcategory.count+")"}).inject(this.content.appCategory_count);
  180. var appsdiv = this.content.appList;
  181. var appsdivwidth= appsdiv.clientWidth-40;
  182. //appwidth = (appsdivwidth-200)/7;
  183. rowappnum = parseInt(appsdivwidth/240);
  184. rowappmargin = (appsdivwidth/240-rowappnum) * 240 / (rowappnum-1);
  185. if (rowappmargin<10){
  186. rowappnum = rowappnum -1;
  187. rowappmargin = (appsdivwidth/240-rowappnum) * 240 / (rowappnum-1)
  188. }
  189. //appsdiv.setStyle("width","calc("+appwidth+"px)");
  190. //appsdiv.setStyle("margin-left","10px");
  191. data.each(function(d, i){
  192. this.loadCertainApplication(appsdiv, d, i,rowappnum,rowappmargin);
  193. }.bind(this));
  194. },
  195. loadCertainApplication: function(appsdiv, d, i,rowappnum,rowappmargin){
  196. //app 排列 begin
  197. var applicationdiv = new Element("div",{"class":"o2_appmarket_application"}).inject(appsdiv);
  198. if ((i+1)%rowappnum!=0){
  199. applicationdiv.setStyle("margin-right",rowappmargin+"px");
  200. }else{
  201. applicationdiv.setStyle("margin-right","30px");
  202. }
  203. var applicationicon = new Element("div",{"class":"o2_appmarket_application_icon"}).inject(applicationdiv);
  204. applicationicon.setStyle("background-image", "url(data:image/png;base64,"+d.icon+")");
  205. var applicationinfo = new Element("div",{"class":"o2_appmarket_application_info"}).inject(applicationdiv);
  206. var applicationinfo_name = new Element("div",{"text":d.name,"class":"o2_appmarket_application_info_name"}).inject(applicationinfo);
  207. //var applicationinfo_recommend = new Element("div",{"text":d.recommend,"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  208. //推荐指数改为显示评星
  209. var applicationinfo_star = new Element("div",{"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  210. var grade = d.grade;
  211. var intgrade = parseInt(grade);
  212. var dotgrade = grade - intgrade;
  213. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  214. new Element("img",{"src":this.app.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star)
  215. }
  216. if (dotgrade>=0.5){
  217. new Element("img",{"src":this.app.iconPath+"halffiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  218. intgrade++;
  219. }
  220. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  221. new Element("img",{"src":this.app.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  222. }
  223. var applicationinfo_category = new Element("div",{"text":d.category,"class":"o2_appmarket_application_info_category"}).inject(applicationinfo);
  224. var applicationinfo_bottom = new Element("div",{"class":"o2_appmarket_application_info_bottom"}).inject(applicationinfo);
  225. var applicationinfo_bottom_free = new Element("div",{"text":d.price==0?"Free":d.price+"","class":"o2_appmarket_application_info_bottom_free"}).inject(applicationinfo_bottom);
  226. var applicationinfo_bottom_open = new Element("div",{"class":"o2_appmarket_application_info_bottom_button mainColor_bg"}).inject(applicationinfo_bottom);
  227. var bottomtext =this.app.lp.setup;
  228. if (d.installedVersion && d.installedVersion!=""){
  229. if (d.installedVersion==d.version){
  230. bottomtext = this.app.lp.setupDone;
  231. }else{
  232. bottomtext = this.app.lp.update;
  233. }
  234. }
  235. var applicationinfo_bottom_open_text = new Element("div",{"text":bottomtext,"class":"o2_appmarket_application_info_bottom_button_text"}).inject(applicationinfo_bottom_open);
  236. var _self = this;
  237. applicationicon.store("data", d);
  238. applicationicon.addEvents({
  239. "mouseover": function(){
  240. },
  241. "mouseout": function(){
  242. },
  243. "click": function(e){
  244. var d = this.retrieve("data");
  245. if (d) {
  246. _self.open(e, d);
  247. }
  248. }
  249. })
  250. applicationinfo_bottom_open.store("data",d);
  251. applicationinfo_bottom_open.addEvents({
  252. "click":function(e){
  253. var d = this.retrieve("data");
  254. if (d){
  255. _self.installapp(e,d);
  256. }
  257. }
  258. })
  259. },
  260. installapp:function(e,d){
  261. var p = e.target.getPosition();
  262. var tmpe = {"event": {"x": p.x+40, "y": p.y}};
  263. var confirmtitle = d.installedVersion==""?this.app.lp.confirmsetupTitle:this.app.lp.confirmupdateTitle;
  264. var confirmcontent = d.installedVersion==""?this.app.lp.confirmsetupContent:this.app.lp.confirmupdateContent;
  265. var _self = this;
  266. MWF.xDesktop.confirm("warn", tmpe, confirmtitle, confirmcontent, 300, 120, function(){
  267. _self.app.mask();
  268. //this.createLoading(this.container,true);
  269. //alert("after createLoading")
  270. _self.actions.MarketAction.installOrUpdate(
  271. d.id,
  272. function( json ){
  273. data = json.data;
  274. _self.app.notice(d.name+" "+_self.app.lp.setupSuccess, "success");
  275. _self.app.unmask();
  276. //this.clearLoading()
  277. }.bind(_self),
  278. function( json ){
  279. data = json.data;
  280. _self.app.unmask();
  281. //this.clearLoading()
  282. }.bind(_self),
  283. true
  284. );
  285. this.close();
  286. }, function(){
  287. this.close();
  288. }, null, null, "o2");
  289. },
  290. open: function(e, d){
  291. var apppar = {};
  292. apppar["appid"] = d.id;
  293. apppar["appname"] = d.name;
  294. layout.openApplication(e, "AppMarketV2.Application", apppar);
  295. },
  296. createLoading: function(node,mask){
  297. //alert("createloading")
  298. this.app.content.mask({
  299. "destroyOnHide": true,
  300. "style": {
  301. "opacity": 0.7,
  302. "background-color": "#999"
  303. },
  304. "loading": true
  305. });
  306. //if (mask) this.mask.loadNode(node);
  307. },
  308. clearLoading: function(){
  309. /*
  310. if (this.loadingAreaNode){
  311. this.loadingAreaNode.destroy();
  312. this.loadingAreaNode = null;
  313. }
  314. */
  315. this.app.content.unmask();
  316. // this.dlg.button.setStyle("display", "block");
  317. }
  318. });