~ubuntu-branches/ubuntu/hardy/coherence/hardy

« back to all changes in this revision

Viewing changes to coherence/web/static/Coherence.Base.js

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Quette
  • Date: 2007-08-02 10:48:40 UTC
  • Revision ID: james.westby@ubuntu.com-20070802104840-ip4jij6unufqno1p
Tags: upstream-0.4.0
ImportĀ upstreamĀ versionĀ 0.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Licensed under the MIT license
 
2
// http://opensource.org/licenses/mit-license.php
 
3
//
 
4
// Copyright 2007, Frank Scholz <coherence@beebits.net>
 
5
 
 
6
// import Nevow.Athena
 
7
 
 
8
// import MochiKit
 
9
 
 
10
if(typeof(Coherence) == "undefined") {
 
11
    Coherence = {};
 
12
}
 
13
 
 
14
Coherence.Base = Nevow.Athena.Widget.subclass('Coherence.Base');
 
15
Coherence.Base.activeTab = 0;
 
16
Coherence.Base.build_done = 'no';
 
17
 
 
18
Coherence.Base.methods(
 
19
 
 
20
function setTab(self, tab, active) {
 
21
    Divmod.debug("base", "setTab " + tab.id + " " + active);
 
22
    log('tab_item ' + tab.id.split('-')[0]+'-'+tab.id.split('-')[1]+'-container');
 
23
    tab_item = $(tab.id.split('-')[0]+'-'+tab.id.split('-')[1]+'-container')
 
24
    log('tab_item ' + tab_item);
 
25
    if( active == 'on') {
 
26
        if( Coherence.Base.activeTab != 0) {
 
27
            Coherence.Base.activeTab.style.color ='#FFFFFF'
 
28
            Coherence.Base.activeTab.style.backgroundColor ='#404040'
 
29
            c = $(Coherence.Base.activeTab.id.split('-')[0]+'-'+Coherence.Base.activeTab.id.split('-')[1]+'-container')
 
30
            c.style.visibility = 'hidden'
 
31
        }
 
32
        tab.style.color ='#000000'
 
33
        tab.style.backgroundColor ='#C0C0C0'
 
34
        log("set " + tab.id.split('-')[0]+'-'+tab.id.split('-')[1]+'-container' + " " + 'visible');
 
35
        tab_item.style.visibility = 'visible'
 
36
        Coherence.Base.activeTab = tab
 
37
    }
 
38
    else
 
39
    {
 
40
        tab.style.color ='#FFFFFF'
 
41
        tab.style.backgroundColor ='#404040'
 
42
        tab_item.style.visibility = 'hidden'
 
43
        Coherence.Base.activeTab = 0
 
44
    }
 
45
},
 
46
 
 
47
function clickTab(self, Event) {
 
48
    Divmod.debug("base", "clickTab " + Event.target.id);
 
49
    if( Event.target.className != 'coherence_menu_item')
 
50
        return;
 
51
    if( Coherence.Base.activeTab == Event.target)
 
52
        return;
 
53
    Coherence.Base.prototype.setTab(Event.target, 'on');
 
54
},
 
55
 
 
56
function addTab(self, tab) {
 
57
    Divmod.debug("base", 'addTab '+tab['title']+' '+tab['athenaid']);
 
58
    if( Coherence.Base.build_done == 'no') {
 
59
        Divmod.debug("base", 'Base.build_done == no');
 
60
        return;
 
61
    }
 
62
    appendChildNodes(self.nodeById('coherence_menu_box'),
 
63
        DIV({'id':tab['athenaid']+'-'+tab['title']+'-tab','class':'coherence_menu_item'}, tab['title']
 
64
        )
 
65
    )
 
66
    $(tab['athenaid']+'-'+tab['title']+'-tab').addEventListener("click", Coherence.Base.prototype.clickTab, false);
 
67
    //self.nodeById(tab['title']+'-tab').addEventListener("click", Coherence.Base.prototype.clickTab, false);
 
68
    if(tab['active'] == 'yes') {
 
69
        Divmod.debug("base", 'addTab set active '+tab['title']);
 
70
        self.setTab($(tab['athenaid']+'-'+tab['title']+'-tab'), 'on');
 
71
    }
 
72
    // MochiKit.Visual.roundElement( $(channel+'-box'));
 
73
},
 
74
 
 
75
function buildMenu(self, result) {
 
76
    Divmod.debug("base", 'buildMenu ' + result.length);
 
77
    Coherence.Base.build_done = 'yes'
 
78
    for(var i=0; i<result.length;++i) {
 
79
        Divmod.debug("base", 'buildMenu ' + i + ' ' + result[i]);
 
80
        self.addTab(result[i]);
 
81
 
 
82
    }
 
83
},
 
84
 
 
85
function __init__(self, node) {
 
86
    Divmod.debug("base",'Coherence.Base __init__');
 
87
    Coherence.Base.upcall(self, '__init__', node);
 
88
    var d = self.callRemote('going_live');
 
89
    d.addCallback(function (result) { self.buildMenu(result); });
 
90
    Divmod.debug("base",'Coherence.Base __init__ done');
 
91
}
 
92
 
 
93
);