modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl
author Harpreet Singh <harpreet@openbravo.com>
Fri, 10 Dec 2010 19:47:45 +0100
changeset 9076 c4f1a5c7d7c2
child 9560 0450f09b11f2
permissions -rw-r--r--
Added 3.0 modules to modules dir and changed the VERSION number
harpreet@9076
     1
/*
harpreet@9076
     2
 *************************************************************************
harpreet@9076
     3
 * The contents of this file are subject to the Openbravo  Public  License
harpreet@9076
     4
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
harpreet@9076
     5
 * Version 1.1  with a permitted attribution clause; you may not  use this
harpreet@9076
     6
 * file except in compliance with the License. You  may  obtain  a copy of
harpreet@9076
     7
 * the License at http://www.openbravo.com/legal/license.html
harpreet@9076
     8
 * Software distributed under the License  is  distributed  on  an "AS IS"
harpreet@9076
     9
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
harpreet@9076
    10
 * License for the specific  language  governing  rights  and  limitations
harpreet@9076
    11
 * under the License.
harpreet@9076
    12
 * The Original Code is Openbravo ERP.
harpreet@9076
    13
 * The Initial Developer of the Original Code is Openbravo SLU
harpreet@9076
    14
 * All portions are Copyright (C) 2010 Openbravo SLU
harpreet@9076
    15
 * All Rights Reserved.
harpreet@9076
    16
 * Contributor(s):  ______________________________________.
harpreet@9076
    17
 ************************************************************************
harpreet@9076
    18
*/
harpreet@9076
    19
harpreet@9076
    20
// make sure that the layout is loaded in the parent window if we accidentally end up
harpreet@9076
    21
// in a child frame
harpreet@9076
    22
try {
harpreet@9076
    23
  if (window.parent && window.parent.OB && window.parent.OB.Layout) {
harpreet@9076
    24
    isc.Log.logDebug("Reloading in parent frame", "OB");
harpreet@9076
    25
    window.parent.location.href=window.location.href;
harpreet@9076
    26
  } else if (window.parent.parent && window.parent.parent.OB && window.parent.parent.OB.Layout) {
harpreet@9076
    27
    isc.Log.logDebug("Reloading in parent.parent frame", "OB");
harpreet@9076
    28
    window.parent.parent.location.href=window.location.href;
harpreet@9076
    29
  } else {
harpreet@9076
    30
    isc.Log.logDebug("loading in own frame", "OB");
harpreet@9076
    31
  }
harpreet@9076
    32
} catch(e) {
harpreet@9076
    33
    // ignoring on purpose
harpreet@9076
    34
    isc.Log.logDebug("Error when checking parent frame: " + e.message, "OB");
harpreet@9076
    35
}
harpreet@9076
    36
harpreet@9076
    37
// needed for backward compatibility... to open the registration form
harpreet@9076
    38
function openRegistration() {
harpreet@9076
    39
  OB.Utilities.openProcessPopup(OB.Application.contextUrl + '/ad_forms/Registration.html', true);
harpreet@9076
    40
}
harpreet@9076
    41
harpreet@9076
    42
isc.Canvas.addClassProperties({neverUsePNGWorkaround:true});
harpreet@9076
    43
isc.Canvas.loadingImageSrc = '[SKINIMG]../../org.openbravo.client.application/images/system/windowLoading.gif';
harpreet@9076
    44
isc.Canvas.loadingImageSize = 70;
harpreet@9076
    45
harpreet@9076
    46
OB.KeyboardManager.KS.readRegisteredKSList('OBUIAPP_KeyboardShortcuts');
harpreet@9076
    47
OB.KeyboardManager.KS.readRegisteredKSList('UINAVBA_KeyboardShortcuts');
harpreet@9076
    48
harpreet@9076
    49
// should be moved to client.kernel component
harpreet@9076
    50
// placed here to prevent dependencies of client.kernel on Preferences
harpreet@9076
    51
OB.Application.startPage = '${data.startPage}';
harpreet@9076
    52
harpreet@9076
    53
isc.defineClass("OBTabHeaderButton", "StretchImgButton").addProperties({
harpreet@9076
    54
    src: '',
harpreet@9076
    55
    showSelectedIcon: true,
harpreet@9076
    56
    showRollOverIcon: true
harpreet@9076
    57
}, OB.MainLayoutStylingProperties.OBTabHeaderButton);
harpreet@9076
    58
