summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/edit/htdocs/app/index.html
blob: 29f9efae65ec79d315f34b22779d781b65ad5c73 (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
144
145
146
147
148
149
150
151
<!--
    * 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.    
-->
<html>
<head>
<title>App</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> 
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
<link rel="stylesheet" type="text/css" href="/ui.css"/>
<script type="text/javascript" src="/util.js"></script>
<script type="text/javascript" src="/elemutil.js"></script>
<script type="text/javascript" src="/xmlutil.js"></script>
<script type="text/javascript" src="/atomutil.js"></script>
<script type="text/javascript" src="/jsonutil.js"></script>
<script type="text/javascript" src="/scdl.js"></script>
<script type="text/javascript" src="/ui.js"></script>
<script type="text/javascript" src="/component.js"></script>
</head>
<body class="delayed">
<div id="app"></div>
<span id="appFrame"></span>

<script type="text/javascript">
if (ui.isIE()) $('bodydiv').style.right = -20;

/**
 * The main page component.
 */
var comp = sca.component('page');

/**
 * Returns the text value of a data element.
 */
function datatext(dv) {
    return elementHasValue(dv)? elementValue(dv) : '';
}

/**
 * Set a data value into a widget.
 */
function setwidgetvalue(e, dv) {
    if (e.className == 'h1' || e.className == 'h2' || e.className == 'text' || e.className == 'section') {
        car(childElements(e)).innerHTML = datatext(dv);
        return t;
    }
    if (e.className == 'button' || e.className == 'entry' || e.className == 'password') {
        car(childElements(e)).value = datatext(dv);
        return t;
    }
    if (e.className == 'checkbox') {
        var t = datatext(dv);
        car(childElements(e)).value = t;
        map(function(n) { if (n.nodeName == "SPAN") n.innerHTML = t; return n; }, nodeList(e.childNodes));
        return t;
    }
    if (e.className == 'list') {
        var t = datatext(dv);
        var ce = car(childElements(car(childElements(e))));
        ce.value = t;
        ce.innerHTML = t;
        return t;
    }
    if (e.className == 'link') {
        var t = datatext(dv);
        var ce = car(childElements(car(childElements(e))));
        ce.href = t;
        ce.innerHTML = t;
        return t;
    }
    if (e.className == 'table') {
        var t = ui.datatable(mklist(dv));
        car(childElements(e)).innerHTML = t;
        return t;
    }
    return '';
};

/**
 * Display data on the app page.
 */
function display(l) {
    if (isNil(l))
        return false;
    var v = car(l);

    // For each widget in the app page, look for a data element with the widget id
    // then set the data value into the widget
    function datavalue(id) {
        var dv = namedElementChild("'" + id, v);
        return dv;
    }

    function updatewidget(e) {
        var dv = datavalue(e.id);
        if (dv == null || isNil(dv))
            return e;
        setwidgetvalue(e, dv);
        return e;
    }

    var e = map(updatewidget, filter(function(e) { return !isNil(e.id); }, nodeList(ui.elementByID($('app'), 'page').childNodes)));

    // Make the page visible
    ui.showbody();
    return true;
}

/**
 * Get the contents of the main page component.
 */
function getdata() {
    $('app').innerHTML = $('appFrame').contentDocument.body.innerHTML;

    var doc = comp.get('', function(doc) {

        if (json.isJSON(mklist(doc)))
            return display(json.readJSON(mklist(doc)));

        if (atom.isATOMEntry(mklist(doc)))
            return display(atom.readATOMEntry(mklist(doc)));

        if (atom.isATOMFeed(mklist(doc)))
            return display(atom.readATOMFeed(mklist(doc)));

        return display(doc);
    });
}

// Load the app frame
$('app').innerHTML = '<iframe id="appFrame" class="widgetFrame" src="app.html" onload="getdata()"></iframe>';

</script>
</body>
</html>