diff --git a/frontend/js/collections/arangoCollections.js b/frontend/js/collections/arangoCollections.js index 6e366b7c99..4df28db236 100644 --- a/frontend/js/collections/arangoCollections.js +++ b/frontend/js/collections/arangoCollections.js @@ -32,8 +32,42 @@ window.arangoCollections = Backbone.Collection.extend({ }); return data2; }, - rename: function (id) { + checkCollectionName: function (name) { + }, + renameCollection: function (id, name) { + $.ajax({ + type: "PUT", + async: false, // sequential calls! + url: "/_api/collection/" + id + "/rename", + data: '{"name":"' + name + '"}', + contentType: "application/json", + processData: false, + success: function(data) { + alert("Collection renamed"); + }, + error: function(data) { + alert(getErrorMessage(data)); + failed = true; + } + }); + }, + changeCollection: function (id, wfs, journalSize) { + $.ajax({ + type: "PUT", + async: false, // sequential calls! + url: "/_api/collection/" + id + "/properties", + data: '{"waitForSync":' + wfs + ',"journalSize":' + JSON.stringify(journalSize) + '}', + contentType: "application/json", + processData: false, + success: function(data) { + alert("Saved collection properties"); + }, + error: function(data) { + alert(getErrorMessage(data)); + failed = true; + } + }); }, deleteCollection: function (id) { diff --git a/frontend/js/templates/documentsView.ejs b/frontend/js/templates/documentsView.ejs index 4620872ff3..ad5aa940d1 100644 --- a/frontend/js/templates/documentsView.ejs +++ b/frontend/js/templates/documentsView.ejs @@ -13,10 +13,10 @@
- - - + + +
diff --git a/frontend/js/views/collectionView.js b/frontend/js/views/collectionView.js index 22e51db679..7658e8162a 100644 --- a/frontend/js/views/collectionView.js +++ b/frontend/js/views/collectionView.js @@ -25,18 +25,18 @@ var collectionView = Backbone.View.extend({ window.location.hash = "#"; }, fillModal: function() { - myCollection = window.arangoCollectionsStore.get(this.options.colId).attributes; - $('#change-collection-name').val(myCollection.name); - $('#change-collection-id').val(myCollection.id); - $('#change-collection-type').val(myCollection.type); - $('#change-collection-status').val(myCollection.status); + this.myCollection = window.arangoCollectionsStore.get(this.options.colId).attributes; + $('#change-collection-name').val(this.myCollection.name); + $('#change-collection-id').val(this.myCollection.id); + $('#change-collection-type').val(this.myCollection.type); + $('#change-collection-status').val(this.myCollection.status); - if (myCollection.status == 'unloaded') { + if (this.myCollection.status == 'unloaded') { $('#colFooter').append(''); $('#collectionSizeBox').hide(); $('#collectionSyncBox').hide(); } - else if (myCollection.status == 'loaded') { + else if (this.myCollection.status == 'loaded') { $('#colFooter').append(''); var data = window.arangoCollectionsStore.getProperties(this.options.colId, true); this.fillLoadedModal(data); @@ -51,19 +51,50 @@ var collectionView = Backbone.View.extend({ else { $('#change-collection-sync').val('true'); } - $('#change-collection-size').val(data.journalSize); + var calculatedSize = data.journalSize / 1024 / 1024; + $('#change-collection-size').val(calculatedSize); $('#change-collection').modal('show') }, saveModifiedCollection: function() { + var collid = this.getCollectionId(); + var status = this.getCollectionStatus(); + if (status === 'loaded') { + var newname = $('#change-collection-name').val(); + if (this.myCollection.name !== newname) { + window.arangoCollectionsStore.renameCollection(collid, newname ); + } + + var wfs = $('#change-collection-sync').val(); + var journalSize = JSON.parse($('#change-collection-size').val() * 1024 * 1024); + window.arangoCollectionsStore.changeCollection(collid, wfs, journalSize); + this.hideModal(); + } + else if (status === 'unloaded') { + var newname = $('#change-collection-name').val(); + if (this.myCollection.name !== newname) { + console.log("different name"); + window.arangoCollectionsStore.renameCollection(collid, newname ); + this.hideModal(); + } + } + }, + getCollectionId: function () { + return this.myCollection.id; + }, + getCollectionStatus: function () { + return this.myCollection.status; }, unloadCollection: function () { - var collid = $('#change-collection-name').val(); + var collid = this.getCollectionId(); window.arangoCollectionsStore.unloadCollection(collid); - $('#change-collection').modal('hide'); + this.hideModal(); }, loadCollection: function () { - var collid = $('#change-collection-name').val(); + var collid = this.getCollectionId(); window.arangoCollectionsStore.loadCollection(collid); + this.hideModal(); + }, + hideModal: function () { $('#change-collection').modal('hide'); }, deleteCollection: function () { @@ -74,10 +105,10 @@ var collectionView = Backbone.View.extend({ type: 'DELETE', url: "/_api/collection/" + collName, success: function () { - $('#change-collection').modal('hide'); + self.hideModal(); }, error: function () { - $('#change-collection').modal('hide'); + self.hideModal(); alert('Error'); } });