harpreet@9076
    59
// the OB.Layout contains everything
harpreet@9076
    60
OB.Layout = isc.VLayout.create({
harpreet@9076
    61
  width: '100%',
harpreet@9076
    62
  height: '100%',
harpreet@9076
    63
  overflow: 'auto'
harpreet@9076
    64
});
harpreet@9076
    65
harpreet@9076
    66
// create the bar with navigation components
harpreet@9076
    67
OB.Toolbar = isc.ToolStrip.create({  
harpreet@9076
    68
  addMembers: function(members) {
harpreet@9076
    69
    // encapsulate the members
harpreet@9076
    70
    var newMembers = [];
harpreet@9076
    71
    for (var i = 0; i < members.length; i++) {
harpreet@9076
    72
        // encapsulate in 2 hlayouts to handle correct mouse over/hover and show of box
harpreet@9076
    73
        var newMember = isc.HLayout.create({layoutLeftMargin: 10, layoutRightMargin: 10, width: '100%', height: '100%', styleName: 'OBNavBarComponent', members:[members[i]]}); 
harpreet@9076
    74
        newMembers[i] = newMember;
harpreet@9076
    75
    }    
harpreet@9076
    76
    // note the array has to be placed in an array otherwise the newMembers
harpreet@9076
    77
    // is considered to the argument list
harpreet@9076
    78
    this.Super('addMembers', [newMembers]);
harpreet@9076
    79
  }
harpreet@9076
    80
}, OB.MainLayoutStylingProperties.Toolbar);
harpreet@9076
    81
harpreet@9076
    82
// the TopLayout has the navigation bar on the left and the logo on the right
harpreet@9076
    83
OB.TopLayout = isc.HLayout.create({}, OB.MainLayoutStylingProperties.TopLayout);
harpreet@9076
    84
    
harpreet@9076
    85
// create the navbar on the left and the logo on the right
harpreet@9076
    86
OB.TopLayout.CompanyImageLogo = isc.Img.create({
harpreet@9076
    87
  imageType: 'normal'
harpreet@9076
    88
}, OB.MainLayoutStylingProperties.CompanyImageLogo);
harpreet@9076
    89
    
harpreet@9076
    90
OB.TopLayout.addMember(OB.Toolbar);
harpreet@9076
    91
OB.TopLayout.addMember(
harpreet@9076
    92
        isc.HLayout.create({
harpreet@9076
    93
            width: '100%',
harpreet@9076
    94
            align: 'right',
harpreet@9076
    95
            layoutRightMargin: 10,
harpreet@9076
    96
            membersMargin: 10,
harpreet@9076
    97
            defaultLayoutAlign: 'center',
harpreet@9076
    98
            members: [OB.TopLayout.CompanyImageLogo, isc.Img.create({
harpreet@9076
    99
                imageType: 'normal',
harpreet@9076
   100
                src: OB.Application.contextUrl + 'utility/GetOpenbravoLogo.png',
harpreet@9076
   101
                getInnerHTML: function() {
harpreet@9076
   102
                    var html = this.Super('getInnerHTML', arguments);
harpreet@9076
   103
                    <#if data.addProfessionalLink>
harpreet@9076
   104
                    return '<a href="http://www.openbravo.com/product/erp/professional/" target="_new">' + html + '</a>';
harpreet@9076
   105
                    <#else>
harpreet@9076
   106
                    return html;
harpreet@9076
   107
                    </#if>
harpreet@9076
   108
                }
harpreet@9076
   109
            })]
harpreet@9076
   110
        })      
harpreet@9076
   111
);
harpreet@9076
   112
harpreet@9076
   113
// add the top part to the main layout
harpreet@9076
   114
OB.Layout.addMember(OB.TopLayout);
harpreet@9076
   115
harpreet@9076
   116
// create some vertical space
harpreet@9076
   117
OB.Layout.addMember(isc.LayoutSpacer.create({height: 10}));
harpreet@9076
   118
harpreet@9076
   119
OB.MainView = isc.VLayout.create({
harpreet@9076
   120
  width: '100%',
harpreet@9076
   121
  height: '100%'
harpreet@9076
   122
});
harpreet@9076
   123
OB.Layout.addMember(OB.MainView);
harpreet@9076
   124
