Main.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. MWF.xApplication.AppMarketV2.Application.options.multitask = true;
  2. MWF.require("MWF.widget.MaskNode", null, false);
  3. MWF.xApplication.AppMarketV2.Application.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "mvcStyle": "style.css",
  9. "view": "applicationView.html",
  10. "name": "AppMarketV2.Application",
  11. "icon": "icon.png",
  12. "width": "1000",
  13. "height": "700",
  14. "isResize": true,
  15. "isMax": true,
  16. "title": MWF.xApplication.AppMarketV2.Application.LP.title,
  17. "minHeight": 700
  18. },
  19. onQueryLoad: function(){
  20. this.lp = MWF.xApplication.AppMarketV2.Application.LP;
  21. this.actions = MWF.Actions.load("x_program_center");
  22. this.viewPath = this.path+this.options.style+"/"+this.options.view;
  23. this.iconPath = this.path+this.options.style+"/icon/";
  24. this.collectToken = "";
  25. this.collectUrl = "";
  26. if (!this.status) {
  27. } else {
  28. this.options.appid = this.status.appid;
  29. this.options.appname = this.status.appname;
  30. }
  31. this.appdata = {};
  32. },
  33. mask: function(){
  34. if (!this.maskNode){
  35. this.maskNode = new MWF.widget.MaskNode(this.introducenode, {"style": "bam"});
  36. this.maskNode.load();
  37. }
  38. },
  39. unmask: function(){
  40. if (this.maskNode) this.maskNode.hide(function(){
  41. MWF.release(this.maskNode);
  42. this.maskNode = null;
  43. }.bind(this));
  44. },
  45. loadApplication: function(callback){
  46. if (this.collectToken=="" || this.collectUrl==""){
  47. //先登录collcect
  48. this.actions.CollectAction.login(//平台封装好的方法
  49. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  50. if (json.type && json.type=="success"){
  51. data = json.data; //为变量data赋值
  52. this.collectUrl = data.collectUrl;
  53. this.collectToken = data.collectToken;
  54. this.content.loadHtml(this.viewPath, {"bind": {"lp": this.lp}, "module": this}, function(){
  55. if (!this.options.isRefresh){
  56. this.maxSize(function(){
  57. this.loadIntroduce(callback);
  58. }.bind(this));
  59. }else{
  60. this.loadIntroduce(callback);
  61. }
  62. }.bind(this));
  63. }
  64. }.bind(this),null,false //同步执行
  65. );
  66. }
  67. },
  68. initNodeSize: function(){
  69. this.resizeNodeSize();
  70. this.addEvent("resize", this.resizeNodeSize.bind(this));
  71. },
  72. resizeNodeSize: function(){
  73. var size = this.content.getSize();
  74. var edge = this.introducenode.getEdgeHeight();
  75. var height = size.y - edge;
  76. if (height<this.options.minHeight) height = this.options.minHeight;
  77. this.introducenode.setStyle("height", ""+height+"px");
  78. },
  79. loadIntroduce:function(callback){
  80. this.initNodeSize();
  81. if (this.options.appid){
  82. this.actions.MarketAction.get(this.options.appid,function(json){
  83. if (json.data && json.data.icon){
  84. this.appdata = json.data;
  85. this.setTitle(MWF.xApplication.AppMarketV2.Application.LP.title+"_"+this.appdata.name);
  86. var applicationicon = new Element("div",{"class":"o2_appmarket_application_introduce_icon"}).inject(this.applicationintroduceiconcontain);
  87. applicationicon.setStyle("background-image", "url(data:image/png;base64,"+this.appdata.icon+")");
  88. if (this.applicationintroduceiconcontain.clientWidth<300){
  89. applicationicon.setStyle("width",this.applicationintroduceiconcontain.clientWidth);
  90. applicationicon.setStyle("height",450*this.applicationintroduceiconcontain.clientWidth/300);
  91. }
  92. var price=this.appdata.price>0?this.appdata.price+"":"Free";
  93. this.applicationintroducememofree.set("text",price);
  94. this.applicationintroducememoname.set("text",this.appdata.name);
  95. var grade = this.numberFix(this.appdata.grade,1);
  96. this.applicationintroducememoremarkgrade.set("text",grade);
  97. var intgrade = parseInt(grade);
  98. var dotgrade = grade - intgrade;
  99. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  100. new Element("img",{"src":this.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular)
  101. }
  102. if (dotgrade>=0.5){
  103. new Element("img",{"src":this.iconPath+"halffiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular);
  104. intgrade++;
  105. }
  106. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  107. new Element("img",{"src":this.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.applicationintroducememoremarkiconangular);
  108. }
  109. if (!this.appdata.commentCount) this.appdata.commentCount=0;
  110. this.applicationintroducememoremarkcommentcount.set("text","共"+this.appdata.commentCount+"个评分")
  111. //this.applicationintroducememodownload.set("text",this.appdata.downloadCount);
  112. this.applicationintroducememocategory.set("text","分类:"+this.appdata.category);
  113. this.applicationintroducememocontent.set("text",this.appdata.describe);
  114. //this.applicationintroducedownloadprice.set("text","$"+this.appdata.price);
  115. this.applicationintroducedownloadprice.set("text","");
  116. var bottomtext =this.lp.setup;
  117. if (this.appdata.installedVersion && this.appdata.installedVersion!=""){
  118. if (this.appdata.installedVersion==this.appdata.version){
  119. bottomtext = this.lp.setupDone;
  120. }else{
  121. bottomtext = this.lp.update;
  122. }
  123. }
  124. this.applicationintroducedownloadbtntext.set("text",bottomtext);
  125. var _self = this;
  126. this.applicationintroducedownloadbtn.store("data",this.appdata);
  127. this.applicationintroducedownloadbtn.addEvents({
  128. "click": function(e){
  129. //updateorinstall application
  130. var d = this.retrieve("data");
  131. if (d){
  132. _self.installapp(e,d);
  133. }
  134. }
  135. })
  136. //this.applicationintroducefavbtntext.set("text","下载");
  137. this.loadIntroduceInfo();
  138. }
  139. this.fireEvent("load");
  140. }.bind(this));
  141. }
  142. if (callback) callback();
  143. },
  144. tabover: function(e){
  145. e.currentTarget.addClass("o2_appmarket_appcategory_tab_over");
  146. },
  147. tabout: function(e){
  148. e.currentTarget.removeClass("o2_appmarket_appcategory_tab_over");
  149. //e.currentTarget.removeClass("mainColor_border").removeClass("mainColor_color");
  150. },
  151. mouseover:function(){
  152. this.addClass("o2_appmarket_appcategory_tab_over");
  153. },
  154. mouseout:function(){
  155. this.removeClass("o2_appmarket_appcategory_tab_over");
  156. },
  157. installapp:function(e,d){
  158. var p = e.target.getPosition();
  159. var tmpe = {"event": {"x": p.x+40, "y": p.y}};
  160. var confirmtitle = d.installedVersion==""?this.lp.confirmsetupTitle:this.lp.confirmupdateTitle;
  161. var confirmcontent = d.installedVersion==""?this.lp.confirmsetupContent:this.lp.confirmupdateContent;
  162. var _self = this;
  163. MWF.xDesktop.confirm("warn", tmpe, confirmtitle, confirmcontent, 300, 120, function(){
  164. _self.mask();
  165. //this.createLoading(this.container,true);
  166. //alert("after createLoading")
  167. _self.actions.MarketAction.installOrUpdate(
  168. d.id,
  169. function( json ){
  170. data = json.data;
  171. _self.notice(d.name+" "+_self.lp.setupSuccess, "success");
  172. _self.unmask();
  173. //this.clearLoading()
  174. }.bind(_self),
  175. function( json ){
  176. data = json.data;
  177. _self.unmask();
  178. //this.clearLoading()
  179. }.bind(_self),
  180. true
  181. );
  182. this.close();
  183. }, function(){
  184. this.close();
  185. }, null, null, "o2");
  186. },
  187. loadIntroduceInfo: function(callback){
  188. var _self = this;
  189. this.applicationintroducesinfoTab.getParent().getElements(".o2_appmarket_application_introduce_tab_current").removeClass("mainColor_color").removeClass("o2_appmarket_application_introduce_tab_current").addClass("o2_appmarket_application_introduce_tab");
  190. this.applicationintroducesinfoTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  191. this.applicationintroducecontent.set("html","");
  192. this.applicationintroducecontent.set("html",this.appdata.abort);
  193. this.applicationintroducepicslable.set("html","");
  194. this.applicationintroducepics.set("html","")
  195. this.applicationintroducepicslable.set("html","屏幕截图"); //截图
  196. this.appdata.attList.each(function(peratt,i){
  197. if (peratt.type == "image"){
  198. picdiv = new Element("img",{"class":"o2_appmarket_application_introduce_pic"}).inject(this.applicationintroducepics);
  199. picdiv.setProperty("src", "data:image/png;base64,"+peratt.icon);
  200. picdiv.setProperty("data-original",this.collectUrl +'/o2_collect_assemble/jaxrs/attachment/download/'+peratt.id+"?c-token="+this.collectToken);
  201. picdiv.setProperty("alt",peratt.name);
  202. //picdiv.store("id",peratt.id);
  203. }
  204. }.bind(this));
  205. this.loadImgView(this.appdata.id);
  206. },
  207. loadImgView:function(viewid){
  208. if(this.viewer) this.viewer.destroy();
  209. this.applicationintroducepics.setProperty("id",viewid);
  210. o2.loadCss(this.path+this.options.style+"/viewer.css", this.content,function(){
  211. o2.load(this.path+this.options.style+"/viewer.js", function(){
  212. this.viewer = new Viewer(document.getElementById(viewid), {
  213. url: 'data-original'
  214. });
  215. }.bind(this));
  216. }.bind(this));
  217. },
  218. loadIntroduceDemand:function(callback){
  219. this.applicationintroducedemandTab.getParent().getElements(".o2_appmarket_application_introduce_tab_current").removeClass("mainColor_color").removeClass("o2_appmarket_application_introduce_tab_current").addClass("o2_appmarket_application_introduce_tab");
  220. this.applicationintroducedemandTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  221. this.applicationintroducecontent.set("html","");
  222. this.applicationintroducepicslable.set("html","");
  223. this.applicationintroducepics.set("html","")
  224. this.applicationintroducecontent.set("html",this.appdata.installSteps);
  225. },
  226. loadIntroduceComment:function(callback){
  227. this.applicationintroducecommentTab.getParent().getElements(".o2_appmarket_application_introduce_tab_current").removeClass("mainColor_color").removeClass("o2_appmarket_application_introduce_tab_current").addClass("o2_appmarket_application_introduce_tab");
  228. this.applicationintroducecommentTab.removeClass("o2_appmarket_application_introduce_tab").addClass("mainColor_color").addClass("o2_appmarket_application_introduce_tab_current");
  229. this.applicationintroducecontent.set("html","");
  230. this.applicationintroducepicslable.set("html","");
  231. this.applicationintroducepics.set("html","");
  232. o2.requireApp("AppMarketV2.Application", "Comment", function(){
  233. new MWF.xApplication.AppMarketV2.Application.Comment(this, this.applicationintroducecontent, {
  234. "onLoad": function(){if (callback) callback();}
  235. });
  236. }.bind(this));
  237. },
  238. recordStatus: function(){
  239. debugger;
  240. return {"appid": this.options.appid,"appname":this.options.appname};x
  241. },
  242. numberFix:function(data,n){
  243. var numbers = '';
  244. // 保留几位小数后面添加几个0
  245. for (var i = 0; i < n; i++) {
  246. numbers += '0';
  247. }
  248. var s = 1 + numbers;
  249. // 如果是整数需要添加后面的0
  250. var spot = "." + numbers;
  251. // Math.round四舍五入
  252. // parseFloat() 函数可解析一个字符串,并返回一个浮点数。
  253. var value = Math.round(parseFloat(data) * s) / s;
  254. // 从小数点后面进行分割
  255. var d = value.toString().split(".");
  256. if (d.length == 1) {
  257. value = value.toString();
  258. return value;
  259. }
  260. if (d.length > 1) {
  261. if (d[1].length < n) {
  262. value = value.toString() + "0";
  263. }
  264. return value;
  265. }
  266. }
  267. });