ApplicationsContent.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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": this.app.lp.all,"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.collectToken = "";
  97. this.collectUrl = "";
  98. this.page = 1;
  99. this.pageSize = 100;
  100. this.load();
  101. },
  102. load: function(){
  103. this.loadAppCategorys();
  104. this.loadApplications();
  105. },
  106. loadAppCategorys: function(){
  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. this.emptyLoadContent();
  116. if (this.collectToken=="" || this.collectUrl==""){
  117. //先登录collcect
  118. debugger
  119. this.actions.CollectAction.login(//平台封装好的方法
  120. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  121. if (json.type && json.type=="success"){
  122. data = json.data; //为变量data赋值
  123. this.collectUrl = data.collectUrl;
  124. this.collectToken = data.collectToken;
  125. }
  126. }.bind(this),null,false //同步执行
  127. );
  128. }
  129. this.actions.MarketAction.listPaging(this.page, this.pageSize, this.content.querydata,function(json){
  130. if (json.data && json.data.length){
  131. this.content.currentcategory["name"] = this.content.querydata.category==""||!(this.content.querydata.category)? this.app.lp.all :this.content.querydata.category;
  132. this.content.currentcategory["count"] = json.count;
  133. this.showApplications(json.data);
  134. }
  135. this.fireEvent("load");
  136. }.bind(this));
  137. this.loadBbsInfo(this);
  138. },
  139. reload: function(){
  140. if (!this.content.isLoading) {
  141. this.loadAppCategorys();
  142. this.loadApplications();
  143. }
  144. },
  145. emptyLoadContent: function(){
  146. this.content.appList.empty();
  147. //this.container.removeClass("o2_homepage_area_content_loading").removeClass("icon_loading");
  148. //this.content.noItemNode = new Element("div.o2_appMarket_content_empty_node", {"text": this.app.lp.noRecommend}).inject(this.container);
  149. //var m = (this.content.contentHeight- this.content.noItemNode.getSize().y)/2;
  150. //this.content.noItemNode.setStyle("margin-top", ""+m+"px");
  151. this.content.isLoading = false;
  152. },
  153. showCategorys:function(data){
  154. var categorysdiv = this.content.appCategory;
  155. categorysdiv.empty();
  156. this.loadCertainCategory(categorysdiv, this.app.lp.all );
  157. data.each(function(d,i){
  158. this.loadCertainCategory(categorysdiv,d)
  159. }.bind(this))
  160. },
  161. loadBbsInfo: function(content){
  162. var json = null;
  163. debugger;
  164. var commenturl = content.collectUrl +'/o2_collect_assemble/jaxrs/collect/config/key/(0)?time='+(new Date()).getMilliseconds();
  165. debugger;
  166. /*var res = new Request.JSON({
  167. url: commenturl,
  168. headers : {'x-debugger' : true,'Authorization':content.collectToken,'c-token':content.collectToken},
  169. secure: false,
  170. method: "get",
  171. async: false,
  172. withCredentials: true,
  173. contentType : 'application/json',
  174. crossDomain : true,
  175. onSuccess: function(responseJSON, responseText){
  176. json = responseJSON;
  177. debugger;
  178. this.bbsUrlPath = json.data.bbsUrlPath;
  179. this.bbsUrl = json.data.bbsUrl;
  180. }.bind(this),
  181. onFailure: function(xhr){
  182. o2.runCallback(callback, "requestFailure", [xhr]);
  183. }.bind(this),
  184. onError: function(text, error){
  185. o2.runCallback(callback, "error", [text, error]);
  186. }.bind(this)
  187. });
  188. res.send();*/
  189. this.actions.CollectAction.bbs(//平台封装好的方法
  190. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  191. if (json.type && json.type=="success"){debugger;
  192. data = json.data; //为变量data赋值
  193. this.bbsUrlPath = data.bbsUrlPath;
  194. this.bbsUrl = data.bbsUrl;
  195. }
  196. }.bind(this),null,false //同步执行
  197. );
  198. },
  199. loadCommentsGrade: function(appdata,callback){
  200. debugger;
  201. var json = null;
  202. var commenturl = this.bbsUrlPath +'/x_bbs_assemble_control/jaxrs/subject/statgrade/sectionName/'+encodeURI(this.app.lp.title)+'/subjectType/'+encodeURI(appdata.name)+'?time='+(new Date()).getMilliseconds();
  203. var res = new Request.JSON({
  204. url: commenturl,
  205. headers : {'x-debugger' : true,'Authorization':this.collectToken,'c-token':this.collectToken},
  206. secure: false,
  207. method: "get",
  208. async: true,
  209. withCredentials: true,
  210. contentType : 'application/json',
  211. crossDomain : true,
  212. onSuccess: function(responseJSON, responseText){
  213. debugger;
  214. //json = responseJSON;
  215. if(callback)callback( responseJSON );
  216. }.bind(this)
  217. });
  218. res.send();
  219. //return json;
  220. },
  221. loadCertainCategory:function(categorysdiv,d){
  222. var _self = this;
  223. var categorydiv = new Element("span",{"text":d,"class":"o2_appmarket_appcategory"}).inject(categorysdiv);
  224. categorydiv.store("data",d);
  225. if (_self.content.querydata["category"]){
  226. if ((_self.content.querydata["category"]=="" && d==_self.app.lp.all )||(_self.content.querydata["category"]==d)){
  227. categorydiv.removeClass("o2_appmarket_appcategory").addClass("mainColor_color").addClass("o2_appmarket_appcategory_current");
  228. }
  229. }
  230. categorydiv.addEvents({
  231. "mouseover":function(){
  232. this.addClass("o2_appmarket_appcategory_tab_over");
  233. },
  234. "mouseout":function(){
  235. this.removeClass("o2_appmarket_appcategory_tab_over");
  236. },
  237. "click":function(e){
  238. var d = this.retrieve("data");
  239. this.getParent().getElements(".o2_appmarket_appcategory_current").removeClass("mainColor_color").removeClass("o2_appmarket_appcategory_current").addClass("o2_appmarket_appcategory");
  240. this.removeClass("o2_appmarket_appcategory").addClass("mainColor_color").addClass("o2_appmarket_appcategory_current");
  241. if (d){
  242. if ( d== _self.app.lp.all ){
  243. _self.content.querydata["category"]="";
  244. }else{
  245. _self.content.querydata["category"]=d;
  246. }
  247. var key = _self.content.searchAppInputNode.get("value");
  248. if (key==undefined) key="";
  249. _self.content.querydata["name"]=key;
  250. _self.loadApplications();
  251. }
  252. }
  253. })
  254. },
  255. showApplications: function(data){
  256. //show category count
  257. //this.content.appCategory_count.empty();
  258. //new Element("div",{"text":this.content.currentcategory.name+"("+this.content.currentcategory.count+")"}).inject(this.content.appCategory_count);
  259. var appsdiv = this.content.appList;
  260. var appsdivwidth= appsdiv.clientWidth-40;
  261. //appwidth = (appsdivwidth-200)/7;
  262. rowappnum = parseInt(appsdivwidth/240);
  263. rowappmargin = (appsdivwidth/240-rowappnum) * 240 / (rowappnum-1);
  264. if (rowappmargin<10){
  265. rowappnum = rowappnum -1;
  266. rowappmargin = (appsdivwidth/240-rowappnum) * 240 / (rowappnum-1)
  267. }
  268. //appsdiv.setStyle("width","calc("+appwidth+"px)");
  269. //appsdiv.setStyle("margin-left","10px");
  270. data.each(function(d, i){
  271. this.loadCertainApplication(appsdiv, d, i,rowappnum,rowappmargin);
  272. }.bind(this));
  273. },
  274. loadCertainApplication: function(appsdiv, d, i,rowappnum,rowappmargin){
  275. //app 排列 begin
  276. debugger;
  277. //var gradeData = this.loadCommentsGrade(d);
  278. this.loadCommentsGrade(d,function( gradeData ){
  279. debugger;
  280. var applicationdiv = new Element("div",{"class":"o2_appmarket_application"}).inject(appsdiv);
  281. if ((i+1)%rowappnum!=0){
  282. applicationdiv.setStyle("margin-right",rowappmargin+"px");
  283. }else{
  284. applicationdiv.setStyle("margin-right","0px");
  285. }
  286. var applicationicon = new Element("div",{"class":"o2_appmarket_application_icon"}).inject(applicationdiv);
  287. applicationicon.setStyle("background-image", "url(data:image/png;base64,"+d.icon+")");
  288. var applicationinfo = new Element("div",{"class":"o2_appmarket_application_info"}).inject(applicationdiv);
  289. var applicationinfo_name = new Element("div",{"text":d.name,"class":"o2_appmarket_application_info_name","title":d.name}).inject(applicationinfo);
  290. //var applicationinfo_recommend = new Element("div",{"text":d.recommend,"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  291. //推荐指数改为显示评星
  292. var applicationinfo_star = new Element("div",{"class":"o2_appmarket_application_info_recommend"}).inject(applicationinfo);
  293. var commentcount = 0;
  294. var grade = 0;
  295. var totalgrade = 0;
  296. var commentratiolist = gradeData.data;
  297. var gradeList = ["0","0","0","0","0"];
  298. commentratiolist.each(function(pergrade){
  299. gradeList[parseInt(pergrade.grade)-1]=pergrade.count;
  300. commentcount +=parseInt(pergrade.count)
  301. }.bind(this));
  302. gradeList.each(function(pergrade,index){
  303. totalgrade += parseInt(pergrade)*(index+1)
  304. })
  305. if (commentcount>0){
  306. grade = this.numberFix(totalgrade/commentcount,1)
  307. }
  308. var intgrade = parseInt(grade);
  309. var dotgrade = grade - intgrade;
  310. /*var grade = d.grade;
  311. var intgrade = parseInt(grade);
  312. var dotgrade = grade - intgrade;*/
  313. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  314. new Element("img",{"src":this.app.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star)
  315. }
  316. if (dotgrade>=0.5){
  317. new Element("img",{"src":this.app.iconPath+"halffiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  318. intgrade++;
  319. }
  320. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  321. new Element("img",{"src":this.app.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_info_starpic"}).inject(applicationinfo_star);
  322. }
  323. var applicationinfo_category = new Element("div",{"text":d.category,"class":"o2_appmarket_application_info_category"}).inject(applicationinfo);
  324. var applicationinfo_bottom = new Element("div",{"class":"o2_appmarket_application_info_bottom"}).inject(applicationinfo);
  325. var applicationinfo_bottom_free = new Element("div",{"text":d.price==0?"Free":d.price+"","class":"o2_appmarket_application_info_bottom_free"}).inject(applicationinfo_bottom);
  326. var applicationinfo_bottom_open = new Element("div",{"class":"o2_appmarket_application_info_bottom_button mainColor_bg"}).inject(applicationinfo_bottom);
  327. var bottomtext =this.app.lp.setup;
  328. if (d.installedVersion && d.installedVersion!=""){
  329. if (d.installedVersion==d.version){
  330. bottomtext = this.app.lp.setupDone;
  331. }else{
  332. bottomtext = this.app.lp.update;
  333. }
  334. }
  335. var applicationinfo_bottom_open_text = new Element("div",{"text":bottomtext,"class":"o2_appmarket_application_info_bottom_button_text"}).inject(applicationinfo_bottom_open);
  336. var _self = this;
  337. applicationicon.store("data", d);
  338. applicationicon.addEvents({
  339. "mouseover": function(){
  340. },
  341. "mouseout": function(){
  342. },
  343. "click": function(e){
  344. var d = this.retrieve("data");
  345. if (d) {
  346. _self.open(e, d);
  347. }
  348. }
  349. })
  350. applicationinfo_bottom_open.store("data",d);
  351. applicationinfo_bottom_open.addEvents({
  352. "click":function(e){
  353. var d = this.retrieve("data");
  354. if (d){
  355. _self.installapp(e,d);
  356. }
  357. }
  358. });
  359. }.bind(this)
  360. );
  361. },
  362. installapp:function(e,d){
  363. var p = e.target.getPosition();
  364. var tmpe = {"event": {"x": p.x+40, "y": p.y}};
  365. var confirmtitle = d.installedVersion==""?this.app.lp.confirmsetupTitle:this.app.lp.confirmupdateTitle;
  366. var confirmcontent = d.installedVersion==""?this.app.lp.confirmsetupContent:this.app.lp.confirmupdateContent;
  367. var _self = this;
  368. _self.app.confirm("warn", tmpe, confirmtitle, confirmcontent, 300, 120, function(){
  369. _self.app.mask();
  370. //this.createLoading(this.container,true);
  371. //alert("after createLoading")
  372. _self.actions.MarketAction.installOrUpdate(
  373. d.id,
  374. function( json ){
  375. data = json.data;
  376. _self.app.notice(d.name+" "+_self.app.lp.setupSuccess, "success");
  377. _self.app.unmask();
  378. //this.clearLoading()
  379. }.bind(_self),
  380. function( json ){
  381. data = json.data;
  382. _self.app.unmask();
  383. //this.clearLoading()
  384. }.bind(_self),
  385. true
  386. );
  387. this.close();
  388. }, function(){
  389. this.close();
  390. }, null, null, "o2");
  391. },
  392. open: function(e, d){
  393. var apppar = {};
  394. apppar["appid"] = d.id;
  395. apppar["appname"] = d.name;
  396. layout.openApplication(e, "AppMarketV2.Application", apppar);
  397. },
  398. createLoading: function(node,mask){
  399. //alert("createloading")
  400. this.app.content.mask({
  401. "destroyOnHide": true,
  402. "style": {
  403. "opacity": 0.7,
  404. "background-color": "#999"
  405. },
  406. "loading": true
  407. });
  408. //if (mask) this.mask.loadNode(node);
  409. },
  410. numberFix:function(data,n){
  411. var numbers = '';
  412. // 保留几位小数后面添加几个0
  413. for (var i = 0; i < n; i++) {
  414. numbers += '0';
  415. }
  416. var s = 1 + numbers;
  417. // 如果是整数需要添加后面的0
  418. var spot = "." + numbers;
  419. // Math.round四舍五入
  420. // parseFloat() 函数可解析一个字符串,并返回一个浮点数。
  421. var value = Math.round(parseFloat(data) * s) / s;
  422. // 从小数点后面进行分割
  423. var d = value.toString().split(".");
  424. if (d.length == 1) {
  425. value = value.toString();
  426. return value;
  427. }
  428. if (d.length > 1) {
  429. if (d[1].length < n) {
  430. value = value.toString() + "0";
  431. }
  432. return value;
  433. }
  434. },
  435. clearLoading: function(){
  436. /*
  437. if (this.loadingAreaNode){
  438. this.loadingAreaNode.destroy();
  439. this.loadingAreaNode = null;
  440. }
  441. */
  442. this.app.content.unmask();
  443. // this.dlg.button.setStyle("display", "block");
  444. }
  445. });