harpreet@9076
   125
OB.MainView.TabSet = isc.TabSet.create({
harpreet@9076
   126
  width: '100%',
harpreet@9076
   127
  height: '100%',
harpreet@9076
   128
  
harpreet@9076
   129
  destroyPanes: false,
harpreet@9076
   130
  
harpreet@9076
   131
  stateAsString: null,
harpreet@9076
   132
    
harpreet@9076
   133
  // note see the smartclient autochild concept for why tabBarProperties is valid
harpreet@9076
   134
  tabBarProperties: isc.addProperties({
harpreet@9076
   135
    buttonConstructor: isc.OBTabHeaderButton,
harpreet@9076
   136
    
harpreet@9076
   137
    dblClickWaiting: false,
harpreet@9076
   138
    
harpreet@9076
   139
    itemClick: function(item, itemNum){
harpreet@9076
   140
      var me = this;
harpreet@9076
   141
      me.dblClickWaiting = true;
harpreet@9076
   142
      isc.Timer.setTimeout(function(){
harpreet@9076
   143
        // if no double click happened then do the single click
harpreet@9076
   144
        if (me.dblClickWaiting) {
harpreet@9076
   145
          me.dblClickWaiting = false;
harpreet@9076
   146
          if (me.tabSet.selectedTab === itemNum && item.pane.doHandleClick) {
harpreet@9076
   147
            item.pane.doHandleClick();
harpreet@9076
   148
          }
harpreet@9076
   149
        }
harpreet@9076
   150
      }, OB.Constants.DBL_CLICK_DELAY);
harpreet@9076
   151
      
harpreet@9076
   152
    },
harpreet@9076
   153
    itemDoubleClick: function(item, itemNum){
harpreet@9076
   154
      this.dblClickWaiting = false;
harpreet@9076
   155
      if (this.tabSet.selectedTab === itemNum && item.pane.doHandleDoubleClick) {
harpreet@9076
   156
        item.pane.doHandleDoubleClick();
harpreet@9076
   157
      }
harpreet@9076
   158
    }
harpreet@9076
   159
  }, OB.MainLayoutStylingProperties.TabSet_tabBarProperties),
harpreet@9076
   160
  tabProperties: OB.MainLayoutStylingProperties.TabSet_tabProperties,
harpreet@9076
   161
  
harpreet@9076
   162
  tabSelected: function(tabNum, tabPane, ID, tab) {
harpreet@9076
   163
    OB.Layout.HistoryManager.updateHistory();
harpreet@9076
   164
  },
harpreet@9076
   165
harpreet@9076
   166
  initWidget: function() {
harpreet@9076
   167
    this.tabBarProperties.tabSet = this;
harpreet@9076
   168
    return this.Super('initWidget', arguments);
harpreet@9076
   169
  },
harpreet@9076
   170
harpreet@9076
   171
  draw : function() {
harpreet@9076
   172
    var me = this;
harpreet@9076
   173
    var ksAction_ActivateTab = function(tab) {
harpreet@9076
   174
      me.selectTab(tab-1);
harpreet@9076
   175
      if(typeof me.getSelectedTab().pane.focusTab === 'function') {
harpreet@9076
   176
        me.getSelectedTab().pane.focusTab();
harpreet@9076
   177
      }
harpreet@9076
   178
    };
harpreet@9076
   179
    OB.KeyboardManager.KS.add('TabSet_ActivateTab1', ksAction_ActivateTab, 1);
harpreet@9076
   180
    OB.KeyboardManager.KS.add('TabSet_ActivateTab2', ksAction_ActivateTab, 2);
harpreet@9076
   181
    OB.KeyboardManager.KS.add('TabSet_ActivateTab3', ksAction_ActivateTab, 3);
harpreet@9076
   182
    OB.KeyboardManager.KS.add('TabSet_ActivateTab4', ksAction_ActivateTab, 4);
harpreet@9076
   183
    OB.KeyboardManager.KS.add('TabSet_ActivateTab5', ksAction_ActivateTab, 5);
harpreet@9076
   184
    OB.KeyboardManager.KS.add('TabSet_ActivateTab6', ksAction_ActivateTab, 6);
harpreet@9076
   185
    OB.KeyboardManager.KS.add('TabSet_ActivateTab7', ksAction_ActivateTab, 7);
harpreet@9076
   186
    OB.KeyboardManager.KS.add('TabSet_ActivateTab8', ksAction_ActivateTab, 8);
harpreet@9076
   187
    OB.KeyboardManager.KS.add('TabSet_ActivateTab9', ksAction_ActivateTab, 9);
harpreet@9076
   188
    var ksAction_closeAllTabs = function() {
harpreet@9076
   189
      var tabCount, tabArray = [], i;
harpreet@9076
   190
      for (i = 1; i > 0; i++) {
harpreet@9076
   191
        if (typeof me.getTab(i) === 'undefined') {
harpreet@9076
   192
          break;
harpreet@9076
   193
        }
harpreet@9076
   194
      }
harpreet@9076
   195
      tabCount = i-1;
harpreet@9076
   196
      me.selectTab(0);
harpreet@9076
   197
      for (i = 1; i <= tabCount; i++) {
harpreet@9076
   198
        tabArray.push(i);
harpreet@9076
   199
      }
harpreet@9076
   200
      me.removeTabs(tabArray);
harpreet@9076
   201
    };
harpreet@9076
   202
    OB.KeyboardManager.KS.add('TabSet_closeAllTabs', ksAction_closeAllTabs);
harpreet@9076
   203
    var ksAction_ActivateRightTab = function() {
harpreet@9076
   204
      me.selectTab((me.getTabNumber(me.getSelectedTab()))+1);
harpreet@9076
   205
      if(typeof me.getSelectedTab().pane.focusTab === 'function') {
harpreet@9076
   206
        me.getSelectedTab().pane.focusTab();
harpreet@9076
   207
      }
harpreet@9076
   208
    };
harpreet@9076
   209
    OB.KeyboardManager.KS.add('TabSet_ActivateRightTab', ksAction_ActivateRightTab);
harpreet@9076
   210
    var ksAction_ActivateLeftTab = function() {
harpreet@9076
   211
      me.selectTab((me.getTabNumber(me.getSelectedTab()))-1);
harpreet@9076
   212
      if(typeof me.getSelectedTab().pane.focusTab === 'function') {
harpreet@9076
   213
        me.getSelectedTab().pane.focusTab();
harpreet@9076
   214
      }
harpreet@9076
   215
    };
harpreet@9076
   216
    OB.KeyboardManager.KS.add('TabSet_ActivateLeftTab', ksAction_ActivateLeftTab);
harpreet@9076
   217
    var ksAction_ReloadActive = function() {
harpreet@9076
   218
      if(typeof me.getSelectedTab().pane.refreshTab === 'function') {
harpreet@9076
   219
        me.getSelectedTab().pane.refreshTab();
harpreet@9076
   220
      } else {
harpreet@9076
   221
        me.getSelectedTab().pane.markForRedraw();
harpreet@9076
   222
      }
harpreet@9076
   223
      if(typeof me.getSelectedTab().pane.focusTab === 'function') {
harpreet@9076
   224
        me.getSelectedTab().pane.focusTab();
harpreet@9076
   225
      }
harpreet@9076
   226
    };
harpreet@9076
   227
    OB.KeyboardManager.KS.add('TabSet_ReloadActive', ksAction_ReloadActive);
harpreet@9076
   228
    this.Super('draw', arguments);
harpreet@9076
   229
  },
harpreet@9076
   230
harpreet@9076
   231
  // is used by selenium
harpreet@9076
   232
  getTabFromTitle : function(title) {
harpreet@9076
   233
      var index = 0, tab = null;
harpreet@9076
   234
      for (; index < OB.MainView.TabSet.tabs.getLength();index++) {
harpreet@9076
   235
        tab = OB.MainView.TabSet.getTabObject(index);
harpreet@9076
   236
        if (tab.title === title) {
harpreet@9076
   237
          return tab;
harpreet@9076
   238
        }
harpreet@9076
   239
      }
harpreet@9076
   240
      return null;
harpreet@9076
   241
    },
harpreet@9076
   242
    
harpreet@9076
   243
  removeTabs: function(tabs, destroyPanes) {
harpreet@9076
   244
    var i, tab, appFrame, tabsLength, toRemove = [],
harpreet@9076
   245
        tabSet = OB.MainView.TabSet;
harpreet@9076
   246
harpreet@9076
   247
    if(!tabs) {
harpreet@9076
   248
      return;
harpreet@9076
   249
    }
harpreet@9076
   250
harpreet@9076
   251
    if (!isc.isAn.Array(tabs)) { 
harpreet@9076
   252
        tabs = [tabs];
harpreet@9076
   253
    }
harpreet@9076
   254
harpreet@9076
   255
    // get the actual tab button object from whatever was passed in.
harpreet@9076
   256
    // We can pass this to tabBar.removeTabs()
harpreet@9076
   257
    tabs = this.map('getTab', tabs);
harpreet@9076
   258
harpreet@9076
   259
    tabsLength = tabs.length;
harpreet@9076
   260
harpreet@9076
   261
    for (i = 0; i < tabsLength; i++) {
harpreet@9076
   262
      tab = tabSet.getTab(tabs[i].ID);
harpreet@9076
   263
      if(tab.pane.Class === 'OBClassicWindow') {
harpreet@9076
   264
harpreet@9076
   265
        appFrame = tab.pane.appFrameWindow ||
harpreet@9076
   266
                   tab.pane.getAppFrameWindow();
harpreet@9076
   267
harpreet@9076
   268
        if(appFrame && appFrame.isUserChanges) {
harpreet@9076
   269
          if(appFrame.validate && !appFrame.validate()) {
harpreet@9076
   270
            return false;
harpreet@9076
   271
          }
harpreet@9076
   272
          tab.pane.saveRecord(tabs[i].ID);
harpreet@9076
   273
        } else {
harpreet@9076
   274
          OB.Layout.ViewManager.views.removeTab(tabs[i].ID);
harpreet@9076
   275
          toRemove.push(tabs[i].ID);
harpreet@9076
   276
        }
harpreet@9076
   277
      } else {
harpreet@9076
   278
        OB.Layout.ViewManager.views.removeTab(tabs[i].ID);
harpreet@9076
   279
        toRemove.push(tabs[i].ID);
harpreet@9076
   280
      }
harpreet@9076
   281
    }
harpreet@9076
   282
    this.Super('removeTabs', [toRemove]);
harpreet@9076
   283
    OB.Layout.HistoryManager.updateHistory();
harpreet@9076
   284
    return true;
harpreet@9076
   285
  }
harpreet@9076
   286
}, OB.MainLayoutStylingProperties.TabSet);
harpreet@9076
   287
