getMessageCountUrl = function(type, status) { return util.getApiUrl({ name: 'getcount', path: 'message', params: { type: type, status: status } }); },
getTongjiNewsUrl = function(beginTime, endTime, type) { return _util.getApiUrl({ "name": "tongad", "params": { 'bt':Math.floor(beginTime/1000), 'et':Math.floor(endTime/1000), 'tp':type } }); },
_createRawModalContentElem: function(item) { var h = []; h.push('<div class="mock-title">吐槽能量池</div>'); h.push('<table class="table table-bordered mock-upload-table"><tbody>'); h.push('<tr><td>标题</td><td>' + item.title + '</td></tr>'); if (!!item.simg) { h.push('<tr><td>广场图</td><td><div class="upload-img-preivew mt10 ml0 hide"><img src="' + item.simg + '"></div></td></tr>'); } h.push('<tr><td>摘要</td><td>' + item.desc + '</td></tr>'); h.push('</tbody></table>'); h.push('<div class="mock-title">吐槽放大镜</div>'); h.push('<table class="table table-bordered mock-upload-table"><tbody>'); if (!!item.img) { h.push('<tr><td>主图</td><td><div class="upload-img-preivew mt10 ml0 hide"><img src="' + item.simg + '"></div></td></tr>'); } h.push('<tr><td>正文</td><td>' + _.unescape(item.content) + '</td></tr>'); h.push('<tr><td>内容类型</td><td>'); switch (item.type) { case '0': h.push('<div>资讯</div>'); break; case '1': h.push('<div>PK</div>'); if ((!!item.ext) && (!_.isEmpty(JSON.parse(item.ext)))) { var ext = JSON.parse(item.ext); h.push('<div class="upload-pk">'); h.push('<div class="upload-pk-item">甲方文案: ' + ext[0]['title'] + '</div>'); h.push('<div class="upload-pk-item">乙方文案: ' + ext[1]['title'] + '</div>'); h.push('</div>'); } break; case '2': h.push('<div>投票</div>'); if ((!!item.ext) && (!_.isEmpty(JSON.parse(item.ext)))) { var ext = JSON.parse(item.ext); h.push('<div class="upload-vote-box">'); _.each(ext, function(vote, index) { h.push('<div class="upload-vote-item">' + vote.title + '</div>'); if (!!vote.img) { h.push('<div class="upload-img-preivew"><img src="' + vote.img + '"/></div>'); } }); h.push('</div>'); } break; } h.push('</td></tr>'); h.push('<tr><td>上线时间</td><td>' + util.dateFormat(item.uptime * 1000, 'yyyy-MM-dd hh:mm') + '</td></tr>'); h.push('</tbody></table>'); h.push(''); $('#msg-raw-modal-loading').addClass('hide'); $('#msg-raw-modal-content').append(h.join('')); },
_createWrapperElem: function() { var h = []; h.push('<div class="mock-hd">广告位编辑</div>'); h.push('<div class="page-content">'); h.push('<ul class="tabs-nav">'); h.push('<li class="tab-nav-item" data-type="0"><a>个人主页</a></li>'); h.push('<li class="tab-nav-item" data-type="1"><a>详情页</a></li>'); h.push('</ul>'); h.push('<div class="tabs-content">'); h.push('<div class="mock-btn mock-btn-red mock-add" data-toggle="modal" id="btnAddNewAd" data-target="#ad-modal-new">+ 新增</div>'); h.push('<div class="modal fade" id="ad-modal-new" tabindex="-1" role="dialog" aria-hidden="true">'); h.push('<div class="modal-dialog">'); h.push('<div class="modal-content">'); h.push('<div class="modal-header">'); h.push('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>'); h.push('<h4 class="modal-title" id="myModalLabel">广告位</h4>'); h.push('</div>'); h.push('<div class="modal-body">'); h.push('<table class="table table-bordered mock-upload-table mock-aditem"><tbody>'); h.push('<tr><td>广告图*</td><td><div class="bg-warning">广告图片尺寸要求:宽720px,高140px。</div><div class="upload-img-box"><div class="upload-img">'); h.push('<span class="errorinfo" for="ad-img" style="display:none;"></span><div class="mock-btn mock-btn-red upload-img-btn">上传广告图</div><input placeholder="广告图片链接" class="form-control upload-img-tx inlineb bgwhite" id="ad-img" readonly="readonly"/><input type="file" accept="image/gif, image/jpeg, image/png" class="hide"></div>'); h.push('<div class="upload-img-preivew mt10 ml0 hide"></div></div></td></tr>'); h.push('<tr><td>广告跳转链接*</td><td><span class="errorinfo" for="ad-link"></span><input class="form-control upload-desc" cols="3" maxlength="100" id="ad-link"/></td></tr>'); h.push('<tr><td>有效期(天)*</td><td><span class="errorinfo" for="ad-expire"></span><div id="ad-expire"></div></td></tr>'); h.push('</tbody></table>'); h.push('</div>'); h.push('<div class="modal-footer">'); h.push('<button type="button" class="btn btn-default data-cancel" data-dismiss="modal">取消</button>'); h.push('<button type="button" class="btn btn-primary data-save">保存</button>'); h.push('</div>'); h.push('</div>'); h.push('</div>'); h.push('</div>'); h.push('<table class="table table-bordered table-hover">'); h.push('<thead><tr><th>id</th><th>广告图片</th><th>广告链接</th><th>有效期</th><th>操作时间</th><th>操作</th></tr></thead><tbody id="ad-table">'); h.push('</tbody></table>'); h.push('<div class="paging hide">'); h.push('<div class="mock-btn mock-btn-white page_pre hide"><</div>'); h.push('<div class="page_num"><span class="page_current"></span><span class="num_gap">/</span><span class="page_total"></span></div>'); h.push('<div class="mock-btn mock-btn-white page_next hide">></div>'); h.push('<input type="text" class="form-control goto_page">'); h.push('<div class="mock-btn mock-btn-white page-go">跳转</div>'); h.push('</div>'); h.push('</div>'); h.push('</div>'); this.element.append(h.join('')); this.renderTable(); $('#ad-expire').append( _util.createSelectElem({ selectClass: 'mock-add-expire', data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] })); },
define(function(require, exports, module) { 'use strict'; var notify = require('mock.plugin.notify'), autosize = require('mock.plugin.autosize.min'), util = require('mock.util'), updateFransCount = null, updateMessageCount = null, globalObject = { callNewMessageMethods: [], callNewFansMethods: [] }, apihost = 'http://' + util.getApiHost(), /** 获得新消息的总数的api地址 * @function * @param {int} type - 2:message 1:fans * @param {int} status - 0:已读 1:未读 */ getMessageCountUrl = function(type, status) { return util.getApiUrl({ name: 'getcount', path: 'message', params: { type: type, status: status } }); }, getNewMessagesCount = function() { $.ajax({ url: getMessageCountUrl(2, 1), crossDomain: true, dataType: 'jsonp', }).done(function(result) { if (!result.errno) { var i; for (i = 0; i < globalObject.callNewMessageMethods.length; i++) { globalObject.callNewMessageMethods[i](+result.data?(+result.data):0); } } }); }, getNewFansCount = function() { $.ajax({ url: getMessageCountUrl(1, 1), crossDomain: true, dataType: 'jsonp', }).done(function(result) {; if (!result.errno) { var i; for (i = 0; i < globalObject.callNewFansMethods.length; i++) { globalObject.callNewFansMethods[i](+result.data); } } }); }, getInfoLoop = function() { getNewMessagesCount(); getNewFansCount(); }; setInterval(getInfoLoop, 60000); getInfoLoop(); $.widget('mock.view', { options: { uploadfile: '/umis/pushc/uploadfile', getaudinews: apihost + '/mock/getaudinews?ua=bd_720_1280_HTC-HTC+One+X-4-0-4_4-2-6-1_j2&cuid=80000000000000000000000000000000|0&fn=?', getaudiadinfo: apihost + '/mock/getaudiadinfo?ua=bd_720_1280_HTC-HTC+One+X-4-0-4_4-2-6-1_j2&cuid=80000000000000000000000000000000|0&fn=?' }, _create: function() { this.render(); this._bindEvents(); this.element.data('widgetCreated', true); }, render: function() { this.element.append(this._createElem()); if (this.element.hasClass('hide')) { this.element.removeClass('hide').addClass('current'); } }, reRender: function() { this.element.addClass('hide').empty(); this.render(); }, getGlobalObject: function() { return globalObject; }, _bindEvents: function() {}, _createElem: function() {}, _updateWrapperElemStatus: function(type) { var $nav = this.element.find('ul.tabs-nav:eq(0)'); $nav.children('li.tab-nav-item-selected').removeClass('tab-nav-item-selected'); $nav.children('li[data-type=' + type + ']').addClass('tab-nav-item-selected'); }, _triggerUploadImg: function(event) { var $input = $(event.target).closest('div.upload-img').children('input'); $input.trigger('click'); return false; }, _uploadImg: function(event) { var self = this, options = this.options, data = new FormData(), img = event.target.files[0], $imgbox = $(event.target).closest('div.upload-img-box'), $tx = $imgbox.find('input.upload-img-tx'), $spanerror = $tx.parent().find('.errorinfo').hide().html(''); if (!img) { return false; } //image can only be png, jpeg or gif. if (!img.type.match('image.*') || !img.name.toLowerCase().match(/(?:gif|jpg|png|jpeg)$/)) { $spanerror.html('图片格式错误,只能上传png, jpg, jpeg, gif格式的图片。'); return false; } // 如果图片尺寸大于100K, 就按照60的质量进行压缩 var bNeedCompress = false; if (img.size > 100 * 1024) { bNeedCompress = true; } if (('' + img.name).match(/\.gif$/i)) { // GIF一定需要压缩, 为了获取到第一帧 bNeedCompress = true; } data.append('file', img); $.ajax({ url: options.uploadfile, data: data, cache: false, contentType: false, processData: false, type: 'POST' }).done(function(res) { if (!res.errno) { var newsrc = res.data; $tx.val(newsrc); autosize($tx); var newImg = new Image(), w, h; newImg.onload = function() { h = newImg.height; w = newImg.width; self._checkImgSize($tx, w, h); if (bNeedCompress) { self._compressImg($tx, newsrc, w, h); } $tx.trigger('change'); } newImg.src = newsrc; } else { notify({ tmpl: 'error', text: res.error }); } }).fail(function() {}); return false; }, _compressImg: function($tx, newsrc, w, h) { var key = $.md5('wisetimgkey_noexpire_3f60e7362b8c23871c7564327a31d9d70' + newsrc); $tx.val('http://cdn01.baidu-img.cn/timg?cbs&quality=60&size=b' + w + '_' + h + '&sec=0&di=' + key + '&src=' + newsrc); autosize($tx); }, _checkImgSize: function($tx, w, h) {}, /*paging*/ _updatePagingStatus: function() { var options = this.options, pn = parseInt(options.pn, 10), totalpage = options.totalpage, $paging = this.element.find('div.paging:eq(0)'); if (totalpage > 1) { var $pre = $paging.children('div.page_pre:eq(0)'), $next = $paging.children('div.page_next:eq(0)'), $cur = $paging.find('span.page_current:eq(0)'), $total = $paging.find('span.page_total:eq(0)'); if ((pn == 0) && (!$pre.hasClass('hide'))) { $pre.addClass('hide'); } else if ((pn > 0) && $pre.hasClass('hide')) { $pre.removeClass('hide'); } if ((pn == (totalpage - 1)) && (!$next.hasClass('hide'))) { $next.addClass('hide'); } else if ((pn < (totalpage - 1)) && $next.hasClass('hide')) { $next.removeClass('hide'); } $cur.text(pn + 1); $total.text(totalpage); if ($paging.hasClass('hide')) { $paging.removeClass('hide'); } } else if (!$paging.hasClass('hide')) { $paging.addClass('hide'); } return false; }, _preGoSiblingPage: function(event) { var options = this.options, pn = parseInt(options.pn, 10), totalpage = options.totalpage, $btn = $(event.target), $paging = this.element.find('div.paging:eq(0)'), $pre = $paging.children('div.page_pre:eq(0)'), $next = $paging.children('div.page_next:eq(0)'), $cur = $paging.find('span.page_current:eq(0)'); if ($btn.hasClass('page_pre')) { pn = pn - 1; } else if ($btn.hasClass('page_next')) { pn = pn + 1; } else if ($btn.hasClass('page_go')) { var page = $paging.find('input.goto_page').val().trim(); if (parseInt(page, 10) && page > 0 && page < totalpage) { pn = page - 1; } else { notify({ tmpl: 'warning', text: '请输入正确的页码。' }); return false; } } if (pn > -1) { this._goSiblingPage(pn); } return false; }, _goSiblingPage: function(pn) {}, showError: function(result) { if (result.errno != 0) { var errorMsg = result.error switch (result.errno) { case 10: errorMsg = "尊敬的用户,您的帐户没有大V权限。"; break; } notify({ tmpl: 'error', text: errorMsg }); } }, // for msgs and msg _showRawModal: function(event) { $('#msg-raw-modal-content').empty(); if ($('#msg-raw-modal-loading').hasClass('hide')) { $('#msg-raw-modal-loading').removeClass('hide'); } var self = this, options = this.options, $a = $(event.target), id = $a.attr('data-id'); $.ajax({ url: options.getaudinews, crossDomain: true, dataType: 'json', data: { id: id } }).done(function(res) { if (!res.errno) { self._createRawModalContentElem(res.data); } else { notify({ tmpl: 'error', text: res.error }); } }); }, _createRawModalContentElem: function(item) { var h = []; h.push('<div class="mock-title">吐槽能量池</div>'); h.push('<table class="table table-bordered mock-upload-table"><tbody>'); h.push('<tr><td>标题</td><td>' + item.title + '</td></tr>'); if (!!item.simg) { h.push('<tr><td>广场图</td><td><div class="upload-img-preivew mt10 ml0 hide"><img src="' + item.simg + '"></div></td></tr>'); } h.push('<tr><td>摘要</td><td>' + item.desc + '</td></tr>'); h.push('</tbody></table>'); h.push('<div class="mock-title">吐槽放大镜</div>'); h.push('<table class="table table-bordered mock-upload-table"><tbody>'); if (!!item.img) { h.push('<tr><td>主图</td><td><div class="upload-img-preivew mt10 ml0 hide"><img src="' + item.simg + '"></div></td></tr>'); } h.push('<tr><td>正文</td><td>' + _.unescape(item.content) + '</td></tr>'); h.push('<tr><td>内容类型</td><td>'); switch (item.type) { case '0': h.push('<div>资讯</div>'); break; case '1': h.push('<div>PK</div>'); if ((!!item.ext) && (!_.isEmpty(JSON.parse(item.ext)))) { var ext = JSON.parse(item.ext); h.push('<div class="upload-pk">'); h.push('<div class="upload-pk-item">甲方文案: ' + ext[0]['title'] + '</div>'); h.push('<div class="upload-pk-item">乙方文案: ' + ext[1]['title'] + '</div>'); h.push('</div>'); } break; case '2': h.push('<div>投票</div>'); if ((!!item.ext) && (!_.isEmpty(JSON.parse(item.ext)))) { var ext = JSON.parse(item.ext); h.push('<div class="upload-vote-box">'); _.each(ext, function(vote, index) { h.push('<div class="upload-vote-item">' + vote.title + '</div>'); if (!!vote.img) { h.push('<div class="upload-img-preivew"><img src="' + vote.img + '"/></div>'); } }); h.push('</div>'); } break; } h.push('</td></tr>'); h.push('<tr><td>上线时间</td><td>' + util.dateFormat(item.uptime * 1000, 'yyyy-MM-dd hh:mm') + '</td></tr>'); h.push('</tbody></table>'); h.push(''); $('#msg-raw-modal-loading').addClass('hide'); $('#msg-raw-modal-content').append(h.join('')); }, _showAdModal: function(event) { $('#msg-ad-modal-content').empty(); if ($('#msg-ad-modal-loading').hasClass('hide')) { $('#msg-ad-modal-loading').removeClass('hide'); } var self = this, options = this.options, $a = $(event.target).closest('div.msg-ad-view'), id = $a.attr('data-id'); $.ajax({ url: options.getaudiadinfo, crossDomain: true, dataType: 'json', data: { id: id } }).done(function(res) { if (!res.errno) { self._createAdModalContentElem(res.data.info); } else { notify({ tmpl: 'error', text: res.error }); } }); }, _createAdModalContentElem: function(item) { var h = []; h.push('<table class="table table-bordered mock-upload-table mock-aditem"><tbody>'); h.push('<tr><td>广告id</td><td>' + item.id + '</td></tr>'); h.push('<tr><td>广告图</td><td><div class="upload-img-preivew ad-img-preivew"><img src="' + item.img + '"></div></td></tr>'); h.push('<tr><td>广告跳转链接</td><td>' + item.link + '</td></tr>'); h.push('<tr><td>有效期(天)</td><td>' + item.expire + '</td></tr>'); h.push('</tbody></table>'); $('#msg-ad-modal-loading').addClass('hide'); $('#msg-ad-modal-content').append(h.join('')); } }); module.exports = $.mock.view; });
_.each(data, function(item, index) { h.push('<tr data-type="' + item.type + '"><td>' + item.id + '</td><td>' + (item.type == 0 ? '个人主页' : '详情页') + '</td><td><div class="ad-img-preivew"><img src="' + item.img + '"/></div></td><td class="wordbreakall">' + item.link + '</td><td>' + item.expire + '天</td><td>' + _util.dateFormat(item.stime * 1000, 'yyyy-MM-dd hh:mm') + '</td></tr>'); });
define(function(require, exports, module) { 'use strict'; var _view = require('mock.view'), notify = require('mock.plugin.notify'), _util = require('mock.util'), apihost = 'http://'+_util.getApiHost(); $.widget('mock.ads', _view, { options: { getmyadlist: apihost+'/mock/getmyadlist?&ua=bd_720_1280_HTC-HTC+One+X-4-0-4_4-2-6-1_j2&cuid=80000000000000000000000000000000|0&fn=?', audiaddo: apihost+'/mock/audiaddo?ua=bd_720_1280_HTC-HTC+One+X-4-0-4_4-2-6-1_j2&cuid=80000000000000000000000000000000|0&fn=?', ps: 100, tp_audit: 3 }, render: function(opt) { var options = this.options; _.extend(options, opt); this._createWrapperElem(); }, renderTable: function() { var self = this, options = this.options; this._updateWrapperElemStatus(options.type); $.ajax({ url: options.getmyadlist, crossDomain: true, dataType: 'jsonp', type: 'GET', data: { type: options.type, pn: options.pn, ps: options.ps } }).done(function(res) { if (!res.errno) { options.allcount = res.data.allcount; options.totalpage = Math.ceil(options.allcount / options.ps); self._updatePagingStatus(); self._resetFilter(); $('#ads-table').addClass('hide').empty().append(self._createTableElem(res.data.list)).removeClass('hide'); } else { notify({ tmpl: 'error', text: res.error }) } }); }, reRender: function(opt) { var options = this.options; _.extend(options, opt); this.renderTable(); }, _bindEvents: function() { this._on(this.element, { 'click li.tab-nav-item': this._goPage, 'change select.ads-stype': this._filterAds, 'click div.data-audit': this._auditAd, 'click div.page_pre': this._preGoSiblingPage, 'click div.page_next': this._preGoSiblingPage, 'click div.page_go': this._preGoSiblingPage }); }, _createWrapperElem: function() { var h = []; h.push('<div class="mock-hd">广告位状态管理</div>'); h.push('<div class="page-content">'); h.push('<ul class="tabs-nav" id="ads-nav">'); h.push('<li class="tab-nav-item" data-type="2"><a>已上线</a></li>'); h.push('<li class="tab-nav-item" data-type="1"><a>待审核</a></li>'); h.push('<li class="tab-nav-item" data-type="0"><a>已保存</a></li>'); h.push('<li class="tab-nav-item" data-type="4"><a>未通过审核</a></li>'); h.push('<li class="tab-nav-item" data-type="3"><a>已删除</a></li>'); h.push('</ul>'); h.push('<div class="tabs-content">'); h.push('<table class="table table-bordered table-hover" id="ads-table">'); h.push('</table>'); h.push('<div class="paging hide">'); h.push('<div class="mock-btn mock-btn-white page_pre hide"><</div>'); h.push('<div class="page_num"><span class="page_current"></span><span class="num_gap">/</span><span class="page_total"></span></div>'); h.push('<div class="mock-btn mock-btn-white page_next hide">></div>'); h.push('<input type="text" class="form-control goto_page">'); h.push('<div class="mock-btn mock-btn-white page-go">跳转</div>'); h.push('</div>'); h.push('</div>'); this.element.append(h.join('')); this.renderTable(); }, _createTableElem: function(data) { var options = this.options; switch (options.type) { case '0': case '4': return this._createSaveTable(data); break; case '1': case '2': case '3': return this._createCommonTable(data); break; } }, _createSaveTable: function(data) { var h = []; h.push('<thead><tr><th>id</th><th><select class="form-control ads-stype" id="ads-stype"><option selected="selected" value="2">全部广告</option><option value="0">个人主页</option><option value="1">详情页</option></select></th><th>广告图片</th><th>广告链接</th><th>有效期</th><th>操作时间</th><th>操作</th></tr></thead>'); h.push('<tbody>'); if (!_.isEmpty(data)) { _.each(data, function(item, index) { h.push('<tr data-type="' + item.type + '"><td>' + item.id + '</td><td>' + (item.type == 0 ? '个人主页' : '详情页') + '</td><td><div class="ad-img-preivew"><img src="' + item.img + '"/></div></td><td class="wordbreakall">' + item.link + '</td><td>' + item.expire + '天</td><td>' + _util.dateFormat(item.stime * 1000, 'yyyy-MM-dd hh:mm') + '</td><td><div class="mock-btn mock-btn-red mock-btn-s data-audit" data-id="' + item.id + '">提交</div></td></tr>'); }); } else { h.push('<tr><td colspan="7">没有数据</td></tr>'); } h.push('</tbody>'); return h.join(''); }, _createCommonTable: function(data) { var h = []; h.push('<thead><tr><th>id</th><th><select class="form-control ads-stype" id="ads-stype"><option selected="selected" value="2">全部广告</option><option value="0">个人主页</option><option value="1">详情页</option></select></th><th>广告图片</th><th>广告链接</th><th>有效期</th><th>操作时间</th></tr></thead>'); h.push('<tbody>'); if (!_.isEmpty(data)) { _.each(data, function(item, index) { h.push('<tr data-type="' + item.type + '"><td>' + item.id + '</td><td>' + (item.type == 0 ? '个人主页' : '详情页') + '</td><td><div class="ad-img-preivew"><img src="' + item.img + '"/></div></td><td class="wordbreakall">' + item.link + '</td><td>' + item.expire + '天</td><td>' + _util.dateFormat(item.stime * 1000, 'yyyy-MM-dd hh:mm') + '</td></tr>'); }); } else { h.push('<tr><td colspan="6">没有数据</td></tr>'); } h.push('</tbody>'); return h.join(''); }, _goSiblingPage: function(pn) { var router = new Backbone.Router; router.navigate('ads/' + this.options.type + '/' + pn, { trigger: true }); return false; }, _goPage: function(event) { var type = $(event.target).closest('li.tab-nav-item').attr('data-type'); var router = new Backbone.Router; router.navigate('ads/' + type, { trigger: true }); return false; }, _filterAds: function(event) { var selectedType = $(event.target).val(), $ads = $('#ads-table').children('tbody'); switch (selectedType) { case '0': case '1': $ads.children('tr').addClass('hide'); $ads.children('tr[data-type=' + selectedType + ']').removeClass('hide'); break; case '2': $ads.children('tr').removeClass('hide'); } return false; }, _resetFilter: function() { $('#ads-stype').children('option:eq(0)').attr({ 'selected': 'selected' }); }, _auditAd: function(event) { var options = this.options, id = $(event.target).attr('data-id'); $.ajax({ url: options.audiaddo, crossDomain: true, dataType: 'jsonp', data: { id: id, tp: options.tp_audit } }).done(function(res) { if (!res.errno) { $(event.target).closest('tr').remove(); } else { notify({ tmpl: 'error', text: res.error }); } }); return false; } }); module.exports = $.mock.ads; });
_createItemElem: function(item) { return '<tr><td>' + item.id + '</td><td><div class="ad-img-preivew"><img src="' + item.img + '"></div></td><td class="wordbreakall">' + item.link + '</td><td>' + item.expire + '天</td><td>' + _util.dateFormat(item.stime * 1000, 'yyyy-MM-dd hh:mm') + '</td><td><div class="mock-btn mock-btn-red mock-btn-s data-audit" data-id="' + item.id + '">提交</div></td></tr>'; },
define(function(require, exports, module) { 'use strict'; var _view = require('mock.view'), notify = require('mock.plugin.notify'), _util = require('mock.util'), apihost = 'http://'+_util.getApiHost(); $.widget('mock.ad', _view, { options: { addaudiad: apihost+'/mock/addaudiad?ua=bd_720_1280_HTC-HTC+One+X-4-0-4_4-2-6-1_j2&cuid=80000000000000000000000000000000|0&fn=?', getmyadlist: apihost+'/mock/getmyadlist?&ua=bd_720_1280_HTC-HTC+One+X-4-0-4_4-2-6-1_j2&cuid=80000000000000000000000000000000|0&fn=?', audiaddo: apihost+'/mock/audiaddo?ua=bd_720_1280_HTC-HTC+One+X-4-0-4_4-2-6-1_j2&cuid=80000000000000000000000000000000|0&fn=?', type: 0, //saved ad list ps: 100, tp_audit: 3 }, render: function(opt) { var options = this.options; _.extend(options, opt); this._createWrapperElem(); }, renderTable: function() { var self = this, options = this.options; this._updateWrapperElemStatus(options.stype); $.ajax({ url: options.getmyadlist, crossDomain: true, dataType: 'jsonp', type: 'GET', data: { stype: options.stype, type: options.type, pn: options.pn, ps: options.ps } }).done(function(res) { if (!res.errno) { options.allcount = res.data.allcount; options.totalpage = Math.ceil(options.allcount / options.ps); self._updatePagingStatus(); $('#ad-table').addClass('hide').empty().append(self._createTableElem(res.data.list)).removeClass('hide'); } else { notify({ tmpl: 'error', text: res.error }) } }); }, reRender: function(opt) { var options = this.options; _.extend(options, opt); this.renderTable(); }, _createWrapperElem: function() { var h = []; h.push('<div class="mock-hd">广告位编辑</div>'); h.push('<div class="page-content">'); h.push('<ul class="tabs-nav">'); h.push('<li class="tab-nav-item" data-type="0"><a>个人主页</a></li>'); h.push('<li class="tab-nav-item" data-type="1"><a>详情页</a></li>'); h.push('</ul>'); h.push('<div class="tabs-content">'); h.push('<div class="mock-btn mock-btn-red mock-add" data-toggle="modal" id="btnAddNewAd" data-target="#ad-modal-new">+ 新增</div>'); h.push('<div class="modal fade" id="ad-modal-new" tabindex="-1" role="dialog" aria-hidden="true">'); h.push('<div class="modal-dialog">'); h.push('<div class="modal-content">'); h.push('<div class="modal-header">'); h.push('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>'); h.push('<h4 class="modal-title" id="myModalLabel">广告位</h4>'); h.push('</div>'); h.push('<div class="modal-body">'); h.push('<table class="table table-bordered mock-upload-table mock-aditem"><tbody>'); h.push('<tr><td>广告图*</td><td><div class="bg-warning">广告图片尺寸要求:宽720px,高140px。</div><div class="upload-img-box"><div class="upload-img">'); h.push('<span class="errorinfo" for="ad-img" style="display:none;"></span><div class="mock-btn mock-btn-red upload-img-btn">上传广告图</div><input placeholder="广告图片链接" class="form-control upload-img-tx inlineb bgwhite" id="ad-img" readonly="readonly"/><input type="file" accept="image/gif, image/jpeg, image/png" class="hide"></div>'); h.push('<div class="upload-img-preivew mt10 ml0 hide"></div></div></td></tr>'); h.push('<tr><td>广告跳转链接*</td><td><span class="errorinfo" for="ad-link"></span><input class="form-control upload-desc" cols="3" maxlength="100" id="ad-link"/></td></tr>'); h.push('<tr><td>有效期(天)*</td><td><span class="errorinfo" for="ad-expire"></span><div id="ad-expire"></div></td></tr>'); h.push('</tbody></table>'); h.push('</div>'); h.push('<div class="modal-footer">'); h.push('<button type="button" class="btn btn-default data-cancel" data-dismiss="modal">取消</button>'); h.push('<button type="button" class="btn btn-primary data-save">保存</button>'); h.push('</div>'); h.push('</div>'); h.push('</div>'); h.push('</div>'); h.push('<table class="table table-bordered table-hover">'); h.push('<thead><tr><th>id</th><th>广告图片</th><th>广告链接</th><th>有效期</th><th>操作时间</th><th>操作</th></tr></thead><tbody id="ad-table">'); h.push('</tbody></table>'); h.push('<div class="paging hide">'); h.push('<div class="mock-btn mock-btn-white page_pre hide"><</div>'); h.push('<div class="page_num"><span class="page_current"></span><span class="num_gap">/</span><span class="page_total"></span></div>'); h.push('<div class="mock-btn mock-btn-white page_next hide">></div>'); h.push('<input type="text" class="form-control goto_page">'); h.push('<div class="mock-btn mock-btn-white page-go">跳转</div>'); h.push('</div>'); h.push('</div>'); h.push('</div>'); this.element.append(h.join('')); this.renderTable(); $('#ad-expire').append( _util.createSelectElem({ selectClass: 'mock-add-expire', data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] })); }, _createTableElem: function(data) { var self = this, h = []; if (!_.isEmpty(data)) { _.each(data, function(item, index) { h.push(self._createItemElem(item)); }); } else { h.push('<tr><td colspan="7">没有更多数据</td></tr>'); } return h.join(''); }, _createItemElem: function(item) { return '<tr><td>' + item.id + '</td><td><div class="ad-img-preivew"><img src="' + item.img + '"></div></td><td class="wordbreakall">' + item.link + '</td><td>' + item.expire + '天</td><td>' + _util.dateFormat(item.stime * 1000, 'yyyy-MM-dd hh:mm') + '</td><td><div class="mock-btn mock-btn-red mock-btn-s data-audit" data-id="' + item.id + '">提交</div></td></tr>'; }, _bindEvents: function() { this._on(this.element, { 'click li.tab-nav-item': this._goPage, 'click div.upload-img-btn': this._triggerUploadImg, 'change input[type=file]': this._uploadImg, 'change input.upload-img-tx': this._previewImg, 'click button.data-save': this._saveAd, 'click div.data-audit': this._auditAd, 'click div.page_pre': this._preGoSiblingPage, 'click div.page_next': this._preGoSiblingPage, 'click div.page_go': this._preGoSiblingPage, 'click #btnAddNewAd': this._clickNewAd, }); }, _clickNewAd: function() { var dialog = this.element.find('#ad-modal-new') dialog.find('#ad-img').val(''); dialog.find('span[for=ad-img]').empty().hide(); dialog.find('#ad-link').val(''); dialog.find('#ad-expire .mock-add-expire')[0].selectedIndex = 1; dialog.find('.upload-img-preivew').empty().addClass('hide'); dialog.find('.upload-img-preivew').parent().find('input[type=file]').val(''); }, _goSiblingPage: function(pn) { var router = new Backbone.Router; router.navigate('ad/' + this.options.type + '/' + pn, { trigger: true }); return false; }, _goPage: function(event) { var stype = $(event.target).closest('li.tab-nav-item').attr('data-type'); var router = new Backbone.Router; router.navigate('ad/' + stype, { trigger: true }); return false; }, _checkImgSize: function($tx, w, h) { var spanerror = $tx.parent().find('span[for=' + $tx[0].id + ']'); if ($tx.hasClass('upload-img-tx') && ((w != 720) || (h != 140))) { spanerror.show().html('广告图片尺寸要求:宽720px,高140px。').show(); $tx.val(''); return false; } else { spanerror.empty().hide(); } }, _previewImg: function(event) { var $tx = $(event.target), $imgbox = $tx.closest('div.upload-img-box'), imgsrc = $tx.val().trim(), $preview = $imgbox.children('div.upload-img-preivew'), $spanerror = $imgbox.children('span[for=ad-img]'); if (!!imgsrc) { if (imgsrc.match(/\.(jpeg|jpg|gif|png)$/)) { if ($spanerror.html() == '') { $spanerror.empty().hide(); } $preview.removeClass("hide"); $preview.empty().append('<img src="' + imgsrc + '"/>'); } else { $spanerror.show().html('请检查图片格式,只能上传png, jpeg, gif格式的图片。'); } } }, _saveAd: function(event) { var self = this, options = this.options, img = $('#ad-img').val().trim(), $dialog = $('#ad-modal-new'), $errorAdImg = $('span[for=ad-img]'), $errorAdLink = $('span[for=ad-link]'), $errorExpire = $('span[for=ad-expire]'), isValidate = true; if (!img.length) { $errorAdImg.show().html('请上传广告图片。'); isValidate = false; } else { if ($errorAdImg.html() == '请上传广告图片。') { $errorAdImg.empty().hide(); } if ($errorAdImg.html() != '') { isValidate = false; } } var link = $('#ad-link').val().trim(); if (!link.length) { $errorAdLink.show().html('请输入广告链接。'); isValidate = false; } else { $errorAdLink.hide().empty(); } var expire = $('#ad-expire').children('select').val(); if (!expire) { $errorExpire.show().html('请选择有效期。'); isValidate = false; } else { $errorExpire.empty().hide(); } if (isValidate) { $.ajax({ url: options.addaudiad, crossDomain: true, dataType: 'jsonp', data: { img: img, link: link, expire: expire, stype: options.stype, stime: Date.now() } }).done(function(res) { if (!res.errno) { var id = res.data.id; $('#ad-table').prepend(self._createItemElem({ id: id, img: img, link: link, expire: expire, stime: parseInt(new Date().getTime()/1000) })); self.element.find('button.data-cancel').trigger('click'); } else { notify({ tmpl: 'error', text: res.error }); } }); } }, _auditAd: function(event) { var options = this.options, id = $(event.target).attr('data-id'); $.ajax({ url: options.audiaddo, crossDomain: true, dataType: 'jsonp', data: { id: id, tp: options.tp_audit } }).done(function(res) { if (!res.errno) { $(event.target).closest('tr').remove(); } else { notify({ tmpl: 'error', text: res.error }); } }); return false; } }); module.exports = $.mock.ad; });
_.each(data, function(item, index) { var fan = $.parseJSON(item.content); h.push('<tr><td><div class="hp-avatar"><img src="' + fan.uc + '"></div></td><td>' + fan.username + '</td><td>' + _util.dateFormat(item.timestamp * 1000, 'yyyy-MM-dd hh:mm') + '</td></tr>'); });
define(function(require, exports, module) { 'use strict'; var _view = require('mock.view'), notify = require('mock.plugin.notify'), _util = require('mock.util'), apihost = 'http://'+_util.getApiHost(); $.widget('mock.fans', _view, { options: { message: apihost+'/message/pullmsg?&fn=?', type: 1, ps: 100, loadmore: true }, _create: function() { this.render(); this._bindEvents(); this._bindWindowEvent(); this.element.data('widgetCreated', true); }, render: function(opt) { var options = this.options; _.extend(options, opt); this._createWrapperElem(); }, reRender: function(opt) { var options = this.options, $nomore = $('#msgs-nomore'); _.extend(options, opt); options.loadmore = true; if (!$nomore.hasClass('hide')) { $nomore.addClass('hide'); } this.renderTable(); }, renderTable: function() { var self = this, options = this.options; this._updateWrapperElemStatus(options.status); $.ajax({ url: options.message, crossDomain: true, dataType: 'jsonp', data: { status: options.status, type: options.type, ps: options.ps } }).done(function(res) { if (!res.errno) { $('#fans-table').addClass('hide').empty().append(self._createTableElem(res.data.list)).removeClass('hide'); } else { notify({ tmpl: 'error', text: res.error }) } }); }, _loadMore: function() { var self = this, options = this.options; if (!options.loadmore) { return false; } $.ajax({ url: options.message, crossDomain: true, dataType: 'jsonp', data: { status: options.status, type: options.type, ps: options.ps, startid: options.startid } }).done(function(res) { if (!res.errno) { $('#fans-table').append(self._createTableElem(res.data.list)); } else { notify({ tmpl: 'error', text: res.error }); } }); }, _createWrapperElem: function() { var h = []; h.push('<div class="mock-hd">粉丝管理</div>'); h.push('<div class="page-content">'); h.push('<ul class="tabs-nav">'); h.push('<li class="tab-nav-item" data-type="1"><a>最新粉丝消息</a></li>'); h.push('<li class="tab-nav-item" data-type="0"><a>全部粉丝消息</a></li>'); h.push('</ul>'); h.push('<div class="tabs-content">'); h.push('<table class="table table-bordered table-hover">'); h.push('<thead><tr><th>粉丝头像</th><th>粉丝昵称</th><th>关注时间</th></tr></thead><tbody id="fans-table">'); h.push('</tbody></table>'); h.push('<div id="msgs-nomore" class="mock-nomore hide">没有更多数据</div>'); h.push('</div>'); this.element.append(h.join('')); this.renderTable(); }, _createTableElem: function(data) { var options = this.options, h = [], $nomore = $('#msgs-nomore'); if (!_.isEmpty(data)) { _.each(data, function(item, index) { var fan = $.parseJSON(item.content); h.push('<tr><td><div class="hp-avatar"><img src="' + fan.uc + '"></div></td><td>' + fan.username + '</td><td>' + _util.dateFormat(item.timestamp * 1000, 'yyyy-MM-dd hh:mm') + '</td></tr>'); }); if (data.length < options.ps) { options.loadmore = false; if ($nomore.hasClass('hide')) { $nomore.removeClass('hide'); } } options.startid = _.last(data).id; } else { if ($nomore.hasClass('hide')) { $nomore.removeClass('hide'); } } return h.join(''); }, _bindEvents: function() { this._on(this.element, { 'click li.tab-nav-item': this._goPage }); }, _bindWindowEvent: function() { var self = this; $(window).on('scroll', function() { if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) { self._loadMore(); } }); }, _goPage: function(event) { var type = $(event.target).closest('li.tab-nav-item').attr('data-type'); var router = new Backbone.Router; router.navigate('fans/' + type, { trigger: true }); return false; } }); module.exports = $.mock.fans; });