Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
16 agent/src/main/webapp/js/models.js
@@ -358,6 +358,22 @@ Diffa.Models.Domain = Backbone.Model.extend({
this.endpoints = new Diffa.Collections.Endpoints([], {domain: this});
this.pairs = new Diffa.Collections.Pairs([], {domain: this});
this.pairStates = new Diffa.Collections.PairStates([], {domain: this});
+ },
+
+ loadAll: function(colls, callback) {
+ var self = this;
+ var remaining = colls.length;
+ _.each(colls, function(preload) {
+ self[preload].fetch({
+ success: function() {
+ remaining -= 1;
+
+ if (remaining == 0) {
+ callback();
+ }
+ }
+ });
+ });
}
});
View
85 agent/src/main/webapp/js/settings.js
@@ -24,27 +24,47 @@ Diffa.Routers.Config = Backbone.Router.extend({
"pair/:pair": "managePair" // #pair/p1
},
+ initialize: function(opts) {
+ this.domain = opts.domain;
+ this.el = opts.el;
+
+ this.endpointEditorEl = $('.diffa-endpoint-editor', this.el);
+ this.pairEditorEl = $('.diffa-pair-editor', this.el);
+ },
+
index: function() {
this.updateEditor(null);
},
createEndpoint: function() {
+ var self = this;
var newEndpoint = new Diffa.Models.Endpoint();
- this.updateEditor(function() { return new Diffa.Views.EndpointEditor({model: newEndpoint, collection: Diffa.domain.endpoints}) });
+ this.updateEditor(function() {
+ return new Diffa.Views.EndpointEditor({model: newEndpoint, collection: self.domain.endpoints, el: self.endpointEditorEl})
+ });
},
createPair: function() {
+ var self = this;
var newPair = new Diffa.Models.Pair();
- this.updateEditor(function() { return new Diffa.Views.PairEditor({model: newPair, collection: Diffa.domain.pairs}) });
+ this.updateEditor(function() {
+ return new Diffa.Views.PairEditor({model: newPair, collection: self.domain.pairs, el: self.pairEditorEl})
+ });
},
manageEndpoint: function(endpointName) {
- var endpoint = Diffa.domain.endpoints.get(endpointName);
- this.updateEditor(function() { return new Diffa.Views.EndpointEditor({model: endpoint, collection: Diffa.domain.endpoints}) });
+ var self = this;
+ var endpoint = self.domain.endpoints.get(endpointName);
+ this.updateEditor(function() {
+ return new Diffa.Views.EndpointEditor({model: endpoint, collection: self.domain.endpoints, el: self.endpointEditorEl})
+ });
},
managePair: function(pairName) {
- var pair = Diffa.domain.pairs.get(pairName);
- this.updateEditor(function() { return new Diffa.Views.PairEditor({model: pair, collection: Diffa.domain.pairs}) });
+ var self = this;
+ var pair = self.domain.pairs.get(pairName);
+ this.updateEditor(function() {
+ return new Diffa.Views.PairEditor({model: pair, collection: self.domain.pairs, el: self.pairEditorEl})
+ });
},
updateEditor: function(newEditorBuilder) {
@@ -216,7 +236,6 @@ Diffa.Views.FormEditor = Backbone.View.extend({
}
});
Diffa.Views.EndpointEditor = Diffa.Views.FormEditor.extend({
- el: $('#endpoint-editor'),
elementType: "endpoint",
template: window.JST['settings/endpointeditor'],
@@ -236,15 +255,15 @@ Diffa.Views.EndpointEditor = Diffa.Views.FormEditor.extend({
}
});
Diffa.Views.PairEditor = Diffa.Views.FormEditor.extend({
- el: $('#pair-editor'),
elementType: "pair",
template: window.JST['settings/paireditor'],
preBind: function() {
var selections = this.$('select.endpoint-selection');
+ var domain = this.model.collection.domain;
selections.empty();
- Diffa.domain.endpoints.each(function(ep) {
+ domain.endpoints.each(function(ep) {
selections.append('<option value="' + ep.get('name') + '">' + ep.get('name') + '</option>');
});
},
@@ -403,37 +422,31 @@ Diffa.Binders.ListBinder = Diffa.Binder.extend({
}
});
-Diffa.currentDomain = currentDiffaDomain;
-Diffa.SettingsApp = new Diffa.Routers.Config();
-Diffa.domain = new Diffa.Models.Domain({name: Diffa.currentDomain});
-Diffa.EndpointElementListView = new Diffa.Views.ElementList({
- el: $('#endpoints-list').html(window.JST['settings/endpointlist']()),
- collection: Diffa.domain.endpoints,
- elementType: 'endpoint'
+$('.diffa-endpoint-list').each(function() {
+ var domain = Diffa.DomainManager.get($(this).data('domain'));
+
+ new Diffa.Views.ElementList({
+ el: $(this).html(window.JST['settings/endpointlist']()),
+ collection: domain.endpoints,
+ elementType: 'endpoint'
+ });
});
-Diffa.EndpointElementListView = new Diffa.Views.ElementList({
- el: $('#pairs-list').html(window.JST['settings/pairlist']()),
- collection: Diffa.domain.pairs,
- elementType: 'pair'
+$('.diffa-pair-list').each(function() {
+ var domain = Diffa.DomainManager.get($(this).data('domain'));
+
+ new Diffa.Views.ElementList({
+ el: $(this).html(window.JST['settings/pairlist']()),
+ collection: domain.pairs,
+ elementType: 'pair'
+ });
});
-var preloadCollections = function(colls, callback) {
- var remaining = colls.length;
- _.each(colls, function(preload) {
- preload.fetch({
- success: function() {
- remaining -= 1;
+$('.diffa-settings-page').each(function() {
+ var domain = Diffa.DomainManager.get($(this).data('domain'));
+ new Diffa.Routers.Config({domain: domain, el: $(this)});
- if (remaining == 0) {
- callback();
- }
- }
- })
+ domain.loadAll(['endpoints', 'pairs'], function() {
+ Backbone.history.start();
});
-};
-
-// Preload useful collections, and then start processing history
-preloadCollections([Diffa.domain.endpoints, Diffa.domain.pairs], function() {
- Backbone.history.start();
});
});
View
12 agent/src/main/webapp/js/status.js
@@ -19,7 +19,13 @@ $(function() {
Diffa.Routers.Pairs = Backbone.Router.extend({
initialize: function(opts) {
+ var self = this;
+
this.domain = opts.domain;
+
+ $(opts.el).on(this.domain.id + ':pairSelected', function(e, selectedPairId) {
+ self.navigate("pair/" + selectedPairId, true);
+ });
},
routes: {
@@ -72,6 +78,8 @@ Diffa.Views.PairSelector = Backbone.View.extend({
this.model.bind('change:state', this.render);
this.model.bind('change:selected', this.render);
this.model.bind('remove', this.close);
+
+ this.domain = this.model.collection.domain; // Make access to the domain cleaner
},
render: function() {
@@ -86,7 +94,7 @@ Diffa.Views.PairSelector = Backbone.View.extend({
},
select: function() {
- Diffa.SettingsApp.navigate("pair/" + this.model.id, true);
+ $(this.el).trigger(this.domain.id + ':pairSelected', [this.model.id]);
},
renderState: function(state) {
@@ -332,7 +340,7 @@ $('.diffa-pair-log').each(function() {
$('.diffa-status-page').each(function() {
var domain = Diffa.DomainManager.get($(this).data('domain'));
- Diffa.SettingsApp = new Diffa.Routers.Pairs({domain: domain});
+ new Diffa.Routers.Pairs({domain: domain, el: this});
Backbone.history.start();
});
});
View
10 agent/src/main/webapp/settings.html
@@ -25,7 +25,7 @@
</head>
<body>
- <div id="settings-page" class="container">
+ <div id="settings-page" class="container diffa-settings-page">
<div class="main-logo">
<h1>Diffa Settings</h1>
@@ -36,13 +36,13 @@
</div>
<div id="elements">
- <div id="endpoints-list" class="element-list-panel"></div>
- <div id="pairs-list" class="element-list-panel"></div>
+ <div id="endpoints-list" class="diffa-endpoint-list element-list-panel"></div>
+ <div id="pairs-list" class="diffa-pair-list element-list-panel"></div>
</div>
<div id="details">
- <div style="display:none" id="endpoint-editor"></div>
- <div style="display:none" id="pair-editor"></div>
+ <div style="display:none" id="endpoint-editor" class="diffa-endpoint-editor"></div>
+ <div style="display:none" id="pair-editor" class="diffa-pair-editor"></div>
</div>
</div>
</body>

No commit comments for this range

Something went wrong with that request. Please try again.