harpreet@9076
   288
OB.MainView.addMember(OB.MainView.TabSet);
harpreet@9076
   289
harpreet@9076
   290
OB.TestRegistry.register('org.openbravo.client.application.mainview', OB.MainView);
harpreet@9076
   291
OB.TestRegistry.register('org.openbravo.client.application.mainview.tabset', OB.MainView.TabSet);
harpreet@9076
   292
OB.TestRegistry.register('org.openbravo.client.application.layout', OB.Layout);
harpreet@9076
   293
harpreet@9076
   294
OB.Toolbar.addMembers([
harpreet@9076
   295
<#list data.navigationBarComponents as nbc>
harpreet@9076
   296
${nbc.jscode}<#if nbc_has_next>,</#if>
harpreet@9076
   297
</#list>]);
harpreet@9076
   298
harpreet@9076
   299
// test to see if we can show the heartbeat or registration popups (or not)
harpreet@9076
   300
(function _OB_checkHeartBeatRegistration() {
harpreet@9076
   301
 var handleReturn = function(response, data, request) {
harpreet@9076
   302
     if (data.showInstancePurpose) {
harpreet@9076
   303
       OB.Layout.ClassicOBCompatibility.Popup.openInstancePurpose();
harpreet@9076
   304
     } else if (data.showHeartbeat) {
harpreet@9076
   305
       OB.Layout.ClassicOBCompatibility.Popup.openHeartbeat();
harpreet@9076
   306
     } else if (data.showRegistration) {
harpreet@9076
   307
       OB.Layout.ClassicOBCompatibility.Popup.openRegistration();
harpreet@9076
   308
     }
harpreet@9076
   309
 };
harpreet@9076
   310
harpreet@9076
   311
 OB.RemoteCallManager.call('org.openbravo.client.application.HeartBeatPopupActionHandler', {}, {}, handleReturn);
harpreet@9076
   312
harpreet@9076
   313
})();