Controller.prototype.init = function(callback) { var controller = this; this.recordURL(); this.callback = callback; orgId = Application.organization.id; sourceType = Helper.param.hash('stype') || 'EVENT'; sourceId = Helper.param.hash('sid'); // 设置后退默认链接 if (sourceType == 'ARTICLE') { this.backURL = '#organization/' + orgId + '/article/' + sourceId + '/info'; } else if (sourceType == 'EVENT') { this.backURL = '#organization/' + orgId + '/event/' + sourceId + '/info'; } else if (sourceType == "VOTE_OPTION") { VoteService.option.get(sourceId).done(function(data) { var voteId = data.result.id; controller.backURL = "#organization/" + orgId + "/vote/" + voteId + "/info"; }).fail(function(error) { controller.backURL = "#organization/" + orgId + "/index"; }).always(function() { }); } this.render(); };
Helper.confirm("确定删除该投票选项?", function() { Helper.begin(_btn); VoteService.option.remove(optionId).done(function(data) { renderOptions(); }).fail(function(error) { Helper.alert(error); }).always(function() { Helper.end(_btn); }); });
// 渲染投票选项 function renderOptions() { if (voteId != 'add') { VoteService.option.getList(voteId, 1, 1000).done(function(data) { var options = data.result; var count = options.length; $("#voteMembersContainer").html(template("app/templates/vote/default/members", { count: count, options: options })); }).fail(function(error) { Helper.alert(error); }); } else { $("#voteMembersContainer").html(template("app/templates/vote/default/members", { count: 0, options: [] })); } };
(function request() { VoteService.option.getList(statisticsBox.targetId, 0, 0).done(function(data) { statisticsBox.statisticsData = data.result; if (statisticsBox.statisticsData.length == 0) { modal.html("<div class='text-gray center'>该投票暂未添加选项!</div>"); // Helper.alert("该投票暂未添加选项!", function() { // modal.destroy(); // }); return; } modal.box.find(".nav-loading").addClass("hide"); modal.box.find(".canvas").removeClass("hide"); // statisticsBox.renderLine(); statisticsBox.renderBar(); // statisticsBox.renderPie(); // statisticsBox.renderDoughnut(); }).fail(function(error) { Helper.alert(error); modal.destroy(); }); })();
(function init() { VoteService.option.get(optionId, options.voteInfo.hideVotes).done(function(data) { optionBox.optionInfo = data.result; optionBox.optionInfo.casted = options.voteInfo.castedOptionIds.indexOf(optionId) > -1; modal.html(template("app/templates/vote/option", { option: optionBox.optionInfo, vote: options.voteInfo })); modal.addAction("[data-xx-action='close']", "click", function() { modal.destroy(); }); // 如果允许评论,则渲染评论模块 options.voteInfo.permitComment && (function() { require.async("lib.commentBox", function(CommentBox) { commentBox = CommentBox({ container: modal.box.find("#CommentsContainer"), sourceId: optionId, sourceType: 'VOTE_OPTION', limit: 5, comment: function() { commentBox.innerRender(); }, remove: function() { commentBox.innerRender(); } }); commentBox.innerRender(); }); })(); }).fail(function(error) { Helper.alert(error); modal.destroy(); }); })();
Controller.prototype.render = function() { var controller = this; var callback = this.callback; $("#header").html(template("app/templates/public/header", { title: '选手详情', user: Application.user.info })); // 获取投票信息 var getVoteInfo = VoteService.get(voteId).done(function(data) { VoteInfo = data.result; if (data.time > VoteInfo.endDate) { VoteInfo.state = "OVER"; } else if (data.time < VoteInfo.startDate) { VoteInfo.state = "NOTSTART"; } else { VoteInfo.state = "UNDERWAY"; } // 确保用户已绑定手机号 if (VoteInfo.compulsivelyBindPhoneNumber && !Application.user.info.phoneNumber) { Helper.confirm("投票需要绑定手机号码!", function() { require.async("lib.phoneBindBox", function(PhoneBindBox) { PhoneBindBox({ success: controller.render }); }); }); } }); // 获取投票选项信息 var getOptionInfo = VoteService.option.get(optionId).done(function(data) { OptionInfo = data.result; controller.share(OptionInfo.name, OptionInfo.imgUrl + "@300w_300h_1e_1c", OptionInfo.description, OptionInfo.shareURL); }); // 获取用户已投选项ID集合 var getCastedOptionIds = VoteService.getCastedOptionIds(voteId); $.when(getVoteInfo, getOptionInfo, getCastedOptionIds).done(function(data1, data2, data3) { if (VoteInfo.compulsivelyInWechat && !Helper.browser.wx) { Helper.alert("请在微信中打开该投票页面!"); $("#content").html("<p>该投票已被设置只能在微信浏览器中浏览!</p>"); return; } VoteInfo.castedOptionIds = data3.result; VoteInfo.remainVote = VoteInfo.tickets - VoteInfo.castedOptionIds.length; $.each(VoteInfo.castedOptionIds, function(idx, opid) { if (OptionInfo.id == opid) { OptionInfo.checked = true; return false; }; }); $("#content").html(template("app/templates/vote/player", { option: OptionInfo, vote: VoteInfo, voteId: voteId, orgId: orgId })); // 如果允许评论,则渲染评论模块 VoteInfo.permitComment && renderComments(); // 如果需要关注微信公众号才能投票则验证用户是否关注 if (VoteInfo.permitAttentionComment) { insureAttention(); } }).fail(function(error) { Helper.errorAlert(error); }).always(function() { Helper.execute(callback); }); }