﻿//<using>
//  nui/nui.js
//  nui/prototype.js
//  nui/lang.js
//  nui/util.js
//  nui/widget.js
//  nui/quill/entity/*
//  nui/quill/render/render.js
//</using>

/**
 * The render class of a survey
 * @param vSurvey {object}. The entity of the survey
 */
NUI.Quill.Render.Survey = (function() {
    var g_lang = NUI.Lang,
        g_dom = NUI.Util.DomService,
        g_sb = NUI.Util.StringService.StringBuilder,
        g_widget = NUI.Widget;
        
    return function(vSurvey) {
        if(vSurvey == null) {
            return null;
        }
        var survey = vSurvey,
            m_secret = {},
            that = g_widget.Base(m_secret),
            m_id = m_secret.id;
        
        var m_node = (function() {
                var retval = g_dom.createNode("div");
                var sb = new g_sb();
                sb.append(
                    "<div id=\"" + m_id + "\" class=\"survey\">",
                    "<div class=\"header\"><span id=\"" + m_id + "_header\">" + survey.header + "</span></div>",
                    "<div class=\"caption\"><h1 id=\"" + m_id + "_cap\">" + survey.caption + "</h1>",
                    "<h2 id=\"" + m_id + "_subcap\" ",
                    ">" + survey.subcaption + "</h2></div>",
                    "<div id=\"" + m_id + "_desc\" class=\"desc\">" + survey.description + "</div>",
                    "<div id=\"" + m_id + "_content\" class=\"content\"></div>",
                    "<div class=\"footer\"><span id=\"" + m_id + "_footer\">" + survey.footer + "</span></div>",
                    "</div>"
                );
                g_dom.setInnerHTML(retval, sb.toString());
                return retval;
            })();
            
        NUI.Util.ObjectService.annex(that, { 
            nodeEntity : m_node,
            
            getCaption : function() {
                return m_secret.getChild(m_id + "_cap");
            },
            
            getSubCaption : function() {
                return m_secret.getChild(m_id + "_subcap");
            },
            
            getDesc : function() {
                return m_secret.getChild(m_id + "_desc");
            },
            
            getContent : function() {
                return m_secret.getChild(m_id + "_content");
            },
            
            getHeader : function() {
                return m_secret.getChild(m_id + "_header");
            },
            
            getFooter : function() {
                return m_secret.getChild(m_id + "_footer");
            }
        });
        return that;
    };
})();
