ApplicationsContent.js 14 KB

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