﻿//<using>
//  nui/nui.js
//  nui/prototype.js
//  nui/lang.js
//  nui/quill/entity/entity.js
//</using>

/**
 * The namespace of question entity used in netranking.cn 
 * @namespace NUI.Quill.Entity.Question
 */
NUI.Quill.Entity.Question = {
    Base : function() {},
    Choice : function() {},
    Matrix : function() {},
    Input : function() {},
    Rank : function() {},
    Sort : function() {},
    ConstSum : function() {},
    Location : function() {},
    MatrixInput : function() {}
};

/**
 * The base class of all kinds of questions.
 * @class NUI.Quill.Entity.Question.Base
 */
NUI.Quill.Entity.Question.Base = function(vSecret) {
    var m_lang = NUI.Lang,
        m_secret = vSecret || {};
    if(!m_lang.isNumber(m_secret.id)) {
        m_secret.id = -1;
    }
    if(!m_lang.isNumber(m_secret.type)) {
        m_secret.type = -1;
    }
    if(!m_lang.isString(m_secret.caption)) {
        m_secret.caption = "标题";
    }
    
    return {
        /**
         * @variable id {int} The id of the question.
         */
        id : m_secret.id,
        /**
         * @variable modified {boolean}
         */
        modified : true,
        /**
         * @variable type {NUI.Quill.Enum.QuestionType.*.id}
         */
        type : m_secret.type,
        /**
         * @variable caption {string} The question's caption 
         */
        caption : m_secret.caption
    };
};

/**
 * The Choice Question entity
 * @class NUI.Quill.Entity.Question.Choice
 */
NUI.Quill.Entity.Question.Choice = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.CHOICE.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            /**
             * The html strings of the choice question's options
             */
            optSet : {
                options : ["选项1", "选项2", "选项3"],
                hasOtherOption : false,
                constrain : {
                    min : 1,
                    max : 1
                }
            },
            style : {
                column : 1,
                isRandom : false
            }
        });
        return that;
    };
})();

/**
 * The Matrix Question entity
 * @class NUI.Quill.Entity.Question.Matrix
 */
NUI.Quill.Entity.Question.Matrix = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.MATRIX.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            rows : {
                options : ["行1", "行2", "行3"],   // html string
                hasOtherOption : false,
                constrain : {
                    min : 1,
                    max : 1
                }
            },
            cols : {
                options : ["列1", "列2", "列3"],   // html string
                hasOtherOption : false,
                constrain : {
                    min : 1,
                    max : 1
                }
            }
        });
        return that;
    };
})();

/**
 * The Input Question entity
 * @class NUI.Quill.Entity.Question.Input
 */
NUI.Quill.Entity.Question.Input = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.INPUT.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            /**
             * String
             */
            texts : ["文本"],
            /**
             * Input : {
             *      type : {int} NUI.Widget.Input.TextInputType.*.id,
             *      min : 0,
             *      max : 10
             * }
             */
            inputs : [{
                type : NUI.Widget.Input.TextInputType.STRING.id,
                min : 0,
                max : 50
            }],
            /**
             * optTypeMask.length = (texts.length + inputs.length)
             * optTypeMask [NUI.Quill.Enum.InputOptionType.*,...]. Indicate the type of the option
             */
            optTypeMask : [NUI.Quill.Enum.InputOptionType.TEXT, NUI.Quill.Enum.InputOptionType.INPUT]
        });
        return that;
    };
})();

/**
 * The Rank Question entity
 * @class NUI.Quill.Entity.Question.Rank
 */
NUI.Quill.Entity.Question.Rank = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.RANK.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            type : g_enum.QuestionType.RANK.id,
            /**
             *  Option : {
             *      value : {string}
             *      type : {NUI.Widget.Input.RankBarType.*}
             *      count : {int}
             *  }
             */
            options : [{
                value : "选项1",
                type : NUI.Widget.Input.RankBarType.apple3,
                count : 10
            },{
                value : "选项2",
                type : NUI.Widget.Input.RankBarType.star1,
                count : 10
            },{
                value : "选项3",
                type : NUI.Widget.Input.RankBarType.moon0,
                count : 10
            }]
        });
        return that;
    };
})();

/**
 * The Sort Question entity
 * @class NUI.Quill.Entity.Question.Sort
 */
NUI.Quill.Entity.Question.Sort = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.SORT.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            type : g_enum.QuestionType.SORT.id,
            /**
             * The html strings of the choice question's options
             */
            options : ["选项1", "选项2", "选项3"],
            style : {
                column : 1
            }
        });
        return that;
    };
})();

/**
 * The ConstSum Question entity
 * @class NUI.Quill.Entity.Question.ConstSum
 */
NUI.Quill.Entity.Question.ConstSum = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.CONSTSUM.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            /**
             * The html strings of the choice question's options
             */
            options : ["选项1", "选项2", "选项3"],
            color : NUI.Widget.Input.ConstBarType.blue,         //{NUI.Widget.Input.ConstBarType.*}
            arrange : NUI.Widget.Input.ArrangeType.horizontal     //{NUI.Widget.Input.ArrangeType.*}
        });
        return that;
    };
})();

/**
 * The Location Question entity
 * @class NUI.Quill.Entity.Question.Location
 */
NUI.Quill.Entity.Question.Location = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.LOCATION.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            constrain : {
                min : 1,
                max : 1
            }
        });
        return that;
    };
})();

/**
 * The MatrixInput Question entity
 * @class NUI.Quill.Entity.Question.MatrixInput
 */
NUI.Quill.Entity.Question.MatrixInput = (function() {
    var g_ns = NUI.Quill.Entity.Question,
        g_enum = NUI.Quill.Enum;
        
    return function(vId) {
        if(!NUI.Lang.isNumber(vId)) {
            return null;
        }
        var m_secret = {
                id : vId,
                type : g_enum.QuestionType.MATRIXINPUT.id
            },
            that = new g_ns.Base(m_secret);
        NUI.Util.ObjectService.annex(that, {
            rows : {
                options : ["行1", "行2", "行3"],   // html string
                hasOtherOption : false
            },
            cols : {
                options : ["列1", "列2", "列3"],   // html string
                hasOtherOption : false
            }
        });
        return that;
    };
})();

