1
0
Fork 0

#1065 - added option to add a key for a new document or edge

This commit is contained in:
Heiko Kernbach 2014-12-23 11:00:08 +01:00
parent bf076c8255
commit 09d14c1be4
3 changed files with 108 additions and 28 deletions

View File

@ -50,18 +50,29 @@ window.arangoDocument = Backbone.Collection.extend({
}
return returnval;
},
addDocument: function (collectionID) {
addDocument: function (collectionID, key) {
console.log("adding document");
var self = this;
self.createTypeDocument(collectionID);
self.createTypeDocument(collectionID, key);
},
createTypeEdge: function (collectionID, from, to) {
var result = false;
createTypeEdge: function (collectionID, from, to, key) {
var result = false, newEdge;
if (key) {
newEdge = JSON.stringify({
_key: key
});
}
else {
newEdge = JSON.stringify({});
}
$.ajax({
cache: false,
type: "POST",
async: false,
url: "/_api/edge?collection=" + collectionID + "&from=" + from + "&to=" + to,
data: JSON.stringify({}),
data: newEdge,
contentType: "application/json",
processData: false,
success: function(data) {
@ -73,14 +84,24 @@ window.arangoDocument = Backbone.Collection.extend({
});
return result;
},
createTypeDocument: function (collectionID) {
var result = false;
createTypeDocument: function (collectionID, key) {
var result = false, newDocument;
if (key) {
newDocument = JSON.stringify({
_key: key
});
}
else {
newDocument = JSON.stringify({});
}
$.ajax({
cache: false,
type: "POST",
async: false,
url: "/_api/document?collection=" + collectionID,
data: JSON.stringify({}),
url: "/_api/document?collection=" + encodeURIComponent(collectionID),
data: newDocument,
contentType: "application/json",
processData: false,
success: function(data) {

View File

@ -15,7 +15,7 @@ var cutByResolution = function (str) {
<thead>
<tr role="row">
<th class="sorting_disabled docsFirstCol" role="columnheader" rowspan="1" colspan="1">Content</th>
<th class="sorting_disabled docsSecCol" role="columnheader" rowspan="1" colspan="1">_key</th>
<th class="sorting_disabled docsSecCol" role="columnheader" rowspan="1" colspan="1"></th>
<th class="sorting_disabled docsThirdCol" role="columnheader" rowspan="1" colspan="1">
<a id="addDocumentButton" class="pull-right addButton"><span class="arangoicon icon_arangodb_roundplus" title="Add a document"></span></a>
</th>

View File

@ -75,7 +75,7 @@
"click .removeFilterItem" : "removeFilterItem",
"click #deleteSelected" : "deleteSelectedDocs",
"click #moveSelected" : "moveSelectedDocs",
"click #addDocumentButton" : "addDocument",
"click #addDocumentButton" : "addDocumentModal",
"click #documents_first" : "firstDocuments",
"click #documents_last" : "lastDocuments",
"click #documents_prev" : "prevDocuments",
@ -94,10 +94,10 @@
"click .deleteIndex" : "prepDeleteIndex",
"click #confirmDeleteIndexBtn" : "deleteIndex",
"click #documentsToolbar ul" : "resetIndexForms",
"click #indexHeader #addIndex" : "toggleNewIndexView",
"click #indexHeader #cancelIndex" : "toggleNewIndexView",
"change #documentSize" : "setPagesize",
"change #docsSort" : "setSorting"
"click #indexHeader #addIndex" : "toggleNewIndexView",
"click #indexHeader #cancelIndex" : "toggleNewIndexView",
"change #documentSize" : "setPagesize",
"change #docsSort" : "setSorting"
},
showSpinner: function() {
@ -490,13 +490,11 @@
this.filterId = 0;
},
addDocument: function () {
addDocumentModal: function () {
var collid = window.location.hash.split("/")[1],
// second parameter is "true" to disable caching of collection type
doctype = arangoHelper.collectionApiType(collid, true);
// second parameter is "true" to disable caching of collection type
doctype = arangoHelper.collectionApiType(collid, true);
if (doctype === 'edge') {
//$('#edgeCreateModal').modal('show');
//arangoHelper.fixTooltips(".modalTooltips", "left");
var buttons = [], tableContent = [];
@ -534,6 +532,20 @@
)
);
tableContent.push(
window.modalView.createTextEntry(
'new-edge-key-attr',
'_key',
undefined,
"the edges unique key(optional attribute, leave empty for autogenerated key",
'is optional: leave empty for autogenerated key',
false,
[
{/*optional validation rules for joi*/}
]
)
);
buttons.push(
window.modalView.createSuccessButton('Create', this.addEdge.bind(this))
);
@ -547,22 +559,49 @@
return;
}
else {
var buttons = [], tableContent = [];
var result = this.documentStore.createTypeDocument(collid);
//Success
if (result !== false) {
window.location.hash = "collection/" + result;
return;
tableContent.push(
window.modalView.createTextEntry(
'new-document-key-attr',
'_key',
undefined,
"the documents unique key(optional attribute, leave empty for autogenerated key",
'is optional: leave empty for autogenerated key',
false,
[
{/*optional validation rules for joi*/}
]
)
);
buttons.push(
window.modalView.createSuccessButton('Create', this.addDocument.bind(this))
);
window.modalView.show(
'modalTable.ejs',
'Create document',
buttons,
tableContent
);
}
//Error
arangoHelper.arangoError('Creating document failed');
},
addEdge: function () {
var collid = window.location.hash.split("/")[1];
var from = $('.modal-body #new-edge-from-attr').last().val();
var to = $('.modal-body #new-edge-to').last().val();
var result = this.documentStore.createTypeEdge(collid, from, to);
var key = $('.modal-body #new-edge-key-attr').last().val();
var result;
if (key !== '' || key !== undefined) {
result = this.documentStore.createTypeEdge(collid, from, to, key);
}
else {
result = this.documentStore.createTypeEdge(collid, from, to);
}
if (result !== false) {
//$('#edgeCreateModal').modal('hide');
@ -575,6 +614,26 @@
}
},
addDocument: function() {
var collid = window.location.hash.split("/")[1];
var key = $('.modal-body #new-document-key-attr').last().val();
var result;
if (key !== '' || key !== undefined) {
result = this.documentStore.createTypeDocument(collid, key);
}
else {
result = this.documentStore.createTypeDocument(collid);
}
//Success
if (result !== false) {
window.modalView.hide();
window.location.hash = "collection/" + result;
}
else {
arangoHelper.arangoError('Creating document failed');
}
},
moveSelectedDocs: function() {
var buttons = [], tableContent = [];
var toDelete = this.getSelectedDocs();