core.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*App.Core.action_reflector = {
  2. 'new_entry': App.Actions.newForm,
  3. 'cancel_form': App.Actions.cancelForm,
  4. 'save_form': App.Actions.saveForm,//App.Pages.IP.saveIpForm,
  5. 'remove': App.Actions.remove,//App.Pages.IP.deleteIp,
  6. 'cancel_dns_form': App.Pages.DNS.closeForm,
  7. 'save_dns_form': App.Pages.DNS.saveForm,
  8. 'edit': App.Actions.edit,
  9. 'embed_subform': App.Actions.embedSubform,
  10. 'form_help': App.Actions.showFormHelp,
  11. 'entry_help': App.Actions.showEntryHelp,
  12. 'close_popup': App.View.closePopup
  13. };*/
  14. //
  15. // CORE
  16. //
  17. App.Core.listen = function(){
  18. fb.log('start listening');
  19. $(document).bind('click', function(evt){
  20. //App.Pages.IP.customListen && App.Pages.IP.customListen(evt);
  21. var elm = $(evt.target);
  22. var action = $(elm).attr('class');
  23. if (!action) {
  24. return fb.log(':)');
  25. }
  26. action = action.split('do_action_');
  27. if(action.length < 2){
  28. if (elm.hasClass('check-this')) {
  29. var ref = $(elm).parents('.row');
  30. ref.hasClass('checked-row') ? ref.removeClass('checked-row') : ref.addClass('checked-row');
  31. }
  32. return; // no action found attached to the dom object
  33. }
  34. try{
  35. // retrieve the action itself
  36. action_with_params = action[1].split(' ');
  37. action = action_with_params[0];
  38. params = elm.find('.prm-'+action).value || null;
  39. // TODO: filter params here
  40. // Call the action
  41. App.Core.__CALL__(evt, action, params);
  42. }catch(e){
  43. fb.error(e)
  44. }
  45. });
  46. }
  47. /**
  48. * Action caller
  49. * if no action registered, execution will stop
  50. */
  51. App.Core.__CALL__ = function(evt, action, params){
  52. if('undefined' == typeof App.Actions[action]){
  53. return fb.warn('No action registered for: "'+action+'". Stop propagation');
  54. }else{
  55. return App.Actions[action](evt, params);
  56. }
  57. }
  58. App.Core.initMenu = function(){
  59. $('.section').bind('click', function(evt){
  60. var elm = $(evt.target);
  61. !elm.hasClass('section') ? elm = elm.parents('.section') : -1;
  62. if(App.Env.world != elm.attr('id')){
  63. App.Env.world = elm.attr('id');
  64. App.Pages.init();
  65. fb.warn('Switch page to: ' + App.Env.world);
  66. }
  67. });
  68. }