diff options
Diffstat (limited to 'sonar-server/src/main/webapp/javascripts/coding-rules/views')
2 files changed, 156 insertions, 1 deletions
diff --git a/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.coffee b/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.coffee index 9ff525e9a62..2c0e74937e3 100644 --- a/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.coffee +++ b/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.coffee @@ -2,13 +2,86 @@ define [ 'backbone.marionette', 'common/handlebars-extensions' ], ( - Marionette, + Marionette ) -> class CodingRulesDetailView extends Marionette.ItemView template: getTemplate '#coding-rules-detail-template' + ui: + tagsChange: '.coding-rules-detail-tags-change' + tagInput: '.coding-rules-detail-tag-input' + tagsEdit: '.coding-rules-detail-tag-edit' + tagsEditDone: '.coding-rules-detail-tag-edit-done' + tagsList: '.coding-rules-detail-tag-list' + + descriptionExtra: '#coding-rules-detail-description-extra' + extendDescriptionLink: '#coding-rules-detail-extend-description' + extendDescriptionForm: '#coding-rules-detail-extend-description-form' + extendDescriptionSubmit: '#coding-rules-detail-extend-description-submit' + extendDescriptionText: '#coding-rules-detail-extend-description-text' + extendDescriptionSpinner: '#coding-rules-detail-extend-description-spinner' + cancelExtendDescription: '#coding-rules-detail-extend-description-cancel' + + + events: + 'click @ui.tagsChange': 'changeTags' + 'click @ui.tagsEditDone': 'editDone' + + 'click @ui.extendDescriptionLink': 'showExtendDescriptionForm' + 'click @ui.cancelExtendDescription': 'hideExtendDescriptionForm' + 'click @ui.extendDescriptionSubmit': 'submitExtendDescription' + + onRender: -> + @ui.tagInput.select2 + tags: _.difference @options.app.tags, @model.get 'tags' + width: '500px' + @ui.tagsEdit.hide() + + @ui.extendDescriptionForm.hide() + @ui.extendDescriptionSpinner.hide() + qp = @options.app.getActiveQualityProfile() @$('.coding-rules-detail-quality-profile').first().addClass 'active' if qp? + + + changeTags: -> + @ui.tagsEdit.show() + @ui.tagsList.hide() + + + editDone: -> + @ui.tagsEdit.html '<i class="spinner"></i>' + tags = @ui.tagInput.val() + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/codingrules/set_tags" + data: tags: tags + .done => + @model.set 'tags', tags.split ',' + @render() + + + showExtendDescriptionForm: -> + @ui.descriptionExtra.hide() + @ui.extendDescriptionForm.show() + + + hideExtendDescriptionForm: -> + @ui.descriptionExtra.show() + @ui.extendDescriptionForm.hide() + + + submitExtendDescription: -> + @ui.extendDescriptionForm.hide() + @ui.extendDescriptionSpinner.show() + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/codingrules/extend_description" + dataType: 'json' + data: text: @ui.extendDescriptionText.val() + .done (r) => + @model.set extra: r.extra, extraRaw: r.extraRaw + @render()
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.js b/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.js index ae0db796904..9e1a0c335ff 100644 --- a/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.js +++ b/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.js @@ -15,14 +15,96 @@ CodingRulesDetailView.prototype.template = getTemplate('#coding-rules-detail-template'); + CodingRulesDetailView.prototype.ui = { + tagsChange: '.coding-rules-detail-tags-change', + tagInput: '.coding-rules-detail-tag-input', + tagsEdit: '.coding-rules-detail-tag-edit', + tagsEditDone: '.coding-rules-detail-tag-edit-done', + tagsList: '.coding-rules-detail-tag-list', + descriptionExtra: '#coding-rules-detail-description-extra', + extendDescriptionLink: '#coding-rules-detail-extend-description', + extendDescriptionForm: '#coding-rules-detail-extend-description-form', + extendDescriptionSubmit: '#coding-rules-detail-extend-description-submit', + extendDescriptionText: '#coding-rules-detail-extend-description-text', + extendDescriptionSpinner: '#coding-rules-detail-extend-description-spinner', + cancelExtendDescription: '#coding-rules-detail-extend-description-cancel' + }; + + CodingRulesDetailView.prototype.events = { + 'click @ui.tagsChange': 'changeTags', + 'click @ui.tagsEditDone': 'editDone', + 'click @ui.extendDescriptionLink': 'showExtendDescriptionForm', + 'click @ui.cancelExtendDescription': 'hideExtendDescriptionForm', + 'click @ui.extendDescriptionSubmit': 'submitExtendDescription' + }; + CodingRulesDetailView.prototype.onRender = function() { var qp; + this.ui.tagInput.select2({ + tags: _.difference(this.options.app.tags, this.model.get('tags')), + width: '500px' + }); + this.ui.tagsEdit.hide(); + this.ui.extendDescriptionForm.hide(); + this.ui.extendDescriptionSpinner.hide(); qp = this.options.app.getActiveQualityProfile(); if (qp != null) { return this.$('.coding-rules-detail-quality-profile').first().addClass('active'); } }; + CodingRulesDetailView.prototype.changeTags = function() { + this.ui.tagsEdit.show(); + return this.ui.tagsList.hide(); + }; + + CodingRulesDetailView.prototype.editDone = function() { + var tags, + _this = this; + this.ui.tagsEdit.html('<i class="spinner"></i>'); + tags = this.ui.tagInput.val(); + return jQuery.ajax({ + type: 'POST', + url: "" + baseUrl + "/api/codingrules/set_tags", + data: { + tags: tags + } + }).done(function() { + _this.model.set('tags', tags.split(',')); + return _this.render(); + }); + }; + + CodingRulesDetailView.prototype.showExtendDescriptionForm = function() { + this.ui.descriptionExtra.hide(); + return this.ui.extendDescriptionForm.show(); + }; + + CodingRulesDetailView.prototype.hideExtendDescriptionForm = function() { + this.ui.descriptionExtra.show(); + return this.ui.extendDescriptionForm.hide(); + }; + + CodingRulesDetailView.prototype.submitExtendDescription = function() { + var _this = this; + this.ui.extendDescriptionForm.hide(); + this.ui.extendDescriptionSpinner.show(); + return jQuery.ajax({ + type: 'POST', + url: "" + baseUrl + "/api/codingrules/extend_description", + dataType: 'json', + data: { + text: this.ui.extendDescriptionText.val() + } + }).done(function(r) { + _this.model.set({ + extra: r.extra, + extraRaw: r.extraRaw + }); + return _this.render(); + }); + }; + return CodingRulesDetailView; })(Marionette.ItemView); |