diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2012-12-14 16:39:20 +0100 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2013-05-06 16:22:17 +0200 |
commit | 693dc560620d52dc24a0ab89e20147b10ed4f469 (patch) | |
tree | a748bc7a89f76d8ea4cdf1dc1a91895192a7ea56 /install/ui/src/freeipa/app.js | |
parent | a4d9e19c79b60b8f7269141374b2e3b6c0d66c45 (diff) | |
download | freeipa-693dc560620d52dc24a0ab89e20147b10ed4f469.tar.gz freeipa-693dc560620d52dc24a0ab89e20147b10ed4f469.tar.xz freeipa-693dc560620d52dc24a0ab89e20147b10ed4f469.zip |
Menu and application controller refactoring
https://fedorahosted.org/freeipa/ticket/3235
https://fedorahosted.org/freeipa/ticket/3236
Diffstat (limited to 'install/ui/src/freeipa/app.js')
-rw-r--r-- | install/ui/src/freeipa/app.js | 133 |
1 files changed, 57 insertions, 76 deletions
diff --git a/install/ui/src/freeipa/app.js b/install/ui/src/freeipa/app.js index 3dcb10f49..88c8c2bab 100644 --- a/install/ui/src/freeipa/app.js +++ b/install/ui/src/freeipa/app.js @@ -18,12 +18,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -// -// AMD Wrapper for json2 library -// - +/** + * Application wrapper + */ define([ //core + 'dojo/_base/lang', + 'dojo/Deferred', + './phases', + './Application_controller', + 'exports', // for circullar deps './ipa', './jquery', './navigation', @@ -50,78 +54,55 @@ define([ './trust', './user', 'dojo/domReady!' -],function(IPA, $) { - - /* main loop (hashchange event handler) */ - function window_hashchange(evt){ - IPA.nav.update(); - } - - function create_navigation() { - var whoami = IPA.whoami; - var factory; - - - if (whoami.hasOwnProperty('memberof_group') && - whoami.memberof_group.indexOf('admins') !== -1) { - factory = IPA.admin_navigation; - } else if (whoami.hasOwnProperty('memberofindirect_group')&& - whoami.memberofindirect_group.indexOf('admins') !== -1) { - factory = IPA.admin_navigation; - } else if (whoami.hasOwnProperty('memberof_role') && - whoami.memberof_role.length > 0) { - factory = IPA.admin_navigation; - } else if (whoami.hasOwnProperty('memberofindirect_role') && - whoami.memberofindirect_role.length > 0) { - factory = IPA.admin_navigation; - } else { - factory = IPA.self_serv_navigation; - } - - return factory({ - container: $('#navigation'), - content: $('#content') - }); - } - - - function init_on_success(data, text_status, xhr) { - $(window).bind('hashchange', window_hashchange); - - var whoami = IPA.whoami; - IPA.whoami_pkey = whoami.uid[0]; - $('#loggedinas .login').text(whoami.cn[0]); - $('#loggedinas a').fragment( - {'user-facet': 'details', 'user-pkey': IPA.whoami_pkey}, 2); - - $('#logout').click(function() { - IPA.logout(); - return false; - }).text(IPA.messages.login.logout); - - $('.header-loggedinas').css('visibility','visible'); - IPA.update_password_expiration(); - - IPA.nav = create_navigation(); - IPA.nav.create(); - IPA.nav.update(); - - $('#login_header').html(IPA.messages.login.header); - } - +],function(lang, Deferred, phases, Application_controller, exports) { + + var app = { + + /** + * Application instance + */ + app: null, + + /** + * Application class + */ + App_class: Application_controller, + + /** + * Phases registration + */ + register_phases: function() { + + phases.on('app-init', lang.hitch(this, function() { + var app = this.app = new this.App_class(); + app.init(); + return app; + })); + + phases.on('metadata', lang.hitch(this, function() { + var deferred = new Deferred(); + + this.app.get_configuration(function(success) { + deferred.resolve(success); + }, function(error) { + deferred.reject(error); + }); + + return deferred.promise; + })); + + phases.on('profile', lang.hitch(this, function() { + this.app.choose_profile(); + })); + }, + + run: function() { + this.register_phases(); + phases.controller.run(); + } + }; - function init_on_error(xhr, text_status, error_thrown) { - var container = $('#content').empty(); - container.append('<p>Error: '+error_thrown.name+'</p>'); - container.append('<p>'+error_thrown.message+'</p>'); - } + lang.mixin(exports, app); - return { - run: function() { - IPA.init({ - on_success: init_on_success, - on_error: init_on_error - }); - } - }; + return exports; });
\ No newline at end of file |