Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/0.4.0' into DatabaseInte…
Browse files Browse the repository at this point in the history
…grity
  • Loading branch information
BartSaelen committed Dec 18, 2014
2 parents c38ec1e + 4ccaf22 commit 74a220e
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 55 deletions.
32 changes: 29 additions & 3 deletions atramhasis/static/admin/src/app/App.js
Expand Up @@ -25,6 +25,7 @@ define([
"./ConceptForm",
"./ExternalSchemeService",
"./ExternalSchemeForm",
"./LanguageManager",
"dGrowl",
"dijit/layout/ContentPane",
"dijit/layout/TabContainer",
Expand All @@ -34,7 +35,7 @@ define([
], function (declare, on, topic, aspect, lang, Memory, dom, request, JSON, registry, FilteringSelect, MenuItem,
_Widget, _TemplatedMixin, _WidgetsInTemplateMixin, template, array, ComboBox, Button, Dialog,
FilteredGrid, ConceptDetail, ThesaurusCollection, ConceptForm, ExternalSchemeService,
ExternalSchemeForm, dGrowl, ContentPane, TabContainer) {
ExternalSchemeForm, LanguageManager, dGrowl, ContentPane, TabContainer) {
return declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {

templateString: template,
Expand All @@ -43,6 +44,7 @@ define([
externalSchemeService: null,
externalSchemeForm: null,
notificationController: null,
languageManager: null,

postMixInProperties: function () {
this.inherited(arguments);
Expand Down Expand Up @@ -79,6 +81,8 @@ define([
thesauri: this.thesauri
});

this.languageManager = new LanguageManager({});

var schemeFileteringSelect = new FilteringSelect({
id: "schemeSelect",
name: "scheme",
Expand All @@ -99,8 +103,8 @@ define([

var conceptForm = new ConceptForm({
thesauri: this.thesauri,
externalSchemeService: this.externalSchemeService

externalSchemeService: this.externalSchemeService,
languageStore: this.languageManager.languageStore
});
var conceptDialog = new Dialog({
id: 'conceptDialog',
Expand Down Expand Up @@ -158,6 +162,11 @@ define([
self.externalSchemeForm.showDialog();
});

var manageLanguagesButton = new Button ({
label: "Manage languages"
}, "languageConceptNode");
this._setupLanguageManager(manageLanguagesButton);

this.externalSchemeForm = new ExternalSchemeForm({
externalSchemeService: this.externalSchemeService
});
Expand Down Expand Up @@ -392,6 +401,23 @@ define([
}
});
topic.publish('dGrowl', message, {'title': errorJson.message, 'sticky': true, 'channel':'error'});
},

_setupLanguageManager: function (button) {
var languageManager = this.languageManager;
languageManager.startup();

on(button, "click", function () {
languageManager.showDialog();
});

on(languageManager, 'change', function (evt) {
topic.publish('dGrowl', evt.message, {'title': evt.title, 'sticky': false, 'channel':'info'});
});
on(languageManager, 'error', function (evt) {
topic.publish('dGrowl', evt.message, {'title': evt.title, 'sticky': true, 'channel':'error'});
});

}


Expand Down
11 changes: 8 additions & 3 deletions atramhasis/static/admin/src/app/ConceptForm.js
Expand Up @@ -36,6 +36,7 @@ define(
conceptId: null,
thesauri: null,
externalSchemeService: null,
languageStore: null,

constructor: function (options) {
declare.safeMixin(this, options);
Expand All @@ -44,10 +45,12 @@ define(
postCreate: function () {
this.inherited(arguments);
this.labelManager = new LabelManager({
'name': 'lblMgr'
'name': 'lblMgr',
'languageStore': this.languageStore
}, this.labelContainerNode);
this.noteManager = new NoteManager({
'name': 'noteMgr'
'name': 'noteMgr',
'languageStore': this.languageStore
}, this.noteContainerNode);
this.broaderManager = new RelationManager({
'name': 'broaderMgr',
Expand Down Expand Up @@ -149,7 +152,9 @@ define(
formObj.member_of = this.memberofManager.getRelations();
formObj.label = this.labelManager.getLabels();
formObj.note = this.noteManager.geNotes();
formObj.matches = this.matchesManager.getMatches();
if (this.matchesManager.getMatches()){
formObj.matches = this.matchesManager.getMatches();
}
console.log(formObj);
topic.publish("conceptform.submit", formObj);
}
Expand Down
211 changes: 211 additions & 0 deletions atramhasis/static/admin/src/app/LanguageManager.js
@@ -0,0 +1,211 @@
define([
'dijit/_WidgetBase',
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/_base/array',
'dojo/dom-construct',
'dojo/on',
'dojo/when',
'dojo/Evented',
'dojo/json',
'dojo/store/Memory',
'dojo/store/JsonRest',
'dojo/store/Cache',
'dojo/store/Observable',
'dijit/Dialog',
'dijit/form/Button',
'dijit/form/TextBox',
'dgrid/OnDemandGrid',
'dgrid/Keyboard',
'dgrid/Selection',
'dgrid/extensions/DijitRegistry'
], function (WidgetBase, declare, lang, array, domConstruct, on, when, Evented, JSON,
Memory, JsonRest, Cache, Observable,
Dialog, Button, TextBox,
OnDemandGrid, dgridKeyboard, dgridSelection, DijitRegistry
) {
return declare([WidgetBase, Evented], {

languageStore: null,

_languageDialog: null,

_languageName: null,

_languageCode: null,

_languageGrid: null,

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

this.languageStore = Observable( Cache( JsonRest({
'target': '/languages',
'idProperty': 'id',
'accepts': 'application/json'
}), Memory()));
},

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

showDialog: function () {
if (this._languageDialog == null) {
this._languageDialog = this._createDialog();
}
this._languageDialog.show();
},

_createDialog: function () {

var langStore = this.languageStore;
var dlg = new Dialog({
'class': "externalForm",
'title': "Manage languages",
'style': "width: 500px"
});

var addGridContainer = domConstruct.create("fieldset", {}, dlg.containerNode);

domConstruct.create("legend", {
innerHTML: "Add a language:"
}, addGridContainer);

var langCode = new TextBox({
name: "langCode",
placeHolder: "code"
}).placeAt(addGridContainer);
this._languageCode = langCode;

var langName = new TextBox({
name: "langName",
placeHolder: "name"
}).placeAt(addGridContainer);
this._languageName = langName;

var addBtn = new Button({
"label": "Add"
}).placeAt(addGridContainer);

addBtn.onClick = lang.hitch(this, function () {
var name = langName.get("value");
var code = langCode.get("value");
if (name.trim().length > 0 && code.trim().length) {
this._addLanguage(name, code);
}
this.reset();
});

domConstruct.create("div", {
innerHTML: "<p>You can use <a href='http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry' target='_blank'>this</a> list as a reference.</p>"
}, dlg.containerNode);

var gridDiv = domConstruct.create("div", {}, dlg.containerNode);
var grid = this._createLangGrid(langStore, gridDiv);
this._languageGrid = grid;

var actionBar = domConstruct.create("div", {
'class': "dijitDialogPaneActionBar"
}, dlg.containerNode);

var deleteBtn = new Button({
"label": "Delete language"
}).placeAt(actionBar);

deleteBtn.onClick = lang.hitch(this, function () {
for(var id in grid.selection){
if(grid.selection[id]){
if (confirm("Are you sure you want to delete '" + id + "'?")) {
this._deleteLanguage(id);
}
}
}
});

new Button({
label: "Close",
onClick: function () {
dlg.hide();
}
}).placeAt(actionBar);

on(dlg, "hide", lang.hitch(this, function () {
this.reset();
}));

return dlg;
},

_createLangGrid: function (store, node) {
return new (declare([OnDemandGrid, dgridKeyboard, dgridSelection, DijitRegistry]))({
sort: "id",
columns: [
{label:'Id', field:'id', sortable: false},
{label:'Name', field:'name', sortable: false}
],
store: store,
getBeforePut: false,
selectionMode: "single"
}, node);
},

_addLanguage: function (name, id) {
var self = this;
when(this.languageStore.add({name : name, id : id})).then(
function (lang) {
var message = 'New language added: ' + lang.name;
self._handleChange(message);
},
function (error) {
self._handleError(error);
}
);
},

_deleteLanguage: function (id) {
var self = this;
when(this.languageStore.remove(id)).then(
function () {
var message = 'Language removed: ' + id;
self._handleChange(message);
},
function (error) {
self._handleError(error);
}
);
},

_handleError: function (error) {
var errorObj = JSON.parse(error.responseText);
var message = "";
array.forEach(errorObj.errors, function (errorObj) {
for (prop in errorObj) {
message += "-<em>";
message += prop;
message += "</em>: ";
message += errorObj[prop];
message += "<br>";
}
});

this.emit('error', {
'title': errorObj.message,
'message': message
});
},

_handleChange: function (message) {
this.emit('change', {
'title': 'Languages',
'message': message
});
},

reset: function () {
this._languageName.reset();
this._languageCode.reset();
this._languageGrid.clearSelection();
}
});
});
33 changes: 9 additions & 24 deletions atramhasis/static/admin/src/app/form/LabelManager.js
Expand Up @@ -37,6 +37,7 @@ define([
labels: null,
tempLabels: null,//this variable is used to recover the labels if user delete a label and then press on the cancel button
EditLabelButton: null,
languageStore: null,

buildRendering: function () {
this.inherited(arguments);
Expand Down Expand Up @@ -97,20 +98,15 @@ define([
style: { width: '120px' }

});
var languages = this._getLanguages();
self.prefLanguage = languages;
var langStoreComboBox = new Select
(
{
id: "langStoreComboBox",
name: "langStoreComboBox",
title: "Language:",
placeHolder: 'Select a language',
options: languages,
style: { width: '80px' }

}
);
var langStoreComboBox = new Select({
id: "langStoreComboBox",
name: "langStoreComboBox",
title: "Language:",
store: this.languageStore,
style: { width: '80px' },
labelAttr: "name"
});

var addLabelButtonToTable = new Button
(
Expand Down Expand Up @@ -206,17 +202,6 @@ define([
return Type;
},

_getLanguages: function () {
var languages = [
{label: "NL", value: "nl", disabled: false},
{label: "FR", value: "fr", disabled: false},
{label: "EN", value: "en", disabled: false}

];

return languages;

},
_createGrid: function (gridDiv) {
var self = this;
var columns;
Expand Down

0 comments on commit 74a220e

Please sign in to comment.