Skip to content

Commit

Permalink
use observable store in filteredgrid and clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanderhaegen Cedrik committed Feb 11, 2015
1 parent 10fd970 commit 8b28451
Showing 1 changed file with 16 additions and 43 deletions.
59 changes: 16 additions & 43 deletions atramhasis/static/admin/src/app/FilteredGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ define([
"dijit/Menu",
"dijit/MenuItem",
"dijit/ConfirmDialog",
"dojo/store/Memory", "dojo/store/Cache",
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dojo/store/Observable",
"dgrid/OnDemandGrid", "dgrid/Selection", "dgrid/Keyboard", "dgrid/editor"

], function (declare, on, topic, lang, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, template, ComboBox, TextBox, Button, Menu, MenuItem, ConfirmDialog, Memory, Cache, OnDemandGrid, Selection, Keyboard, editor) {
], function (declare, on, topic, lang, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, template, ComboBox,
TextBox, Button, Menu, MenuItem, ConfirmDialog, JsonRest, Memory, Cache, Observable,
OnDemandGrid, Selection, Keyboard, editor) {
return declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template,

Expand All @@ -32,14 +37,6 @@ define([
conceptFilter: {label: "", type: "all"},
isResettingFilters: true,

postMixInProperties: function () {
this.inherited(arguments);
},

buildRendering: function () {
this.inherited(arguments);
},

postCreate: function () {
this.inherited(arguments);

Expand All @@ -54,8 +51,6 @@ define([
startup: function () {
this.inherited(arguments);
var self = this;
console.log("startup grid");

var timeoutId;

this.typeCombo = new ComboBox({
Expand All @@ -73,8 +68,6 @@ define([
intermediateChanges: true
}, "filterNode");

var self = this;

var columns = [
{label: "ID", field: "id"},
{label: "label", field: "label"},
Expand All @@ -89,41 +82,32 @@ define([
selectionMode: "single",
minRowsPerPage: 20,
maxRowsPerPage: 100

}, "gridNode");

on(this.conceptGrid, "dgrid-select", lang.hitch(this, function (evt) {
var row = evt.rows[0];
row.scheme = this.conceptScheme;
console.log("row selected: " + row.id);
topic.publish("concept.open", row.id, row.scheme);
}));

this.conceptGrid.on(".dgrid-row:contextmenu", function (evt) {
evt.preventDefault();


var cell = self.conceptGrid.cell(evt);
var gridId = self.conceptGrid.get("id");
var pMenu = self._createGridContextMenu(gridId, cell.element, self, cell.row.data.id, cell.row.data.type, cell.row.data.label);
var args = {target: pMenu.selector};
pMenu._openMyself(args);

}
);


on(this.typeCombo, "change", lang.hitch(this, function (evt) {
if (evt != "") {
console.log("on ", evt);
this._setTypeFilter(evt);
}

}));

this.textFilter.watch("value", (lang.hitch(this, function (name, oldValue, newValue) {
if (this.isResettingFilters) return false;
console.log("typing text: " + newValue);
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
Expand All @@ -136,7 +120,6 @@ define([
},

_resetFilters: function () {
console.log("grid _reset");
this.isResettingFilters = true;
this.typeCombo.reset();
this.textFilter.reset();
Expand All @@ -145,33 +128,30 @@ define([
},

setScheme: function (schemeid) {
console.log("grid setScheme: " + schemeid);
this._resetFilters();
this.conceptScheme = schemeid;
this.conceptStore = Cache(dojo.store.JsonRest({
target: "/conceptschemes/" + schemeid + "/c",
sortParam: "sort"
}), Memory());
this.conceptStore = new Observable( Cache( JsonRest({
'target': "/conceptschemes/" + schemeid + "/c",
'idProperty': 'id',
'sortParam': 'sort',
'accepts': 'application/json'
}), Memory()));
this.conceptGrid.set("store", this.conceptStore, this.conceptFilter);
},

ResetConceptGrid: function () {
this._resetFilters();

this.conceptStore = null;
this.conceptGrid.set("store", this.conceptStore, this.conceptFilter);

},


_setTypeFilter: function (type) {
console.log("setting type filter: " + type);
this.conceptFilter = {label: this.conceptFilter.label, type: type};
this.conceptGrid.set("query", this.conceptFilter);
},

_setTextFilter: function (label) {
console.log("setting label filter: " + label);
this.conceptFilter = {label: label, type: this.conceptFilter.type};
this.conceptGrid.set("query", this.conceptFilter);
},
Expand Down Expand Up @@ -200,22 +180,22 @@ define([
widget._addMemberOf(conceptId, type, label);
}
}));

}


pMenu.addChild(new MenuItem({
label: "Edit",
onClick: function () {
widget._editConcept(conceptId);
}
}));

pMenu.addChild(new MenuItem({
label: "Delete",
onClick: function () {
widget._deleteConcept(conceptId, type, label);
}
}));

pMenu.addChild(new dijit.MenuSeparator());
pMenu.addChild(new MenuItem({
label: "Add a new Concept or collection",
Expand All @@ -224,34 +204,27 @@ define([
}
}));


pMenu.startup();
return pMenu;
var args = {target: pMenu.selector};
pMenu._openMyself(args);


return pMenu;
},


_addNarrower: function (conceptId, type, label) {

topic.publish("concept.addNarrower", conceptId, type, label);

},

_addMemberOf: function (conceptId, type, label) {
topic.publish("concept.addMemberOf", conceptId, type, label);

},

_editConcept: function (conceptId) {
topic.publish("concept.edit", conceptId);

},

_createNewConcept: function () {

topic.publish("concept.create");
},

Expand Down

0 comments on commit 8b28451

Please sign in to comment.