From 6975a53a22b6d956d1b9cda1b8f93a20625ea5dd Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 24 Oct 2011 17:53:38 +0300 Subject: [PATCH] Whitespace and comment fixes. - Add missing semicolons. - Add comments to classes without one. - Remove empty lines at the beginning of functions. - Remove one accidental global variable. --- template/app/controller/Auth.js | 12 ++++++------ template/app/controller/AuthHelpers.js | 5 ++++- template/app/controller/Comments.js | 25 ++++++------------------- template/app/controller/CommentsMeta.js | 16 +++++----------- template/app/view/Comments.js | 21 +++++++-------------- template/app/view/auth/Login.js | 3 +++ 6 files changed, 31 insertions(+), 51 deletions(-) diff --git a/template/app/controller/Auth.js b/template/app/controller/Auth.js index 4da45fe9..38f8365a 100644 --- a/template/app/controller/Auth.js +++ b/template/app/controller/Auth.js @@ -1,17 +1,19 @@ +/** + * 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( @@ -65,7 +67,6 @@ Ext.define('Docs.controller.Auth', { * Checks if a user is logged in server side and sets up a local session if they are. */ getSession: function() { - if (!Docs.enableComments) { return; } @@ -98,7 +99,6 @@ Ext.define('Docs.controller.Auth', { * @param {Ext.Element} submitEl */ login: function(username, password, remember, submitEl) { - Ext.Ajax.request({ url: Docs.baseUrl + '/login', method: 'POST', @@ -162,7 +162,7 @@ Ext.define('Docs.controller.Auth', { */ loggedOut: function(user) { this.currentUser = {}; - this.setSid(null) + this.setSid(null); this.getAuth().showLoggedOut(); this.fireEvent('loggedOut'); }, @@ -189,7 +189,7 @@ Ext.define('Docs.controller.Auth', { 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]') + submitEl = form.down('input[type=submit]'); var remember = rememberEl ? Boolean(rememberEl.getAttribute('checked')) : false; diff --git a/template/app/controller/AuthHelpers.js b/template/app/controller/AuthHelpers.js index 49256542..910dcdba 100644 --- a/template/app/controller/AuthHelpers.js +++ b/template/app/controller/AuthHelpers.js @@ -1,3 +1,6 @@ +/** + * A mixin for Comments controller to help with authentication. + */ Ext.define('Docs.controller.AuthHelpers', { addSid: function(url) { @@ -8,4 +11,4 @@ Ext.define('Docs.controller.AuthHelpers', { loggedIn: function() { return this.getController('Auth').isLoggedIn(); } -}); \ No newline at end of file +}); diff --git a/template/app/controller/Comments.js b/template/app/controller/Comments.js index 92daf557..e3550632 100644 --- a/template/app/controller/Comments.js +++ b/template/app/controller/Comments.js @@ -26,16 +26,17 @@ Ext.define('Docs.controller.Comments', { ], init: function() { - this.addEvents( /** - * @event add Fired after a comment is added + * @event add + * Fired after a comment is added * @param {String} key Key of the comment */ 'add', /** - * @event remove Fired after a comment is removed + * @event remove + * Fired after a comment is removed * @param {String} key Key of the comment */ 'remove' @@ -121,7 +122,6 @@ Ext.define('Docs.controller.Comments', { }, 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, @@ -144,7 +144,6 @@ Ext.define('Docs.controller.Comments', { }, postComment: function(cmp, el) { - if (!this.loggedIn()) { return false; } @@ -214,7 +213,6 @@ 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({ @@ -236,7 +234,6 @@ Ext.define('Docs.controller.Comments', { * if the user confirms. */ promptDeleteComment: function(cmp, el) { - if (!this.loggedIn()) { return false; } @@ -259,7 +256,6 @@ Ext.define('Docs.controller.Comments', { * Sends a delete comment request to the server. */ deleteComment: function(cmp, el) { - var id = Ext.get(el).up('.comment').getAttribute('id'), commentsEl = Ext.get(el).up('.comments'), cls = commentsEl && commentsEl.getAttribute('id'); @@ -295,7 +291,6 @@ Ext.define('Docs.controller.Comments', { callback: function(options, success, response) { var data = Ext.JSON.decode(response.responseText); if (data.success) { - contentEl.dom.origContent = contentEl.dom.innerHTML; var commentData = Ext.merge(Ext.clone(currentUser), { @@ -314,7 +309,6 @@ Ext.define('Docs.controller.Comments', { }, updateComment: function(cmp, el) { - if (!this.loggedIn()) { return false; } @@ -370,7 +364,6 @@ Ext.define('Docs.controller.Comments', { * @private */ vote: function(direction, el) { - if (!this.loggedIn()) { this.showError('Please login to vote on this comment', el); return false; @@ -410,7 +403,6 @@ Ext.define('Docs.controller.Comments', { }, toggleComments: function(cmp, el) { - var commentsDiv = Ext.get(el).up('.comments'); if (commentsDiv.hasCls('open')) { @@ -421,7 +413,6 @@ Ext.define('Docs.controller.Comments', { }, openComments: function(commentsDiv) { - if (commentsDiv.hasCls('open')) return; var commentNum = commentsDiv.down('.name'), @@ -439,7 +430,6 @@ Ext.define('Docs.controller.Comments', { }, closeComments: function(commentsDiv) { - if (!commentsDiv.hasCls('open')) return; var commentNum = commentsDiv.down('.name'), @@ -467,7 +457,6 @@ Ext.define('Docs.controller.Comments', { }, renderComments: function(rows, id, opts) { - opts = opts || {}; var comments = Ext.get(id), @@ -487,7 +476,6 @@ Ext.define('Docs.controller.Comments', { if (opts.hideCommentForm) { comments.addCls('hideCommentForm'); } else if (!comments.hasCls('hideCommentForm')) { - var commentWrap = comments.down('.new-comment-wrap'); if (this.loggedIn()) { var wrap = Docs.view.Comments.loggedInCommentTpl.overwrite(commentWrap, this.getController('Auth').currentUser, true); @@ -527,7 +515,7 @@ Ext.define('Docs.controller.Comments', { data = row.value; data.id = opts.id; } - }) + }); } else { data = rows[rows.length - 1].value; data.id = rows[rows.length - 1].id; @@ -556,7 +544,6 @@ Ext.define('Docs.controller.Comments', { }, showError: function(msg, el) { - if (this.errorTip) { this.errorTip.update(msg); this.errorTip.setTarget(el); @@ -570,4 +557,4 @@ Ext.define('Docs.controller.Comments', { this.errorTip.show(); } } -}); \ No newline at end of file +}); diff --git a/template/app/controller/CommentsMeta.js b/template/app/controller/CommentsMeta.js index 4770d2a3..08a2d118 100644 --- a/template/app/controller/CommentsMeta.js +++ b/template/app/controller/CommentsMeta.js @@ -21,7 +21,6 @@ Ext.define('Docs.controller.CommentsMeta', { ], init: function() { - Docs.commentMeta = { idMap: {}, 'class': {} @@ -83,7 +82,6 @@ Ext.define('Docs.controller.CommentsMeta', { group_level: 3 }, success: function(response) { - Ext.Array.each(response.rows, function(r) { this.updateMeta(r.key, r.value.num); }, this); @@ -97,7 +95,6 @@ Ext.define('Docs.controller.CommentsMeta', { }, // updateVoteMeta: function() { - // // var id = Docs.App.getController('Classes').currentCls.name, // startkey = Ext.JSON.encode(['class',id]), // endkey = Ext.JSON.encode(['class',id,{}]), @@ -123,7 +120,6 @@ Ext.define('Docs.controller.CommentsMeta', { // }, fetchCommentLeaders: function() { - Ext.data.JsonP.request({ url: Docs.baseUrl + '/' + Docs.commentsDb + '/_design/Comments/_view/by_author', method: 'GET', @@ -134,7 +130,6 @@ Ext.define('Docs.controller.CommentsMeta', { limit: 10 }, success: function(response) { - var tpl = Ext.create('Ext.XTemplate', '

Comment reputation

', '', @@ -177,15 +172,14 @@ Ext.define('Docs.controller.CommentsMeta', { * Creates a mapping between comment element IDs and DB view keys. */ createCommentIdMap: function(cls) { - var key, commentId, member Docs.commentMeta.idMap[('comments-class-' + cls.name).replace(/\./g, '-')] = ['class', cls.name, '']; if (cls.members) { - for(member in cls.members) { + for (var member in cls.members) { Ext.Array.each(cls.members[member], function(memberItem) { - origKey = ['class', cls.name, memberItem.id]; - key = ['class', memberItem.owner, memberItem.id]; - commentId = 'comments-' + origKey.join('-').replace(/\./g, '-'); + var origKey = ['class', cls.name, memberItem.id]; + var key = ['class', memberItem.owner, memberItem.id]; + var commentId = 'comments-' + origKey.join('-').replace(/\./g, '-'); Docs.commentMeta.idMap[commentId] = key; }, this); } @@ -229,4 +223,4 @@ Ext.define('Docs.controller.CommentsMeta', { }); } } -}); \ No newline at end of file +}); diff --git a/template/app/view/Comments.js b/template/app/view/Comments.js index 8e578e44..d2e9d01e 100644 --- a/template/app/view/Comments.js +++ b/template/app/view/Comments.js @@ -1,10 +1,11 @@ +/** + * View for rendering comments. + */ Ext.define('Docs.view.Comments', { - singleton: true, requires: ['Docs.view.auth.Login'], constructor: function() { - var numComments = [ '', 'View {[values.num == 1 ? "1 comment" : values.num + " comments"]}', @@ -268,7 +269,6 @@ Ext.define('Docs.view.Comments', { * Renders the comment containers for the currently active class */ renderClassCommentContainers: function(cls) { - // Add comment button to class toolbar Ext.ComponentQuery.query('classoverview toolbar')[0].insert(-2, { xtype: 'container', @@ -299,7 +299,6 @@ Ext.define('Docs.view.Comments', { * Updates the comment meta information (i.e. number of comments) on a class page */ updateClassCommentMeta: function(cls) { - var clsMeta = Docs.commentMeta['class'][cls]; if (clsMeta && clsMeta['']) { @@ -323,7 +322,6 @@ Ext.define('Docs.view.Comments', { // Update class member comments meta Ext.Array.each(Ext.query('.member'), function(memberDom) { - var memberEl = Ext.get(memberDom), memberId = memberEl.getAttribute('id'), memberCls = memberEl.down('.meta .docClass').getAttribute('rel'), @@ -350,14 +348,12 @@ Ext.define('Docs.view.Comments', { this.updateClassIndex(); Ext.Array.each(Ext.ComponentQuery.query('hovermenu'), function(m) { - m.fireEvent('refresh', this) + m.fireEvent('refresh', this); }); }, renderHoverMenuMeta: function(cmp) { - Ext.Array.each(cmp.query('a.docClass'), function(a) { - var rel = "comments-class-" + a.getAttribute('rel').replace(/[^A-Za-z\-]/g, '-'), relEl = Ext.get(a), memberComments = relEl.down('.toggleMemberComments'), @@ -368,7 +364,7 @@ Ext.define('Docs.view.Comments', { if (memberComments) { if (!meta) { - memberComments.remove() + memberComments.remove(); } else { memberComments.update(String(meta)); } @@ -397,16 +393,14 @@ Ext.define('Docs.view.Comments', { }, renderNewCommentForms: function() { - var currentUser = Docs.App.getController('Auth').currentUser; Ext.Array.each(Ext.query('.new-comment-wrap'), function(newComment) { - var hideCommentForm = Ext.get(newComment).up('.comment-list').parent().hasCls('hideCommentForm'); if (hideCommentForm) { + // Do nothing } else if (Docs.App.getController('Auth').isLoggedIn()) { - var wrap = this.loggedInCommentTpl.overwrite(newComment, currentUser, true), textarea = wrap.down('textarea').dom; @@ -445,7 +439,6 @@ Ext.define('Docs.view.Comments', { }, showMember: function(cls, member) { - var memberEl = Ext.get(member).down('.long'), id = ('class-' + cls + '-' + member).replace(/\./g, '-'); @@ -458,4 +451,4 @@ Ext.define('Docs.view.Comments', { Docs.App.getController('CommentsMeta').commentIdMap['comments-' + id] = ['class', cls, member]; } } -}); \ No newline at end of file +}); diff --git a/template/app/view/auth/Login.js b/template/app/view/auth/Login.js index a129ae40..03ea1f96 100644 --- a/template/app/view/auth/Login.js +++ b/template/app/view/auth/Login.js @@ -1,3 +1,6 @@ +/** + * View for login form. + */ Ext.define('Docs.view.auth.Login', { extend: 'Ext.container.Container', alias: 'widget.authentication', -- GitLab