1
0
Fork 0

can hide system collections

This commit is contained in:
Jan Steemann 2013-02-21 09:58:24 +01:00
parent 53b41e7832
commit 935fbf70cd
3 changed files with 66 additions and 27 deletions

View File

@ -1,23 +1,37 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
/*global require, exports */
window.arangoCollections = Backbone.Collection.extend({
url: '/_api/collection',
model: arangoCollection,
comparator : function(model) {
return model.get('name').toLowerCase();
},
url: '/_api/collection',
parse: function(response) {
$.each(response.collections, function(key, val) {
if (val.status == 2) {
val.status = 'unloaded';
}
else if (val.status == 3) {
val.status = 'loaded';
}
});
return response.collections;
isSystemCollection : function (name) {
return name.substr(0, 1) === '_';
},
model: arangoCollection,
translateStatus : function (status) {
if (status == 2) {
return 'unloaded';
}
else if (status == 3) {
return 'loaded';
}
},
parse: function(response) {
var that = this;
$.each(response.collections, function(key, val) {
val.isSystem = that.isSystemCollection(val.name);
val.status = that.translateStatus(val.status);
});
return response.collections;
},
getProperties: function (id) {
var data2;
$.ajax({

View File

@ -1,12 +1,15 @@
window.arangoCollection = Backbone.Model.extend({
initialize: function () {
},
urlRoot: "/_api/collection",
defaults: {
id: "",
name: "",
status: "",
type: "",
isSystem: false,
picture: ""
}
});

View File

@ -1,20 +1,33 @@
var collectionsView = Backbone.View.extend({
el: '#content',
el2: '.thumbnails',
searchPhrase: '',
searchOptions: {
searchPhrase: null,
excludeSystem: false
},
init: function () {
},
template: new EJS({url: '/_admin/html/js/templates/collectionsView.ejs'}),
render: function() {
render: function () {
$(this.el).html(this.template.text);
var searchPhrase = this.searchPhrase.toLowerCase();
var searchPhrase = '';
if (this.searchOptions.searchPhrase !== null) {
searchPhrase = this.searchOptions.searchPhrase.toLowerCase();
}
this.collection.each(function (arango_collection) {
if (searchPhrase !== '' && arango_collection.get('name').toLowerCase().indexOf(searchPhrase) === -1) {
// search phrase entered but current collection does not match?
return;
}
if (this.searchOptions.excludeSystem && arango_collection.get('isSystem')) {
// system collection?
return;
}
@ -33,22 +46,31 @@ var collectionsView = Backbone.View.extend({
"click #searchSubmit" : "restrictToSearchPhrase"
},
restrictToSearchPhraseKey: function(e) {
if (e.keyCode == 13) {
this.searchPhrase = $('#searchInput').val().replace(/(^\s+|\s+$)/g, '');
this.render();
}
},
restrictToSearchPhrase: function() {
var searchPhrase = this.searchPhrase;
this.searchPhrase = $('#searchInput').val().replace(/(^\s+|\s+$)/g, '');
if (searchPhrase === this.searchPhrase) {
search: function () {
var searchPhrase = $('#searchInput').val().replace(/(^\s+|\s+$)/g, '');
if (searchPhrase === this.searchOptions.searchPhrase) {
return;
}
this.searchOptions.searchPhrase = searchPhrase;
this.render();
},
details: function() {
restrictToSearchPhraseKey: function (e) {
// key pressed in search box
if (e.keyCode == 13) {
// return pressed? this triggers the search
this.search();
}
},
restrictToSearchPhrase: function () {
// search executed
this.search();
},
details: function () {
}
});