Skip to content

Commit

Permalink
[view][s]: create a CKAN.View.flash method for doing message flashing…
Browse files Browse the repository at this point in the history
… and convert from existing trigger method to this.
  • Loading branch information
rgrp committed Aug 13, 2011
1 parent f341c5d commit be5beea
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/view.js
Expand Up @@ -4,6 +4,17 @@ CKAN.View = function($) {
var my = {};
var showdown = new Showdown.converter();

// Flash a notification message
//
// Parameters: msg, type. type is set as class on notification and should be one of success, error.
// If type not defined defaults to success
my.flash = function(msg, type) {
if (type === undefined) {
var type = 'success'
}
$.event.trigger('notification', [msg, type]);
};

my.NotificationView = Backbone.View.extend({
initialize: function() {
$.template('notificationTemplate',
Expand Down Expand Up @@ -48,7 +59,7 @@ CKAN.View = function($) {
updateConfig: function(e) {
e.preventDefault();
this.saveConfig();
$.event.trigger('notification', ['Saved configuration', 'success']);
CKAN.View.flash('Saved configuration');
},

saveConfig: function() {
Expand Down Expand Up @@ -96,7 +107,7 @@ CKAN.View = function($) {
this.model.set(this.getData());
this.model.save({}, {
success: function(model) {
$.event.trigger('notification', ['Saved dataset', 'success']);
CKAN.View.flash('Saved dataset');
window.location.hash = '#dataset/' + model.id + '/view';
}
});
Expand Down

0 comments on commit be5beea

Please sign in to comment.