Main.js 13 KB

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