Main.js 12 KB

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