LT-67 Fixing navigation issues and implementing server's removal

This commit is contained in:
Bruno Alves de Faria 2016-05-14 23:46:10 -03:00 committed by Erik Ziegler
parent 16a302e979
commit 1ca585bfb0
6 changed files with 37 additions and 33 deletions

View File

@ -3,7 +3,9 @@ Template.serverInformationDimse.onCreated(function() {
instance.peers = new ReactiveVar([]);
instance.autorun(function() {
var currentItem = instance.data.currentItem.get();
instance.peers.set(currentItem.peers || []);
if (currentItem) {
instance.peers.set(currentItem.peers || []);
}
});
});

View File

@ -25,7 +25,7 @@ Template.serverInformationForm.events({
console.log('>>>>ERROR', error);
}
instance.data.mode.set('list');
instance.data.resetState();
});
}
});

View File

@ -14,10 +14,10 @@
<td>{{this.type}}</td>
<td class="text-right">
<div class="btn-group" role="group" aria-label="Actions">
<button class="btn btn-sm btn-default editServer" {{tooltipTop "Edit"}}>
<button class="btn btn-sm btn-default js-edit-server" title="Edit">
<i class="fa fa-pencil"></i>
</button>
<button class="btn btn-sm btn-danger removeServer" {{tooltipTop "Remove"}}>
<button class="btn btn-sm btn-danger js-remove-server" title="Remove">
<i class="fa fa-trash"></i>
</button>
</div>
@ -30,7 +30,7 @@
{{/each}}
</tbody>
</table>
<button class="btn btn-default addServer">
<button class="btn btn-default js-add-server">
<i class="fa fa-plus"></i> Add a new server
</button>
</template>

View File

@ -1,34 +1,24 @@
Template.serverInformationList.onRendered(function() {
var instance = Template.instance();
instance.$('[data-toggle="tooltip"]').tooltip({
container: 'body'
});
});
Template.serverInformationList.onDestroyed(function() {
var instance = Template.instance();
instance.$('[data-toggle="tooltip"]').tooltip('destroy');
});
Template.serverInformationList.helpers({
tooltipTop: function(title) {
return {
'data-toggle': 'tooltip',
'data-placement': 'top',
title: title
};
},
servers: function() {
return Servers.find().fetch();
}
});
Template.serverInformationList.events({
'click .addServer': function(event, instance) {
'click .js-add-server': function(event, instance) {
instance.data.mode.set('create');
},
'click .editServer': function(event, instance) {
'click .js-edit-server': function(event, instance) {
instance.data.currentItem.set(this);
instance.data.mode.set('edit');
},
'click .js-remove-server': function(event, instance) {
var id = this._id;
Meteor.call('removeServer', this._id, function(error) {
if (error) {
// TODO: check for errors: not-authorized, data-write
console.log('>>>>ERROR', error);
}
});
}
});

View File

@ -4,14 +4,17 @@ Template.serverInformationModal.onCreated(function() {
mode: new ReactiveVar('list'),
serverType: new ReactiveVar(null),
currentItem: new ReactiveVar(null),
$form: null
$form: null,
resetState: function() {
instance.container.mode.set('list');
instance.container.serverType.set(null);
instance.container.currentItem.set(null);
}
};
});
Template.serverInformationModal.events({
'click .js-back': function(event, instance) {
var container = instance.container;
container.mode.set('list');
container.serverType.set(null);
'click .js-back, click [data-dismiss=modal]': function(event, instance) {
instance.container.resetState();
}
});

View File

@ -12,12 +12,13 @@ Meteor.startup(function() {
});
Meteor.methods({
saveServer: function(serverSettings) {
if (!Meteor.userId()) {
throw new Meteor.Error('not-authorized');
}
var criteria = {
var query = {
_id: serverSettings._id
};
var options = {
@ -35,6 +36,14 @@ Meteor.methods({
};
Servers.update(criteria, serverSettings, options, callback);
Servers.update(query, serverSettings, options, callback);
},
removeServer: function(serverId) {
var query = {
_id: serverId
};
Servers.remove(query, true);
}
});