Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化 table 功能,提取基础 table #8

Closed
x03570227 opened this issue Nov 26, 2014 · 0 comments
Closed

优化 table 功能,提取基础 table #8

x03570227 opened this issue Nov 26, 2014 · 0 comments
Assignees
Milestone

Comments

@x03570227
Copy link
Owner

/**

  • Product 模块相关的操作

  • */
    define( ["jquery","template","utils/table/pager"],
    function( jQuery, template, pg){

    var table={};
    
    table["init"] = function(config){
        config = config||{};
        this.config=config;
        if(this.config.pager==null){
            this.config.pager={};
        }
    };
    
    table["search"] = function(searchCond){
    
        searchCond=searchCond||{};
    
        this.searchCond=searchCond;
    
        jQuery.post(this.config.url, this.buildSubmit(searchCond), this.buildHtml, "json");
    
    };
    
    table["buildSubmit"]=function(searchCond){
        var pager = this.config.pager;
        if(typeof searchCond == "string"){
            jQuery.each(pager,function(k, v){
                searchCond = searchCond+"&"+k+"="+encodeURIComponent(v);
            });
            return searchCond;
        }
    
        jQuery.each(pager,function(k, v){
            searchCond[k]=encodeURIComponent(v);
        });
    
        return searchCond;
    };
    
    table["buildHtml"]=function(p){
    
        p = table.preBuildTable(p);
    

    // p= table.preBuildTable(p);

        var tableHtml = template(table.config.tpl.table, p);
        var pagerBar = pg.pageBar(p);
    
        jQuery("#"+table.config.renderTo).empty();
    
        jQuery("#"+table.config.renderTo).html(tableHtml);
        jQuery("#"+table.config.renderTo).append(pagerBar);
    
        //绑定分页导航事件
        pg.doPage(table.config.renderTo, function(item){
            var start = item.attr("page-start");
            start = start||0;
            table.setStart(start);
            table.search(table.searchCond);
        });
    
        table.afterBuildTable();
    };
    
    //需要按照实情情况重新实现
    table["preBuildTable"] = function(p){
        // pre build html
        return p;
    };
    
    table["afterBuildTable"] = function(){
    

// jQuery("#"+table.config.renderTo+" .act-delete").click(function(){
// var pid= jQuery(this).attr("model-product-id");
//
// table.remove(pid, jQuery(this));
//
// });

    };

    table["setOrder"]=function(sort, desc){
        var pager = this.config.pager||{};
        pager["sort"]=sort;
        pager["desc"]=desc;
        this.config.pager = pager;
    };

    table["setStart"]=function(start){
        var pager = this.config.pager||{};
        pager["start"]=start;
        this.config.pager = pager;
    };

    table["setLimit"]=function(limit){
        var pager = this.config.pager||{};
        pager["limit"]=limit;
        this.config.pager = pager;
    };

    return table;
}

);

@x03570227 x03570227 added this to the v1.1.x milestone Nov 26, 2014
@x03570227 x03570227 self-assigned this Nov 26, 2014
@x03570227 x03570227 modified the milestones: v1.1.x, v1.2.x Dec 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant