core.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // REFLECTOR
  3. //
  4. App.Core.action_reflector = {
  5. 'new_entry': App.Actions.newForm,
  6. 'cancel_form': App.Actions.cancelForm,
  7. 'save_form': App.Actions.saveForm,//App.Pages.IP.saveIpForm,
  8. 'remove': App.Actions.remove,//App.Pages.IP.deleteIp,
  9. 'cancel_dns_form': App.Pages.DNS.closeForm,
  10. 'save_dns_form': App.Pages.DNS.saveForm,
  11. 'edit': App.Actions.edit,
  12. 'embed_subform': App.Actions.embedSubform,
  13. 'form_help': App.Actions.showFormHelp,
  14. 'entry_help': App.Actions.showEntryHelp,
  15. 'close_popup': App.View.closePopup
  16. };
  17. //
  18. // CORE
  19. //
  20. App.Core.listen = function(){
  21. fb.log('start listening');
  22. $(document).bind('click', function(evt){
  23. //App.Pages.IP.customListen && App.Pages.IP.customListen(evt);
  24. var elm = $(evt.target);
  25. fb.log(elm);
  26. var action = $(elm).attr('className').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.Core.action_reflector[action]){
  53. return fb.warn('No action registered for: "'+action+'". Stop propagation');
  54. }else{
  55. return App.Core.action_reflector[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. }