]> source.dussan.org Git - sonarqube.git/commitdiff
add backbone-super
authorStas Vilchik <vilchiks@gmail.com>
Tue, 2 Jun 2015 15:18:28 +0000 (17:18 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Tue, 2 Jun 2015 15:18:28 +0000 (17:18 +0200)
19 files changed:
server/sonar-web/Gruntfile.coffee
server/sonar-web/src/main/js/apps/groups/delete-view.js
server/sonar-web/src/main/js/apps/groups/form-view.js
server/sonar-web/src/main/js/apps/groups/groups.js
server/sonar-web/src/main/js/apps/groups/list-footer-view.js
server/sonar-web/src/main/js/apps/groups/users-view.js
server/sonar-web/src/main/js/apps/provisioning/delete-view.js
server/sonar-web/src/main/js/apps/provisioning/form-view.js
server/sonar-web/src/main/js/apps/provisioning/list-footer-view.js
server/sonar-web/src/main/js/apps/provisioning/projects.js
server/sonar-web/src/main/js/apps/users/change-password-view.js
server/sonar-web/src/main/js/apps/users/deactivate-view.js
server/sonar-web/src/main/js/apps/users/form-view.js
server/sonar-web/src/main/js/apps/users/groups-view.js
server/sonar-web/src/main/js/apps/users/list-footer-view.js
server/sonar-web/src/main/js/apps/users/list-item-view.js
server/sonar-web/src/main/js/apps/users/users.js
server/sonar-web/src/main/js/libs/third-party/backbone-super.js [new file with mode: 0644]
server/sonar-web/src/test/views/layouts/main.jade

index fc55da5fceb8d8a7ac20a2483abb0c94df448e2a..7375822b38e6c2920fa7dacd992d5521046ffa06 100644 (file)
@@ -46,6 +46,7 @@ module.exports = (grunt) ->
             '<%= BUILD_PATH %>/js/libs/third-party/latinize.js'
             '<%= BUILD_PATH %>/js/libs/third-party/underscore.js'
             '<%= BUILD_PATH %>/js/libs/third-party/backbone.js'
+            '<%= BUILD_PATH %>/js/libs/third-party/backbone-super.js'
             '<%= BUILD_PATH %>/js/libs/third-party/backbone.marionette.js'
             '<%= BUILD_PATH %>/js/libs/third-party/handlebars.js'
             '<%= BUILD_PATH %>/js/libs/third-party/underscore.js'
index 8fd83d34031f71db0fdba8a286729b66844a6d58..137aa768da2808c3c6deefcb6ca8fdfcbd42ddee 100644 (file)
@@ -6,8 +6,8 @@ define([
   return ModalForm.extend({
     template: Templates['groups-delete'],
 
-    onFormSubmit: function () {
-      ModalForm.prototype.onFormSubmit.apply(this, arguments);
+    onFormSubmit: function (e) {
+      this._super(e);
       this.sendRequest();
     },
 
index aa872784e1e31fbccb7b141dd882d1b93b978238..e79ea6eec65e860f90a1c13757c320ec222c60e5 100644 (file)
@@ -7,17 +7,17 @@ define([
     template: Templates['groups-form'],
 
     onRender: function () {
-      ModalForm.prototype.onRender.apply(this, arguments);
+      this._super();
       this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' });
     },
 
     onClose: function () {
-      ModalForm.prototype.onClose.apply(this, arguments);
+      this._super();
       this.$('[data-toggle="tooltip"]').tooltip('destroy');
     },
 
-    onFormSubmit: function () {
-      ModalForm.prototype.onFormSubmit.apply(this, arguments);
+    onFormSubmit: function (e) {
+      this._super(e);
       this.sendRequest();
     }
   });
index 9ddd6c9f9a1a97bdebc65991f91a8810d9f38e6a..dcfbb8c731bf30ec05f5492b68fa4e00bbed627e 100644 (file)
@@ -19,7 +19,7 @@ define([
     fetch: function (options) {
       var d = (options && options.data) || {};
       this.q = d.q;
-      return Backbone.Collection.prototype.fetch.apply(this, arguments);
+      return this._super(options);
     },
 
     fetchMore: function () {
index cdad034f24ac408ff3107ea059dcc9a587814290..3c0fbe198c52229193c6913925bdecce9025edef 100644 (file)
@@ -23,7 +23,7 @@ define([
     },
 
     serializeData: function () {
-      return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), {
+      return _.extend(this._super(), {
         total: this.collection.total,
         count: this.collection.length,
         more: this.collection.hasMore()
index bd236b670409eaa6dcba48bb21b3c6a924d1a533..7786d63fe44d669881fd49676f64d11cbd4c03e0 100644 (file)
@@ -8,7 +8,7 @@ define([
     template: Templates['groups-users'],
 
     onRender: function () {
-      Modal.prototype.onRender.apply(this, arguments);
+      this._super();
       new window.SelectList({
         el: this.$('#groups-users'),
         width: '100%',
@@ -35,7 +35,7 @@ define([
 
     onClose: function () {
       this.model.collection.refresh();
-      Modal.prototype.onClose.apply(this, arguments);
+      this._super();
     }
   });
 
index 2ff38de169f6890f172d13bcb36e3cbb848d58d0..7797227aa40e6105177411a18ca09409cb0d7734 100644 (file)
@@ -6,8 +6,8 @@ define([
   return ModalForm.extend({
     template: Templates['provisioning-delete'],
 
-    onFormSubmit: function () {
-      ModalForm.prototype.onFormSubmit.apply(this, arguments);
+    onFormSubmit: function (e) {
+      this._super(e);
       this.sendRequest();
     },
 
index ed7fe702f2cc50d5e08a36bd724c93ff585e5cd5..ce359c6fa075370ffef72b8563bf6686dbfa70ce 100644 (file)
@@ -7,17 +7,17 @@ define([
     template: Templates['provisioning-form'],
 
     onRender: function () {
-      ModalForm.prototype.onRender.apply(this, arguments);
+      this._super();
       this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' });
     },
 
     onClose: function () {
-      ModalForm.prototype.onClose.apply(this, arguments);
+      this._super();
       this.$('[data-toggle="tooltip"]').tooltip('destroy');
     },
 
-    onFormSubmit: function () {
-      ModalForm.prototype.onFormSubmit.apply(this, arguments);
+    onFormSubmit: function (e) {
+      this._super(e);
       this.sendRequest();
     }
 
index 6dc243e7b67ef2dea86456763eb08fe19bb1ea35..902b9322372d3f821ec057eab769f227840347d6 100644 (file)
@@ -23,7 +23,7 @@ define([
     },
 
     serializeData: function () {
-      return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), {
+      return _.extend(this._super(), {
         total: this.collection.total,
         count: this.collection.length,
         more: this.collection.hasMore()
index 44f1c5b4b5a9aa9a477cf480e47dbe2148da5ca7..a5c26347c59b8ca76f496500a6cd59308f9a588f 100644 (file)
@@ -19,7 +19,7 @@ define([
     fetch: function (options) {
       var d = (options && options.data) || {};
       this.q = d.q;
-      return Backbone.Collection.prototype.fetch.apply(this, arguments);
+      return this._super(options);
     },
 
     fetchMore: function () {
index cd2a892fc2bca4b02acbca5d65382d05df4ac273..6187333c9e65b4fce7aae27253d5104472dbaae7 100644 (file)
@@ -6,8 +6,8 @@ define([
   return ModalForm.extend({
     template: Templates['users-change-password'],
 
-    onFormSubmit: function () {
-      ModalForm.prototype.onFormSubmit.apply(this, arguments);
+    onFormSubmit: function (e) {
+      this._super(e);
       this.sendRequest();
     },
 
index cf4c4654984716a020bc2921c63d2c4687391a3d..37c71d4a94b18a7307b887dff475b9250858291b 100644 (file)
@@ -6,8 +6,8 @@ define([
   return ModalForm.extend({
     template: Templates['users-deactivate'],
 
-    onFormSubmit: function () {
-      ModalForm.prototype.onFormSubmit.apply(this, arguments);
+    onFormSubmit: function (e) {
+      this._super(e);
       this.sendRequest();
     },
 
index 2cf2e1ac3f1b09ad705703b86e4cea52314c4785..f1c7f602d14bd3082989487f8040c64a462083c6 100644 (file)
@@ -9,23 +9,23 @@ define([
     template: Templates['users-form'],
 
     events: function () {
-      return _.extend(ModalForm.prototype.events.apply(this, arguments), {
+      return _.extend(this._super(), {
         'click #create-user-add-scm-account': 'onAddScmAccountClick'
       });
     },
 
     onRender: function () {
-      ModalForm.prototype.onRender.apply(this, arguments);
+      this._super();
       this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' });
     },
 
     onClose: function () {
-      ModalForm.prototype.onClose.apply(this, arguments);
+      this._super();
       this.$('[data-toggle="tooltip"]').tooltip('destroy');
     },
 
-    onFormSubmit: function () {
-      ModalForm.prototype.onFormSubmit.apply(this, arguments);
+    onFormSubmit: function (e) {
+      this._super(e);
       this.sendRequest();
     },
 
index 992594b4f101cdb09c961fb4478647be99a5d166..6a874070b660b968b0233fc38f6a8c94a825366b 100644 (file)
@@ -9,7 +9,7 @@ define([
     itemTemplate: Templates['users-group'],
 
     onRender: function () {
-      Modal.prototype.onRender.apply(this, arguments);
+      this._super();
       new window.SelectList({
         el: this.$('#users-groups'),
         width: '100%',
index 968ad0990d5a6b6a89a07dd7f5c0f04b74a011a7..cf802586354e272f366d731013808a3229064dbc 100644 (file)
@@ -23,7 +23,7 @@ define([
     },
 
     serializeData: function () {
-      return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), {
+      return _.extend(this._super(), {
         total: this.collection.total,
         count: this.collection.length,
         more: this.collection.hasMore()
index c6a81a2e71f20f3c8612ab3eefe0138e10408f02..99aa973579bbc2be63da3e72f0a19ad7d7a4ec85 100644 (file)
@@ -101,7 +101,7 @@ define([
           scmAccountsLimit = scmAccounts.length > this.scmLimit ? this.scmLimit - 1 : this.scmLimit,
           groups = this.model.get('groups'),
           groupsLimit = groups.length > this.groupsLimit ? this.groupsLimit - 1 : this.groupsLimit;
-      return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), {
+      return _.extend(this._super(), {
         firstScmAccounts: _.first(scmAccounts, scmAccountsLimit),
         moreScmAccountsCount: scmAccounts.length - scmAccountsLimit,
         firstGroups: _.first(groups, groupsLimit),
index adf80b669dad86f05d0fe29b2919a233f3e91877..9c45979a9fefce4a35e863dee2f4dc195ba733d3 100644 (file)
@@ -19,7 +19,7 @@ define([
     fetch: function (options) {
       var d = (options && options.data) || {};
       this.q = d.q;
-      return Backbone.Collection.prototype.fetch.apply(this, arguments);
+      return this._super(options);
     },
 
     fetchMore: function () {
diff --git a/server/sonar-web/src/main/js/libs/third-party/backbone-super.js b/server/sonar-web/src/main/js/libs/third-party/backbone-super.js
new file mode 100644 (file)
index 0000000..9562638
--- /dev/null
@@ -0,0 +1,111 @@
+// This is a plugin, constructed from parts of Backbone.js and John Resig's inheritance script.
+// (See http://backbonejs.org, http://ejohn.org/blog/simple-javascript-inheritance/)
+// No credit goes to me as I did absolutely nothing except patch these two together.
+(function(root, factory) {
+
+  // Set up Backbone appropriately for the environment. Start with AMD.
+  if (typeof define === 'function' && define.amd) {
+    define(['underscore', 'backbone'], function(_, Backbone) {
+      // Export global even in AMD case in case this script is loaded with
+      // others that may still expect a global Backbone.
+      factory( _, Backbone);
+    });
+
+  // Next for Node.js or CommonJS.
+  } else if (typeof exports !== 'undefined' && typeof require === 'function') {
+    var _ = require('underscore'),
+               Backbone = require('backbone');
+    factory(_, Backbone);
+
+  // Finally, as a browser global.
+  } else {
+    factory(root._, root.Backbone);
+  }
+
+}(this, function factory(_, Backbone) {
+       Backbone.Model.extend = Backbone.Collection.extend = Backbone.Router.extend = Backbone.View.extend = function(protoProps, classProps) {
+               var child = inherits(this, protoProps, classProps);
+               child.extend = this.extend;
+               return child;
+       };
+       var unImplementedSuper = function(method){throw "Super does not implement this method: " + method;};
+
+  var fnTest = /\b_super\b/;
+
+  var makeWrapper = function(parentProto, name, fn) {
+    var wrapper = function() {
+      var tmp = this._super;
+
+      // Add a new ._super() method that is the same method
+      // but on the super-class
+      this._super = parentProto[name] || unImplementedSuper(name);
+
+      // The method only need to be bound temporarily, so we
+      // remove it when we're done executing
+      var ret;
+      try {
+        ret = fn.apply(this, arguments);
+      } finally {
+        this._super = tmp;
+      }
+      return ret;
+    };
+
+    //we must move properties from old function to new
+    for (var prop in fn) {
+      wrapper[prop] = fn[prop];
+      delete fn[prop];
+    }
+
+    return wrapper;
+  };
+
+       var ctor = function(){}, inherits = function(parent, protoProps, staticProps) {
+        var child, parentProto = parent.prototype;
+
+               // The constructor function for the new subclass is either defined by you
+               // (the "constructor" property in your `extend` definition), or defaulted
+               // by us to simply call the parent's constructor.
+               if (protoProps && protoProps.hasOwnProperty('constructor')) {
+                       child = protoProps.constructor;
+               } else {
+                       child = function(){ return parent.apply(this, arguments); };
+               }
+
+               // Inherit class (static) properties from parent.
+               _.extend(child, parent, staticProps);
+
+               // Set the prototype chain to inherit from `parent`, without calling
+               // `parent`'s constructor function.
+               ctor.prototype = parentProto;
+               child.prototype = new ctor();
+
+               // Add prototype properties (instance properties) to the subclass,
+               // if supplied.
+               if (protoProps) {
+                       _.extend(child.prototype, protoProps);
+
+                       // Copy the properties over onto the new prototype
+                       for (var name in protoProps) {
+                               // Check if we're overwriting an existing function
+                               if (typeof protoProps[name] == "function" && fnTest.test(protoProps[name])) {
+                                       child.prototype[name] = makeWrapper(parentProto, name, protoProps[name]);
+                               }
+                       }
+               }
+
+               // Add static properties to the constructor function, if supplied.
+               if (staticProps) _.extend(child, staticProps);
+
+               // Correctly set child's `prototype.constructor`.
+               child.prototype.constructor = child;
+
+               // Set a convenience property in case the parent's prototype is needed later.
+               child.__super__ = parentProto;
+
+               return child;
+       };
+
+       return inherits;
+}));
+
index 901a104205594e6a09581504dabe8172f756a82c..ccc08eb3ad85d0e0e1542ce8ae442efd368b66e5 100644 (file)
@@ -10,6 +10,7 @@ html
     script(src='/js/libs/third-party/latinize.js')
     script(src='/js/libs/third-party/underscore.js')
     script(src='/js/libs/third-party/backbone.js')
+    script(src='/js/libs/third-party/backbone-super.js')
     script(src='/js/libs/third-party/backbone.marionette.js')
     script(src='/js/libs/third-party/handlebars.js')
     script(src='/js/libs/third-party/underscore.js')