ApplicationsContent.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. var key = _self.content.searchAppInputNode.get("value");
  172. if (key==undefined) key="";
  173. _self.content.querydata["name"]=key;
  174. _self.loadApplications();
  175. }
  176. }
  177. })
  178. },
  179. showApplications: function(data){
  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-40;
  185. //appwidth = (appsdivwidth-200)/7;
  186. rowappnum = parseInt(appsdivwidth/240);
  187. rowappmargin = (appsdivwidth/240-rowappnum) * 240 / (rowappnum-1);
  188. if (rowappmargin<10){
  189. rowappnum = rowappnum -1;
  190. rowappmargin = (appsdivwidth/240-rowappnum) * 240 / (rowappnum-1)
  191. }
  192. //appsdiv.setStyle("width","calc("+appwidth+"px)");
  193. //appsdiv.setStyle("margin-left","10px");
  194. data.each(function(d, i){
  195. this.loadCertainApplication(appsdiv, d, i,rowappnum,rowappmargin);
  196. }.bind(this));
  197. },
  198. loadCertainApplication: function(appsdiv, d, i,rowappnum,rowappmargin){
  199. //app 排列 begin
  200. var applicationdiv = new Element("div",{"class":"o2_appmarket_application"}).inject(appsdiv);
  201. if ((i+1)%rowappnum!=0){
  202. applicationdiv.setStyle("margin-right",rowappmargin+"px");
  203. }else{
  204. applicationdiv.setStyle("margin-right","30px");
  205. }
  206. var applicationicon = new Element("div",{"class":"o2_appmarket_application_icon"}).inject(applicationdiv);
  207. applicationicon.setStyle("background-image", "url(data:image/png;base64,"+d.icon+")");
  208. var applicationinfo = new Element("div",{"class":"o2_appmarket_application_info"}).inject(applicationdiv);
  209. var applicationinfo_name = new Element("div",{"text":d.name,"class":"o2_appmarket_application_info_name"}).inject(applicationinfo);
  210. //var applicationinfo_recommend = new Element("div",{"text":d.recommend,"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  211. //推荐指数改为显示评星
  212. var applicationinfo_star = new Element("div",{"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  213. var grade = d.grade;
  214. var intgrade = parseInt(grade);
  215. var dotgrade = grade - intgrade;
  216. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  217. new Element("img",{"src":this.app.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star)
  218. }
  219. if (dotgrade>=0.5){
  220. new Element("img",{"src":this.app.iconPath+"halffiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  221. intgrade++;
  222. }
  223. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  224. new Element("img",{"src":this.app.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  225. }
  226. var applicationinfo_category = new Element("div",{"text":d.category,"class":"o2_appmarket_application_info_category"}).inject(applicationinfo);
  227. var applicationinfo_bottom = new Element("div",{"class":"o2_appmarket_application_info_bottom"}).inject(applicationinfo);
  228. var applicationinfo_bottom_free = new Element("div",{"text":d.price==0?"Free":d.price+"","class":"o2_appmarket_application_info_bottom_free"}).inject(applicationinfo_bottom);
  229. var applicationinfo_bottom_open = new Element("div",{"class":"o2_appmarket_application_info_bottom_button mainColor_bg"}).inject(applicationinfo_bottom);
  230. var bottomtext =this.app.lp.setup;
  231. if (d.installedVersion && d.installedVersion!=""){
  232. if (d.installedVersion==d.version){
  233. bottomtext = this.app.lp.setupDone;
  234. }else{
  235. bottomtext = this.app.lp.update;
  236. }
  237. }
  238. var applicationinfo_bottom_open_text = new Element("div",{"text":bottomtext,"class":"o2_appmarket_application_info_bottom_button_text"}).inject(applicationinfo_bottom_open);
  239. var _self = this;
  240. applicationicon.store("data", d);
  241. applicationicon.addEvents({
  242. "mouseover": function(){
  243. },
  244. "mouseout": function(){
  245. },
  246. "click": function(e){
  247. var d = this.retrieve("data");
  248. if (d) {
  249. _self.open(e, d);
  250. }
  251. }
  252. })
  253. applicationinfo_bottom_open.store("data",d);
  254. applicationinfo_bottom_open.addEvents({
  255. "click":function(e){
  256. var d = this.retrieve("data");
  257. if (d){
  258. _self.installapp(e,d);
  259. }
  260. }
  261. })
  262. },
  263. installapp:function(e,d){
  264. var p = e.target.getPosition();
  265. var tmpe = {"event": {"x": p.x+40, "y": p.y}};
  266. var confirmtitle = d.installedVersion==""?this.app.lp.confirmsetupTitle:this.app.lp.confirmupdateTitle;
  267. var confirmcontent = d.installedVersion==""?this.app.lp.confirmsetupContent:this.app.lp.confirmupdateContent;
  268. var _self = this;
  269. _self.app.confirm("warn", tmpe, confirmtitle, confirmcontent, 300, 120, function(){
  270. _self.app.mask();
  271. //this.createLoading(this.container,true);
  272. //alert("after createLoading")
  273. _self.actions.MarketAction.installOrUpdate(
  274. d.id,
  275. function( json ){
  276. data = json.data;
  277. _self.app.notice(d.name+" "+_self.app.lp.setupSuccess, "success");
  278. _self.app.unmask();
  279. //this.clearLoading()
  280. }.bind(_self),
  281. function( json ){
  282. data = json.data;
  283. _self.app.unmask();
  284. //this.clearLoading()
  285. }.bind(_self),
  286. true
  287. );
  288. this.close();
  289. }, function(){
  290. this.close();
  291. }, null, null, "o2");
  292. },
  293. open: function(e, d){
  294. var apppar = {};
  295. apppar["appid"] = d.id;
  296. apppar["appname"] = d.name;
  297. layout.openApplication(e, "AppMarketV2.Application", apppar);
  298. },
  299. createLoading: function(node,mask){
  300. //alert("createloading")
  301. this.app.content.mask({
  302. "destroyOnHide": true,
  303. "style": {
  304. "opacity": 0.7,
  305. "background-color": "#999"
  306. },
  307. "loading": true
  308. });
  309. //if (mask) this.mask.loadNode(node);
  310. },
  311. clearLoading: function(){
  312. /*
  313. if (this.loadingAreaNode){
  314. this.loadingAreaNode.destroy();
  315. this.loadingAreaNode = null;
  316. }
  317. */
  318. this.app.content.unmask();
  319. // this.dlg.button.setStyle("display", "block");
  320. }
  321. });