专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > JavaScript

js轨范

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
js规范


(function(e) {
    function questions_list() {
        this.addId = "";    //添加页页签id
    };
    questions_list.prototype = {
        inital : function inital() {

        },

        /**
         * 添加
         */
        create : function create(type) {
            this.addId = questionsList.randomNum(1,100000);
            openPage(this.addId,ctx+"/system/examstack/question/questions/formPage.chtml?type="+type+"&tabId="+this.addId,"添加" + (type == 'naire'?'问题':'试题'));
        },

        /**
         * 修改
         */
        edit : function edit(id) {
            dialogShow("修改分类",900,600,ctx+"/system/examstack/question/questions/update/"+id+".chtml");

        },

        /**
         * 预览
         */
        preview : function preview(id) {
            dialogShowNoButton("试题预览",900,600,ctx+"/system/examstack/question/questions/preview/"+id+".chtml");
        },

        /**
         * 打开新窗口预览
         * @param id
         */
        previewBlank : function previewBlank(id) {
            window.open(ctx+"/system/examstack/question/questions/preview/"+id+".chtml");
        },

        /**
         * 导出
         * @constructor
         */
        BTNexport : function BTNexport(type) {
            dialogShow("导出数据",350,350,ctx+"/system/examstack/question/questions/formExport.chtml?type=" + type);
        },

        composeEntity : function composeEntity() {

            var data = new Object();

            var question_entity = new Object();

            var pointList = new Array();

            var pointOpts = $("#point-to-select option");

            for (var i = 0; i < pointOpts.length; i++) {
                pointList.push($(pointOpts[i]).attr("value"));
            }

            question_entity.pointList = pointList;
            question_entity.id = $("#add-update-questionid").val();
            question_entity.analysis = $(".form-question-analysis textarea").val();
            question_entity.reference = $(".form-question-reference input").val();
            question_entity.examingPoint = $(".form-question-examingpoint input").val();
            question_entity.keyword = $(".form-question-keyword input").val();

            data.question = question_entity;
            return data;

        },

        /**
         * 绑定更新操作
         * @returns {boolean}
         */
        bindUpdate : function bindUpdate() {
            if ($("#kn-selected option").length == 0) {
                util.error("请选择知识类");
                return false;
            }
            parent.loading();
            var data = questionsList.composeEntity();
            $.ajax({
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                type : "POST",
                url : ctx + "/system/examstack/question/questions/update.chtml",
                data : JSON.stringify(data),
                success : function(message, tst, jqXHR) {
                    if(message.errorCode == "0") {
                        //
                        setTimeout("parent.location.href = ctx + '/system/examstack/question/questions.chtml?type=questions'", 1000);
                    }else {
                        failmsg(message.message);
                    }
                },
                error : function(jqXHR, textStatus) {
                    util.error("操作失败请稍后尝试");
                    $(".df-submit").removeAttr("disabled");
                }
            });
        },

        /**
         * 生成随机数
         */
        randomNum : function randomNum(Min, Max) {
            var Range = Max - Min;
            var Rand = Math.random();
            if(Math.round(Rand * Range)==0){
                return Min + 1;
            }else if(Math.round(Rand * Max)==Max)
            {
                index++;
                return Max - 1;
            }else{
                var num = Min + Math.round(Rand * Range) - 1;
                return num;
            }
        }
    };
    window.questionsList = new questions_list();
    questionsList.inital();
})(jQuery);

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: