1
0
Fork 0

cleanup + arangoHelper

This commit is contained in:
Heiko Kernbach 2013-02-22 11:33:25 +01:00
parent c9a15b5ad5
commit 205ed128c0
5 changed files with 59 additions and 98 deletions

View File

@ -1,61 +1,60 @@
/*global functions */ arangoHelper = {
systemAttributes: function () {
return {
'_id' : true,
'_rev' : true,
'_key' : true,
'_from' : true,
'_to' : true,
'_bidirectional' : true,
'_vertices' : true,
'_from' : true,
'_to' : true,
'$id' : true
};
},
function systemAttributes () { isSystemAttribute: function (val) {
return { var a = this.systemAttributes();
'_id' : true, return a[val];
'_rev' : true, },
'_key' : true,
'_from' : true,
'_to' : true,
'_bidirectional' : true,
'_vertices' : true,
'_from' : true,
'_to' : true,
'$id' : true
};
}
function isSystemAttribute (val) { isSystemCollection: function (val) {
var a = systemAttributes(); return val && val.name && val.name.substr(0, 1) === '_';
return a[val]; },
}
function isSystemCollection (val) { collectionApiType: function (identifier) {
return val && val.name && val.name.substr(0, 1) === '_'; if (CollectionTypes[identifier] == undefined) {
} CollectionTypes[identifier] = getCollectionInfo(identifier).type;
}
function collectionApiType (identifier) { if (CollectionTypes[identifier] == 3) {
if (CollectionTypes[identifier] == undefined) { return "edge";
CollectionTypes[identifier] = getCollectionInfo(identifier).type; }
return "document";
},
collectionType: function (val) {
if (! val || val.name == '') {
return "-";
}
var type;
if (val.type == 2) {
type = "document";
}
else if (val.type == 3) {
type = "edge";
}
else {
type = "unknown";
}
if (isSystemCollection(val)) {
type += " (system)";
}
return type;
} }
if (CollectionTypes[identifier] == 3) { };
return "edge";
}
return "document";
}
function collectionType (val) {
if (! val || val.name == '') {
return "-";
}
var type;
if (val.type == 2) {
type = "document";
}
else if (val.type == 3) {
type = "edge";
}
else {
type = "unknown";
}
if (isSystemCollection(val)) {
type += " (system)";
}
return type;
}

View File

@ -7,10 +7,6 @@ window.arangoCollections = Backbone.Collection.extend({
return model.get('name').toLowerCase(); return model.get('name').toLowerCase();
}, },
isSystemCollection : function (name) {
return name.substr(0, 1) === '_';
},
translateStatus : function (status) { translateStatus : function (status) {
if (status == 2) { if (status == 2) {
return 'unloaded'; return 'unloaded';
@ -23,7 +19,7 @@ window.arangoCollections = Backbone.Collection.extend({
var that = this; var that = this;
$.each(response.collections, function(key, val) { $.each(response.collections, function(key, val) {
val.isSystem = that.isSystemCollection(val.name); val.isSystem = arangoHelper.isSystemCollection(val.name);
val.status = that.translateStatus(val.status); val.status = that.translateStatus(val.status);
}); });
return response.collections; return response.collections;

View File

@ -26,7 +26,7 @@ window.arangoDocument = Backbone.Collection.extend({
}, },
addDocument: function (collectionID) { addDocument: function (collectionID) {
var self = this; var self = this;
var doctype = self.collectionApiType(collectionID); var doctype = arangoHelper.collectionApiType(collectionID);
if (doctype === 'edge') { if (doctype === 'edge') {
alert("adding edge not implemented"); alert("adding edge not implemented");
return false; return false;
@ -50,16 +50,6 @@ window.arangoDocument = Backbone.Collection.extend({
} }
}); });
}, },
collectionApiType: function (identifier) {
if (this.CollectionTypes[identifier] == undefined) {
this.CollectionTypes[identifier] = this.getCollectionInfo(identifier).type;
}
if (this.CollectionTypes[identifier] == 3) {
return "edge";
}
return "document";
},
getCollectionInfo: function (identifier) { getCollectionInfo: function (identifier) {
var self = this; var self = this;

View File

@ -40,7 +40,7 @@ var documentSourceView = Backbone.View.extend({
var data = arangoDocumentStore.models[0].attributes; var data = arangoDocumentStore.models[0].attributes;
var model = []; var model = [];
$.each(data, function(key, val) { $.each(data, function(key, val) {
if (isSystemAttribute(key) === true) { if (arangoHelper.isSystemAttribute(key) === true) {
delete data[key]; delete data[key];
} }
}); });

View File

@ -39,7 +39,7 @@ var documentView = Backbone.View.extend({
drawTable: function () { drawTable: function () {
var self = this; var self = this;
$.each(window.arangoDocumentStore.models[0].attributes, function(key, value) { $.each(window.arangoDocumentStore.models[0].attributes, function(key, value) {
if (self.isSystemAttribute(key)) { if (arangoHelper.isSystemAttribute(key)) {
$(self.table).dataTable().fnAddData([ $(self.table).dataTable().fnAddData([
key, key,
self.value2html(value, true), self.value2html(value, true),
@ -101,30 +101,6 @@ var documentView = Backbone.View.extend({
}); });
}, },
systemAttributes: function () {
return {
'_id' : true,
'_rev' : true,
'_key' : true,
'_from' : true,
'_to' : true,
'_bidirectional' : true,
'_vertices' : true,
'_from' : true,
'_to' : true,
'$id' : true
};
},
isSystemAttribute: function (val) {
var a = this.systemAttributes();
return a[val];
},
isSystemCollection: function (val) {
return val && val.name && val.name.substr(0, 1) === '_';
},
value2html: function (value, isReadOnly) { value2html: function (value, isReadOnly) {
var self = this; var self = this;
var typify = function (value) { var typify = function (value) {
@ -172,7 +148,7 @@ var documentView = Backbone.View.extend({
$(this).removeClass('writeable'); $(this).removeClass('writeable');
i = 0; i = 0;
} }
if (self.isSystemAttribute(this.innerHTML)) { if (arangoHelper.isSystemAttribute(this.innerHTML)) {
$(this).removeClass('writeable'); $(this).removeClass('writeable');
i = 1; i = 1;
} }