summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/hosting/server/htdocs/store/index.html
blob: 471229d9d5ca91e70036223e5fdac0e26855a7e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<!--
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
-->
<div id="bodydiv" class="body">

<div id="apps" class="viewcontent"></div>

<script type="text/javascript">

// Set page titles
document.title = ui.windowtitle(location.hostname) + ' - Store';

// Get the store category
var category = ui.fragmentParams(location)['category'];
if (isNil(category))
    category = 'top';

/**
 * Build store menu bar
 */
function catmenu() {
    function catmenuitem(name, cat, idx) {
        var c = cat == category? 'smenu' : 'amenu';
        return '<span>' + ui.ahref('/#view=store&category=' + cat + '&idx=' + idx, '_view', '<span class="' + c + '">' + name + '</span>') + '</span>';
    }

    var m = '';
    //m += catmenuitem('Featured', 'featured', '1');
    m += catmenuitem('Top', 'top', '2');
    m += catmenuitem('New', 'new', '3');
    m += catmenuitem('Search', 'all', '4');
    m += catmenuitem('My Apps', 'myapps', '5');
    m += '<span class="rmenu"><input type="button" class="graybutton bluebutton" id="createApp" title="Create a new app" Value="Create"/></span>';
    return m;
}

// Build store menu bar
$('viewhead').innerHTML = catmenu();

/**
 * Service references.
 */
var editWidget = sca.component("EditWidget");
var store = sca.reference(editWidget, "store");
var dashboards = sca.reference(editWidget, "dashboards");

/**
 * Edit an app.
 */
function editApp(appname) {
    return ui.navigate('/#view=page&app=' + appname, '_view');
}

/**
 * View an app.
 */
function viewApp(appname) {
    return ui.navigate('/#view=stats&app=' + appname, '_view');
}

/**
 * Create an app.
 */
$('createApp').onclick = function() {
    return ui.navigate('/#view=create', '_view');
}

/**
 * Get and display list of apps.
 */
function getapps(category) {
    //debug('category', category);
    showStatus('Loading');

    function display(doc) {

        // Stop now if we didn't get the apps
        if (doc == null) {
            showError('App not available');
            return false;
        }
        showStatus(defaultStatus());

        var apps = '<div>';
        var feed = car(elementsToValues(atom.readATOMFeed(mklist(doc))));
        var aentries = assoc("'entry", cdr(feed));
        var entries = isNil(aentries)? mklist() : isList(car(cadr(aentries)))? cadr(aentries) : mklist(cdr(aentries));

        var appimg = ui.b64img(appcache.get('/public/app.b64'));

        function displayentries(entries) {
            if (isNil(entries))
                return apps;
            var entry = car(entries);
            var title = cadr(assoc("'title", entry))
            var name = cadr(assoc("'id", entry));
            var author = cadr(assoc("'author", entry));
            var updated = cadr(assoc("'updated", entry));

            apps += '<div class="box">'
            apps += '<span class="appicon">' + ui.ahref('/#view=stats&app=' + name, '_view', '<img src="' + appimg + '" width="50" height="50"></img>') + '</span>';
            apps += '<span>'
            apps += '<span class="apptitle">' + ui.ahref('/#view=stats&app=' + name, '_view', name) + '</span>';
            if (category != 'myapps')
                apps += '<br/><span>' + 'by&nbsp;' + author.split('@')[0] + '</span>';
            apps += '</span>';
            apps += '</div>';
            return displayentries(cdr(entries));
        }

        displayentries(entries);

        apps += '</div>';
        $('apps').innerHTML = apps;
    }

    if (category == 'myapps')
        return dashboards.get('', display);
    return store.get(category, display);
}

// Get and display the list of apps
getapps(category);

</script>

</div>