Commit c923ec98 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Merge branch 'comments'

parents 58063b47 2647f358
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ class JsDuckRunner
    @out_dir = OUT_DIR
    @ext_dir = EXT_DIR
    @animator_dir = ANIMATOR_DIR
    @base_url = "http://projects.sencha.com/auth"
  end

  def add_options(options)
@@ -158,7 +159,8 @@ class JsDuckRunner

    head_html = <<-EOHTML
      <link rel="canonical" href="http://docs.sencha.com/ext-js/4-0/" />
      <meta name="description" content="Ext JS 4.0 API Documentation from Sencha. Class documentation, Guides and Videos on how to create Javascript applications with Ext JS 4">
      <meta name="description" content="Ext JS 4.0 API Documentation from Sencha. Class documentation, Guides and Videos on how to create Javascript applications with Ext JS 4" />
      <script type="text/javascript">Docs.enableComments = true; Docs.baseUrl = "#{@base_url}"; Docs.commentsDb = 'comments-ext-js-4';</script>
    EOHTML

    if mode == 'export'
@@ -206,6 +208,11 @@ class JsDuckRunner
  end

  def add_ext3
    head_html = <<-EOHTML
      <link rel="canonical" href="http://docs.sencha.com/ext-js/3-4/" />
      <meta name="description" content="Ext JS 3.4 API Documentation from Sencha. Class documentation, Guides and Videos on how to create Javascript applications with Ext JS 3.4" />
    EOHTML

    @options += [
      "--title", "Sencha Docs - Ext JS 3.4",
      "--footer", "Ext JS 3.4 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
@@ -240,7 +247,7 @@ class JsDuckRunner
  def add_touch
    head_html = <<-EOHTML
      <link rel="canonical" href="http://docs.sencha.com/touch/1-1/" />
      <meta name="description" content="Sencha Touch 1.1 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch">
      <meta name="description" content="Sencha Touch 1.1 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch" />
    EOHTML

    @options += [
@@ -262,7 +269,8 @@ class JsDuckRunner
  def add_touch2
    head_html = <<-EOHTML
      <link rel="canonical" href="http://docs.sencha.com/touch/2-0/" />
      <meta name="description" content="Sencha Touch 2.0 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch">
      <meta name="description" content="Sencha Touch 2.0 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch" />
      <script type="text/javascript">Docs.enableComments = true; Docs.baseUrl = "#{@base_url}"; Docs.commentsDb = 'comments-touch-2';</script>
    EOHTML

    @options += [
@@ -341,7 +349,7 @@ class JsDuckRunner
  def add_touch_charts
    head_html = <<-EOHTML
      <link rel="canonical" href="http://docs.sencha.com/touch-charts/1-0/" />
      <meta name="description" content="Sencha Touch Charts 1.0 API Documentation. Documentation on how to create Charts with Sencha Touch">
      <meta name="description" content="Sencha Touch Charts 1.0 API Documentation. Documentation on how to create Charts with Sencha Touch" />
    EOHTML

    @options += [
@@ -381,7 +389,7 @@ class JsDuckRunner
  def add_animator
    head_html = <<-EOHTML
      <link rel="canonical" href="http://docs.sencha.com/animator/1-0/" />
      <meta name="description" content="Sencha Animator 1.0 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch">
      <meta name="description" content="Sencha Animator 1.0 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch" />
    EOHTML

    @options += [
+3 −1
Original line number Diff line number Diff line
@@ -19,8 +19,11 @@ Ext.define('Docs.Application', {
    ],

    controllers: [
        'Auth',
        'Welcome',
        'Classes',
        'Comments',
        'CommentsMeta',
        'Search',
        'InlineExamples',
        'Examples',
@@ -46,5 +49,4 @@ Ext.define('Docs.Application', {
        //     Ext.DomQuery.select('link')[4].href = "resources/css/viewport.css?" + Math.ceil(Math.random() * 100000000)
        // }, 1000);
    }

});
+4 −1
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ Ext.define("Docs.History", {
        else if (url.type === "example") {
            Docs.App.getController('Examples').loadExample(url.url, true);
        }
        else if (url.url === "#!/comment") {
            Docs.App.getController('Comments').loadIndex();
        }
        else {
            if (Docs.App.getController('Welcome').isActive()) {
                Docs.App.getController('Welcome').loadIndex(true);
@@ -77,7 +80,7 @@ Ext.define("Docs.History", {

    // Parses current browser location
    parseToken: function(token) {
        var matches = token && token.match(/!?(\/(api|guide|example|video)(\/(.*))?)/);
        var matches = token && token.match(/!?(\/(api|guide|example|video|comment)(\/(.*))?)/);
        return matches ? {type: matches[2], url: "#!"+matches[1]} : {};
    },

+201 −0
Original line number Diff line number Diff line
/**
 * Authentication controller.
 */
Ext.define('Docs.controller.Auth', {
    extend: 'Ext.app.Controller',

    requires: ['Ext.util.Cookies'],

    refs: [
        {
            ref: 'auth',
            selector: 'authentication'
        }
    ],

    init: function() {
        this.sid = Ext.util.Cookies.get('sid');

        this.addEvents(
            /**
             * @event loggedIn
             * Fired after user logs in
             */
            "loggedIn",

            /**
             * @event loggedOut
             * Fired after user logs out
             */
            "loggedOut",

            /**
             * @event available
             * Fired if the authorisation is available
             */
            "available"
        );

        if (Ext.isIE) {
            Docs.enableComments = Ext.ieVersion >= 8;
        }

        this.control({
            'authentication': {
                afterrender: function(cmp) {
                    cmp.el.addListener('click', function(e, el) {
                        cmp.showLogin();
                    }, this, {
                        preventDefault: true,
                        delegate: '.login'
                    });

                    cmp.el.addListener('click', function(e, el) {
                        this.logout();
                    }, this, {
                        preventDefault: true,
                        delegate: '.logout'
                    });

                    this.getSession();
                }
            }
        });
    },

    /**
     * Checks if a user is logged in server side and sets up a local session if they are.
     */
    getSession: function() {
        if (!Docs.enableComments) {
            return;
        }

        Ext.Ajax.request({
            url: Docs.baseUrl + '/session',
            params: { sid: this.sid },
            method: 'GET',
            cors: true,
            callback: function(options, success, response) {
                if (response && response.responseText) {
                    this.currentUser = JSON.parse(response.responseText);
                    this.fireEvent('available');
                    if (this.currentUser) {
                        this.loggedIn();
                    } else {
                        this.loggedOut();
                    }
                }
            },
            scope: this
        });
    },

    /**
     * Authenticates a user
     * @param {String} username
     * @param {String} password
     * @param {Boolean} remember
     * @param {Ext.Element} submitEl
     */
    login: function(username, password, remember, submitEl) {
        Ext.Ajax.request({
            url: Docs.baseUrl + '/login',
            method: 'POST',
            cors: true,
            params: {
                username: username,
                password: password
            },
            callback: function(options, success, response) {
                var data = JSON.parse(response.responseText);
                if (data.success) {
                    this.currentUser = data;
                    this.setSid(data.sessionID, { remember: remember });
                    this.loggedIn();
                } else {
                    if (this.errorTip) {
                        this.errorTip.update(data.reason);
                        this.errorTip.setTarget(submitEl);
                        this.errorTip.show();
                    } else {
                        this.errorTip = Ext.create('Ext.tip.ToolTip', {
                            anchor: 'bottom',
                            target: submitEl,
                            html: data.reason
                        });
                        this.errorTip.show();
                    }
                }
            },
            scope: this
        });
    },

    /**
     * Logs out a user
     */
    logout: function() {
        Ext.Ajax.request({
            url: Docs.baseUrl + '/logout?sid=' + this.sid,
            method: 'POST',
            cors: true,
            callback: function(){
                this.loggedOut();
            },
            scope: this
        });
    },

    /**
     * Marks the user as logged in.
     */
    loggedIn: function() {
        if (this.currentUser) {
            this.getAuth().showLoggedIn(this.currentUser.userName);
            this.fireEvent('loggedIn');
        }
    },

    /**
     * Marks a user as logged out.
     */
    loggedOut: function(user) {
        this.currentUser = {};
        this.setSid(null);
        this.getAuth().showLoggedOut();
        this.fireEvent('loggedOut');
    },

    /**
     * Checks if a user is logged in.
     * @return {Boolean} true if the user is logged in
     */
    isLoggedIn: function() {
        return Boolean(this.sid);
    },

    setSid: function(sid, opts) {
        this.sid = sid;
        if (sid && opts && opts.remember) {
            Ext.util.Cookies.set('sid', sid);
        } else {
            Ext.util.Cookies.clear('sid');
        }
    },

    submitLogin: function(el) {
        var form = Ext.get(el),
            username = form.down('input[name=username]').getValue(),
            password = form.down('input[name=password]').getValue(),
            rememberEl = form.down('input[name=remember]'),
            submitEl = form.down('input[type=submit]');

        var remember = rememberEl ? Boolean(rememberEl.getAttribute('checked')) : false;

        this.login(username, password, remember, submitEl);

        return false;
    }

});
+14 −0
Original line number Diff line number Diff line
/**
 * A mixin for Comments controller to help with authentication.
 */
Ext.define('Docs.controller.AuthHelpers', {

    addSid: function(url) {
        var sid = this.getController('Auth').sid;
        return url + (url.match(/\?/) ? '&' : '?') + 'sid=' + sid;
    },

    loggedIn: function() {
        return this.getController('Auth').isLoggedIn();
    }
});
Loading