Skip to content

Commit

Permalink
Merge pull request #118 from OnroerendErfgoed/#92_ui_error_handling
Browse files Browse the repository at this point in the history
#92 ui error handling
  • Loading branch information
Cedrik Vanderhaegen committed Dec 16, 2014
2 parents 8f66794 + 8399955 commit 8893c5b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ atramhasis/static/admin/src/util/
atramhasis/static/admin/src/dojo/
atramhasis/static/admin/src/dojox/
atramhasis/static/admin/src/dijit/
atramhasis/static/admin/src/dGrowl/
atramhasis/static/admin/src/dgrid/
atramhasis/static/admin/src/put-selector/
atramhasis/static/admin/src/xstyle/
Expand Down
5 changes: 3 additions & 2 deletions atramhasis/static/admin/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"util": "dojo-util#~1.10.0",
"put-selector": "~0.3.5",
"xstyle": "~0.2.1",
"dgrid": "~0.3.15"
"dgrid": "~0.3.15",
"dGrowl": "~0.0.0"
}
}
}
46 changes: 36 additions & 10 deletions atramhasis/static/admin/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define([
"dojo/store/Memory",
"dojo/dom",
"dojo/request",
"dojo/json",
"dijit/registry",
"dijit/form/FilteringSelect",
"dijit/MenuItem",
Expand All @@ -24,22 +25,24 @@ define([
"./ConceptForm",
"./ExternalSchemeService",
"./ExternalSchemeForm",
"dGrowl",
"dijit/layout/ContentPane",
"dijit/layout/TabContainer",
"dijit/layout/BorderContainer"


], function (declare, on, topic, aspect, lang, Memory, dom, request, registry, FilteringSelect, MenuItem,
], 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, ContentPane, TabContainer) {
ExternalSchemeForm, dGrowl, ContentPane, TabContainer) {
return declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {

templateString: template,
thesauri: null,
currentScheme: null,
externalSchemeService: null,
externalSchemeForm: null,
notificationController: null,

postMixInProperties: function () {
this.inherited(arguments);
Expand All @@ -57,6 +60,14 @@ define([
this.inherited(arguments);
console.log('postCreate', arguments);
this.thesauri = new ThesaurusCollection();

this.notificationController = new dGrowl({
'channels':[
{'name':'info','pos':3},
{'name':'error', 'pos':1},
{'name':'warn', 'pos':2}
]
});
},

startup: function () {
Expand Down Expand Up @@ -308,7 +319,8 @@ define([
function () {
console.log("row edited");
conceptDialog.hide();
alert("The concept or collection has been saved");
var message = "The " + rowToAdd.type + " has been saved";
topic.publish('dGrowl', message, {'title': "Success", 'sticky': false, 'channel':'info'});
filteredGrid.conceptGrid.refresh();

//refresh Concept Detail widget.
Expand All @@ -317,29 +329,28 @@ define([
});
},
function (error) {
console.log("An error occurred: " + error);
alert("Can't add the concept or collection to the database. Please check if business rules are respected");
self._handleSaveErrors(error);
}
);
}
else {
filteredGrid.conceptGrid.store.add(rowToAdd)
.then(
function () {
console.log("row added");
conceptDialog.hide();
alert("The concept or collection has been added to the thesaurus");

var message = "The " + rowToAdd.type + " has been saved";
topic.publish('dGrowl', message, {'title': "Success", 'sticky': false, 'channel':'info'});
filteredGrid.conceptGrid.refresh();
},
function (error) {
console.log("An error occurred: " + error);
alert("Can't add the concept or collection to the database. Please check if business rules are respected");
self._handleSaveErrors(error);
}
);
}
});

this.notificationController.addNotification("Atramhasis is up and running",{'channel':'info'});

},

_createConcept: function (conceptForm, conceptDialog, Scheme) {
Expand All @@ -366,6 +377,21 @@ define([
}, function(err){
console.error(err);
});
},

_handleSaveErrors: function(error) {
var errorJson = JSON.parse(error.responseText);
var message = "";
array.forEach(errorJson.errors, function (errorObj) {
for (prop in errorObj) {
message += "-<em>";
message += prop;
message += "</em>: ";
message += errorObj[prop];
message += "<br>";
}
});
topic.publish('dGrowl', message, {'title': errorJson.message, 'sticky': true, 'channel':'error'});
}


Expand Down
10 changes: 0 additions & 10 deletions atramhasis/static/admin/src/app/ConceptForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ define(
console.log(formObj);
topic.publish("conceptform.submit", formObj);
}
this.show({
spinnerNode: true,
formNode: false,
successNode: false
});
this.dialog && this.dialog.layout();

return false;
Expand Down Expand Up @@ -229,11 +224,6 @@ define(
this.matchesManager.setMatchUris(concept.matches);
}
}
this.show({
spinnerNode: false,
formNode: true,
successNode: false
});
this.dialog && this.dialog.layout();
},
addBroader: function (broader) {
Expand Down
7 changes: 7 additions & 0 deletions atramhasis/static/admin/src/app/resources/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import '../../dijit/themes/claro/claro.css';
@import '../../dgrid/css/dgrid.css';
@import '../../dgrid/css/skins/claro.css';
@import '../../dGrowl/dGrowl.css';

@import 'FilteredGrid.css';
@import 'ConceptForm.css';
Expand Down Expand Up @@ -66,3 +67,9 @@ html, body {
width: 11px;
height: 11px;
}

.dGrowl-channel-warn .dGrowl-notification {
background-color: rgb(250, 217, 95);
border: 1px solid #b97422;
}

3 changes: 2 additions & 1 deletion atramhasis/static/admin/src/dojoConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var dojoConfig = {
'put-selector',
'xstyle',
'dgrid',
'app'
'app',
'dGrowl'
]
};

0 comments on commit 8893c5b

Please sign in to comment.