0

I am writing a small web app in Google Apps Script. I've split the app up into several tabs, each of which performs a specific task. To facilitate maintainability, I've written a module to control each tab.

I'm having trouble conceptualizing how to bind each module to its appropriate tab. The code below shows how I'm attempting to set up each tab via its module's init script when the 'tabscreate' message is sent.

HTML

<div id="tabs">
  <ul>
    <li><a href="#tab1"/></li>
    <li><a href="#tab2"/></li>
    <li><a href="#tab3"/></li>
  </ul>
</div>

<div id="tab1"><button></div>
<div id="tab2"><button></div>
<div id="tab3"><button></div>

Script:

$(
  $('#tabs').tabs()
);

var tab1 = (function(){
  function init(){
    //...set up tab here
  }
   return {init: init};
}());

//repeat above for each tab

I know I can do...

$('#tab1').on('tabscreate',function(){
  tab1.init();
});

...but I don't want to have to manually create bindings for every function. I want each tab to call its own init function when tabs are created.

I imagine doing something like this:

$('#tabs').on('tabscreate',<call your init function>)

First of all, is my approach to this problem valid? This is my first real web app, and I've had trouble pinning down an approach that fits my needs. I'm open to any suggestions.

Second, if this approach is ok, how can I achieve what I'm describing in the last code snippet above?

Charlie Patton
  • 435
  • 2
  • 12
  • Have you ever thought about the possibility of making it a single page application that changes it's contents on the fly based upon user selection. AngularJS uses the term SPA "Single Page Application" a lot. Whether you use AngularJS or JQuery or both the idea is to hide and display varying sections of the DOM based upon users current needs thus avoiding any unnecessary page refreshes. – Cooper Mar 10 '17 at 16:55
  • 1
    The last comment was too long so here's the rest. It's pretty easy to [communicate with the server](https://developers.google.com/apps-script/guides/html/communication) in GS and you can store any data required in [PropertiesService](https://developers.google.com/apps-script/reference/properties/properties-service) but hey if you want to use tabs go for it but I wouldn't worry to much about forcing it into multiple pages until I figure out what I want to say and how I'm going to say it. – Cooper Mar 10 '17 at 16:55
  • This page that were on right now is a good example of a great single page app. Just think what a nuisance it would be to have to suffer a page refresh every time we added a comment or edited and answer. – Cooper Mar 10 '17 at 17:01
  • Actually, after posting this, I saw the related question [Thinking in angularjs if I have a jquery background](http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background?rq=1), and I think it would be a really good fit for my needs, since the app itself is pretty much entirely client-side, only making occasional server calls. I hate to start over on my project, but it seems like a worthwhile endeavor. – Charlie Patton Mar 10 '17 at 17:04
  • also, it's basically already a single-page app; there are no page-refreshes at all. Interfaces are basically limited to choosing some options from an auto-complete menu or dynamically-created checkbox list and then clicking submit, so there isn't much to update on the view anyway. – Charlie Patton Mar 10 '17 at 17:05
  • 1
    If multiple pages is better that's fine. But I'm just saying to consider the best presentation for the content so that the user experience is the best that it can be. – Cooper Mar 10 '17 at 17:09

0 Answers0