Created
September 7, 2012 12:38
-
-
Save dervalp/3665890 to your computer and use it in GitHub Desktop.
Feedback
This file contains hidden or 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
| define([ | |
| "app" | |
| // Modules | |
| // Plugins | |
| ], | |
| /* | |
| Questions ? | |
| - Do we need to add the div#flash in the page or do we add it if is not present on the first notification? (like lazy initialization) | |
| - Do we allowed our user to close the error message ? Some UX rules say that you cannot close an error or a warning, but you can close information, | |
| I think we should follow that idea. | |
| */ | |
| /* | |
| This module should be responsible for all the notifications of your app. | |
| Currently, we planned to support two types of notification, local (which means that it will notify the user inside a specific div) | |
| or general notification (which means, it will notify somewhere near the body element) | |
| In the future, we planned to develop some more complex notification, like a windows appearing in the bottom righ of your page, of that kind of stuff | |
| This module needs to be decoupld and written in pure javascript. That why you will see some HTML in variable and not using templates and so on. | |
| */ | |
| function(app) { | |
| // Create a new module | |
| var Feedback = app.module(), | |
| _notificationTemplate = '<div id="flash" class="alert alert-error"></div>', | |
| _defaultClass = "alert", /*this is a warning by default*/ | |
| _errorClass = "alert-error", /*in fact I am using the twitter bootstrap class*/ | |
| _successClass = "alert-success", | |
| _infoClass = "alert-info", | |
| _state = {} ; /*state will be an internal object used to keep track of all the active notifications*/ | |
| /* | |
| First public function to be exposed, this function will render notifications | |
| { | |
| el: "#el_you_want_to_look_for_the_flash_duv" | |
| type: "warning|error|notification" | |
| message: "The message you want to be displayed by your app" | |
| } | |
| the feedback takes only charge about notifying the users, this is not the place where you can redirect, reload or anything | |
| */ | |
| Feedback.flash = function(data){ | |
| console.log("I should flash"); | |
| if(!el) { | |
| console.log("no el defined, default behavior"); | |
| /*we look for a flash somewhere in the body element*/ | |
| /*we clean it and insert the right things in it*/ | |
| var mainFlash = $("#flash").empty().html(); | |
| } | |
| $("#flash").html("Please correct the highlighted fields before submiting"); | |
| }; | |
| // Required, return the module for AMD compliance | |
| return Feedback; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about having the feedback container on a baseview used by the whole backbone app (like index.htm or something). Presumably there's a default html frame that our views are populated into?