Commit faaa35b8 authored by Nick Poulden's avatar Nick Poulden
Browse files

Commenting updates

parent 88489274
Loading
Loading
Loading
Loading
+8 −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)
@@ -157,7 +158,8 @@ class JsDuckRunner
  def add_sdk
    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

    @options += [
@@ -212,7 +214,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 += [
@@ -233,7 +235,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 += [
@@ -310,7 +313,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 += [
@@ -329,7 +332,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 += [
+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]} : {};
    },

+6 −24
Original line number Diff line number Diff line
@@ -3,8 +3,6 @@ Ext.define('Docs.controller.Auth', {

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

    authServer: 'http://projects.sencha.com/auth',

    refs: [
         {
            ref: 'auth',
@@ -12,8 +10,6 @@ Ext.define('Docs.controller.Auth', {
        }
    ],

    enabled: true,

    init: function() {

        this.sid = Ext.util.Cookies.get('sid');
@@ -33,7 +29,7 @@ Ext.define('Docs.controller.Auth', {
        );

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

        this.control({
@@ -64,27 +60,12 @@ Ext.define('Docs.controller.Auth', {
     */
    getSession: function() {

        if (!this.enabled) {
        if (!Docs.enableComments) {
            return;
        }

        // if (window.XDomainRequest) {
        //     xdr = new XDomainRequest();
        //     if (xdr) {
        //         xdr.onerror = function() { alert("XDR onerror"); };
        //         xdr.ontimeout =  function() { alert("XDR timeout"); };
        //         xdr.onload =  function() { alert("XDR load " + xdr.responseText); };
        //
        //         xdr.timeout = 2000;
        //         xdr.open('POST', 'http://projects.sencha.com/auth/login');
        //         xdr.send('username=user&password=pass');
        //     } else {
        //         alert('Failed to create');
        //     }
        // }

        Ext.Ajax.request({
            url: this.authServer + '/session',
            url: Docs.baseUrl + '/session',
            params: { sid: this.sid },
            method: 'GET',
            cors: true,
@@ -97,6 +78,7 @@ Ext.define('Docs.controller.Auth', {
                if (this.currentUser) {
                    this.loggedIn();
                } else {
                    this.setSid(null);
                    this.getAuth().showLoggedOut();
                }
            },
@@ -114,7 +96,7 @@ Ext.define('Docs.controller.Auth', {
    login: function(username, password, remember, submitEl) {

        Ext.Ajax.request({
            url: this.authServer + '/login',
            url: Docs.baseUrl + '/login',
            method: 'POST',
            cors: true,
            params: {
@@ -151,7 +133,7 @@ Ext.define('Docs.controller.Auth', {
     */
    logout: function() {
        Ext.Ajax.request({
            url: this.authServer + '/logout?sid=' + this.sid,
            url: Docs.baseUrl + '/logout?sid=' + this.sid,
            method: 'POST',
            cors: true,
            callback: function(){
+1 −6
Original line number Diff line number Diff line
@@ -6,11 +6,6 @@ Ext.define('Docs.controller.AuthHelpers', {
    },

    loggedIn: function() {
        if (!this.getController('Auth').isLoggedIn()) {
            return false;
        } else {
            return true;
        return this.getController('Auth').isLoggedIn();
    }
    }

});
 No newline at end of file
+64 −21
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@
 * Retrieving and posting Comments
 */
Ext.define('Docs.controller.Comments', {
    extend: 'Ext.app.Controller',

    baseUrl: 'http://projects.sencha.com/auth',
    extend: 'Docs.controller.Content',
    baseUrl: '#!/comments',
    title: 'Comments',

    mixins: {
        authMixin: 'Docs.controller.AuthHelpers'
@@ -12,16 +12,12 @@ Ext.define('Docs.controller.Comments', {

    refs: [
        {
            ref: 'toolbar',
            selector: 'classoverview toolbar'
        },
        {
            ref: 'authentication',
            selector: 'authentication'
            ref: 'viewport',
            selector: '#viewport'
        },
        {
            ref: 'overview',
            selector: 'classoverview'
            ref: 'index',
            selector: '#commentindex'
        }
    ],

@@ -94,14 +90,25 @@ Ext.define('Docs.controller.Comments', {
        });
    },

    fetchComments: function(id, callback) {
    loadIndex: function() {
        this.fireEvent('loadIndex');
        Ext.getCmp('treecontainer').hide();
        if (!this.recentComments) {
            this.fetchRecentComments('recentcomments');
            this.recentComments = true;
        }
        this.callParent([true]);
    },

    fetchComments: function(id, callback, opts) {

        var startkey = Ext.JSON.encode(this.commentId(id)),
            endkey = Ext.JSON.encode(this.commentId(id).concat([{}])),
            currentUser = this.getController('Auth').currentUser;
            currentUser = this.getController('Auth').currentUser,
            url = Docs.baseUrl + '/' + Docs.commentsDb + '/_design/Comments/_list/with_vote/by_target';

        Ext.data.JsonP.request({
            url: this.baseUrl + '/comments/_design/Comments/_list/with_vote/by_target',
            url: url,
            method: 'GET',
            params: {
                reduce: false,
@@ -128,7 +135,7 @@ Ext.define('Docs.controller.Comments', {
            target = Ext.JSON.encode(this.commentId(id));

        Ext.Ajax.request({
            url: this.addSid(this.baseUrl + '/comments'),
            url: this.addSid(Docs.baseUrl + '/' + Docs.commentsDb),
            method: 'POST',
            cors: true,
            params: {
@@ -147,6 +154,31 @@ Ext.define('Docs.controller.Comments', {
        });
    },

    /**
     * Fetches the most recent comments
     */
    fetchRecentComments: function(id) {

        var url = Docs.baseUrl + '/' + Docs.commentsDb + '/_design/Comments/_list/with_vote/by_date';

        Ext.data.JsonP.request({
            url: url,
            method: 'GET',
            params: {
                descending: true,
                limit: 10
            },
            success: function(response) {
                this.renderComments(response.rows, id, {showCls: true, hideCommentForm: true});
            },
            scope: this
        });
    },

    /**
     * Promts the user for confirmation of comment deletion. Deleted the comment
     * if the user confirms.
     */
    promptDeleteComment: function(cmp, el) {

        if (!this.loggedIn()) {
@@ -167,13 +199,16 @@ Ext.define('Docs.controller.Comments', {
        });
    },

    deleteComment: function(cmp, el) {
    /**
     * Sends a delete comment request to the server.
     */
    deleteComment: function(cmp, dom) {

        var id = Ext.get(el).up('.comment').getAttribute('id'),
            cls = Ext.get(el).up('.comments').getAttribute('id');

        Ext.Ajax.request({
            url: this.addSid(this.baseUrl + '/comments/' + id + '/delete'),
            url: this.addSid(Docs.baseUrl + '/' + Docs.commentsDb + '/' + id + '/delete'),
            cors: true,
            method: 'POST',
            callback: function(options, success, response) {
@@ -215,7 +250,7 @@ Ext.define('Docs.controller.Comments', {
            scoreEl = meta.down('.score');

        Ext.Ajax.request({
            url: this.addSid(this.baseUrl + '/comments/' + id),
            url: this.addSid(Docs.baseUrl + '/' + Docs.commentsDb + '/' + id),
            cors: true,
            method: 'POST',
            params: { vote: direction },
@@ -285,16 +320,24 @@ Ext.define('Docs.controller.Comments', {
        this.getOverview().scrollToEl(commentsDiv, -20);
    },

    renderComments: function(rows, id) {
    renderComments: function(rows, id, opts) {

        opts = opts || {};

        var comments = Ext.get(id);
        var data = Ext.Array.map(rows, function(r) {
            r.value.id = r.id;
            r.value = Ext.merge(r.value, opts);
            return r.value;
        });
        Docs.view.Comments.commentsTpl.append(comments, data);

        if (opts.hideCommentForm) {
            comments.addCls('hideCommentForm');
        } else if (!comments.hasCls('hideCommentForm')) {
            var commentTpl = (this.loggedIn() ? Docs.view.Comments.loggedInCommentTpl : Docs.view.Comments.loggedOutCommentTpl);
            commentTpl.overwrite(comments.down('.new-comment-wrap'), this.loggedIn() ? this.getController('Auth').currentUser : {});
        }
    },

    toggleNewComment: function(cmp, el) {
Loading