ps.js 4.56 KB
/**
 * plus/star页控制器文件
 * @author: xuqi(qi.xu@yoho.cn)
 * @date: 2015/4/15
 */
var data = require('../../public/js/data'),
    ps = data('ps'),
    list = data('ps-list'),
    path = require('path'),
    fs = require('fs'),
    tabpage = require('../../public/js/data_tabpage')('temp'),
    original = require('../../public/js/data_tabpage')('original'),
    newtagpage = require('../../public/js/data_newtabpage')(),
    tplPath = path.normalize(path.join(__dirname, '../partials/ps/info-item.html'));

function clone(myObj) {
    if (typeof(myObj) != 'object') return myObj;
    if (myObj == null) return myObj;
    var myNewObj = new Object();
    for (var i in myObj)
        myNewObj[i] = clone(myObj[i]);
    return myNewObj;
}
exports.show = function(req, res) {
    res.render('pages/ps', {
        data: ps,
        layout: '../layouts/layout',
        isPs: true,
        isLogin: 'Y'
    });
};

exports.readTpl = function(req, res) {
    fs.readFile(tplPath, 'utf8', function(err, data) {
        if (err) {
            res.send({
                success: false
            });
        }

        fs.readFile(
            path.normalize(path.join(__dirname, '../partials/common/time-view-like-share.html')),
            'utf8',
            function(err, subData) {
                if (err) {
                    res.send({
                        success: false
                    });
                }
                data = data.replace('{{> common/time_view_like_share}}', subData); //Note: 后端需将partials目录替换为内容
                res.send(data);
            });
    });
};
exports.tabPageNew = function(req, res) {
        var obj = {};
        obj.global_fetchdataurl = 'getBrand';
        obj.global_brandcat = '1';
        obj.global_showpannel = 'showpannel1';
        obj.global_totalcount = 20;
        res.render('pages/ps-newtabpage', {
            data: newtagpage,
            globalConfig: obj,
            layout: '../layouts/layout',
            isNewTabPage: true
        });
    }
/**
 * 首次跳转
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.tabPage = function(req, res) {
        var obj = {};
        obj.global_fetchdataurl = 'getBrand';
        obj.global_brandcat = '1';
        obj.global_showpannel = 'showpannel1';
        var data = tabpage[2].starinner;
        var renddata = data[0].brandList;
        obj.global_totalcount = original[2].starinner[0].brandList.length;
        var responsedata = renddata.slice(0, 10);
        tabpage[2].starinner[0].brandList = responsedata;
        tabpage[2].starinner[1].brandList = [];
        res.render('pages/ps-tabpage', {
            data: tabpage,
            globalConfig: obj,
            layout: '../layouts/layout',
            isTabPage: true
        });
    }
    /**
     * 异步获取数据
     * @param  {[type]} req [description]
     * @param  {[type]} res [description]
     * @return {[type]}     [description]
     */
exports.getBrand = function(req, res) {
        var obj = {};
        var data = original[2].starinner;
        var start = parseInt(req.body.start);
        var count = parseInt(req.body.count);
        var catid = parseInt(req.body.brandcat);
        var renddata = data[catid - 1].brandList;
        var totalcount = data[catid - 1].brandList.length;
        var end = start + count;
        if (end > totalcount) {
            end = totalcount;
        }
        var responsedata = renddata.slice(start, end);
        obj.code = 200,
            obj.message = 'ok',
            obj.data = {
                brandList: responsedata,
                total: totalcount
            };
        res.send(obj);
    }
    /**
     * 渲染模板
     * @param  {[type]} req [description]
     * @param  {[type]} res [description]
     * @return {[type]}     [description]
     */
exports.psTmplage = function(req, res) {
    var temp = '{{#brandList}}' +
        '<div class="swiper-container swiper-container{{subId}}" id="{{subId}}">' +
        '<div class="swiper-wrapper">' +
        '{{# imgList}}' +
        '<div class="swiper-slide branddetail">' +
        '<a href="{{url}}">' +
        '<img  data-src="{{src}}" class="img" src="{{src}}"/>' +
        '</a>' +
        '</div>' +
        '{{/imgList}}' +
        '</div>' +
        '<div class="swiper-pagination swiper-pagination{{subId}}"></div>' +
        '</div>' +
        '{{/brandList}}';
    res.send(temp);
}
exports.list = function(req, res) {
    res.render('pages/ps-list', {
        data: list,
        layout: '../layouts/layout',
        isPsList: true
    });
};