Last active
August 29, 2015 14:07
-
-
Save mupkoo/9eb13ef72a2f546a2367 to your computer and use it in GitHub Desktop.
Ember Flash messages view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Uncaught TypeError: Cannot read property 'send' of undefined vendor.js:32923 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
var Flash = Ember.ContainerView.extend({ | |
rootElement: null, | |
container: null, | |
classNames: [ 'flash-messages' ], | |
error: function (message) { return this.show(message, 'error'); }, | |
info: function (message) { return this.show(message, 'info'); }, | |
success: function (message) { return this.show(message, 'success'); }, | |
show: function (message, type) { | |
var view = this.createChildView(Message, { | |
message: message, | |
type: type | |
}); | |
return this.pushObject(view); | |
}, | |
init: function () { | |
this._super(); | |
var self = this; | |
var observer = { | |
arrayWillChange: function() { | |
self.appendTo(document.body); | |
self.removeArrayObserver(observer); | |
} | |
}; | |
this.addArrayObserver(observer); | |
} | |
}); | |
var Message = Ember.View.extend({ | |
classNameBindings: [ ':flash-message', 'view.type', ':visible' ], | |
defaultTemplate: Ember.Handlebars.compile('<a class="close" {{ action "close" }}>×</a><p>{{ view.message }}</p>'), | |
actions: { | |
close: function () { | |
var parent = this.get('parentView'); | |
console.log(parent); | |
if (parent) { | |
parent.removeObject(this); | |
} | |
} | |
} | |
}); | |
export default Flash.create(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
ActionHelper.registerAction = function(actionNameOrPath, options, allowedKeys) { | |
var actionId = uuid(); | |
ActionManager.registeredActions[actionId] = { | |
eventName: options.eventName, | |
handler: function handleRegisteredAction(event) { | |
if (!isAllowedEvent(event, allowedKeys)) { return true; } | |
if (options.preventDefault !== false) { | |
event.preventDefault(); | |
} | |
if (options.bubbles === false) { | |
event.stopPropagation(); | |
} | |
var target = options.target; | |
var parameters = options.parameters; | |
var eventName = options.eventName; | |
var actionName; | |
if (target.target) { | |
target = handlebarsGet(target.root, target.target, target.options); | |
} else { | |
target = target.root; | |
} | |
if (options.boundProperty) { | |
actionName = resolveParams(parameters.context, [actionNameOrPath], { types: ['ID'], data: parameters.options.data })[0]; | |
if (typeof actionName === 'undefined' || typeof actionName === 'function') { | |
Ember.deprecate("You specified a quoteless path to the {{action}} helper '" + actionNameOrPath + "' which did not resolve to an actionName. Perhaps you meant to use a quoted actionName? (e.g. {{action '" + actionNameOrPath + "'}})."); | |
actionName = actionNameOrPath; | |
} | |
} | |
if (!actionName) { | |
actionName = actionNameOrPath; | |
} | |
run(function runRegisteredAction() { | |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
// !!! This is where the error is triggered from !!! | |
// !!! `target` is the undefined !!! | |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
if (target.send) { | |
target.send.apply(target, args(parameters, actionName)); | |
} else { | |
Ember.assert("The action '" + actionName + "' did not exist on " + target, typeof target[actionName] === 'function'); | |
target[actionName].apply(target, args(parameters)); | |
} | |
}); | |
} | |
}; | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment