| <!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="viewcontent" class="viewcontent"> |
| |
| <div id="apps"></div> |
| <br/> |
| |
| </div> |
| |
| <script type="text/javascript"> |
| (function storebody() { |
| |
| /** |
| * Setup page layout. |
| */ |
| (function layout() { |
| document.title = config.windowtitle() + ' - Apps'; |
| if (!ui.isMobile()) |
| $('viewcontent').className = 'viewcontent flatscrollbars'; |
| |
| $('viewcontent').appendChild(ui.declareCSS( |
| '.ratings { ' + |
| 'background: url(\'' + ui.b64png(appcache.get('/public/ratings.b64')) + '\'); ' + |
| 'margin-top: 6px; width: 50px; height: 14px; display: inline-block; ' + |
| ' }')); |
| })(); |
| |
| /** |
| * The store categories |
| */ |
| var categories = [ |
| ['Featured', 'featured', 1], |
| ['Top', 'top', 2], |
| ['New', 'new', 3], |
| ['My Apps', 'myapps', 5] |
| ]; |
| |
| /** |
| * Find a store category. |
| */ |
| function findcategory(name) { |
| if (isNull(name)) |
| return findcategory('featured'); |
| var f = filter(function(c) { return cadr(c) == name }, categories); |
| if (isNull(f)) |
| return findcategory('featured'); |
| return car(f); |
| } |
| |
| /** |
| * Get the requested store category. |
| */ |
| var catname = cadr(findcategory(ui.fragmentParams(location)['category'])); |
| |
| /** |
| * Build the store menu bar |
| */ |
| $('viewhead').innerHTML = (function catmenu() { |
| function catmenuitem(name, cat, idx) { |
| var c = cat == catname? 'smenu' : 'amenu'; |
| return '<span>' + ui.href('storecat_' + cat, '/#view=store&category=' + cat + '&idx=' + idx, '_view', '<span class="' + c + '">' + name + '</span>') + '</span>'; |
| } |
| |
| var m = ''; |
| map(function(c) { m += catmenuitem(car(c), cadr(c), caddr(c)); }, categories); |
| m += '<input type="button" class="bluebutton" id="createApp" style="position: absolute; top: 4px; right: 2px;" title="Create a new app" Value="Create"/>'; |
| return m; |
| })(); |
| |
| |
| /** |
| * Initialize service references. |
| */ |
| var editorComp = sca.component("Editor"); |
| var store = sca.reference(editorComp, "store"); |
| var dashboards = sca.reference(editorComp, "dashboards"); |
| var icons = sca.reference(editorComp, "icons"); |
| |
| /** |
| * Edit an app. |
| */ |
| function editapp(appname) { |
| return ui.navigate('/#view=page&app=' + appname, '_view'); |
| } |
| |
| /** |
| * View an app. |
| */ |
| function viewapp(appname) { |
| return ui.navigate('/#view=info&app=' + appname, '_view'); |
| } |
| |
| /** |
| * Create an app. |
| */ |
| ui.onclick($('createApp'), function(e) { |
| return ui.navigate('/#view=create', '_view'); |
| }); |
| |
| /** |
| * Get and display an app icon. |
| */ |
| function geticon(appname) { |
| if (isNull(appname)) |
| return false; |
| |
| return icons.get(appname, function(doc) { |
| // Stop now if we didn't get an icon |
| if (doc == null) |
| return false; |
| |
| var iconentry = car(elementsToValues(atom.readATOMEntry(mklist(doc)))); |
| var content = assoc("'content", iconentry); |
| var icon = assoc("'icon", content); |
| var img = assoc("'image", icon); |
| if (!isNull(img)) { |
| var appimg = $('store_app_img_' + appname); |
| if (!isNull(appimg)) |
| appimg.src = cadr(img); |
| } |
| return true; |
| }); |
| return true; |
| } |
| |
| /** |
| * Get and display list of apps. |
| */ |
| (function getapps() { |
| workingstatus(true); |
| showstatus('Loading'); |
| |
| function display(doc) { |
| |
| // Stop now if we didn't get the apps |
| if (doc == null) { |
| errorstatus('Couldn\'t get the list of apps'); |
| workingstatus(false); |
| return false; |
| } |
| |
| var feed = car(elementsToValues(atom.readATOMFeed(mklist(doc)))); |
| var aentries = assoc("'entry", feed); |
| var entries = isNull(aentries)? mklist() : isList(car(cadr(aentries)))? cadr(aentries) : mklist(cdr(aentries)); |
| |
| var defappimg = ui.b64png(appcache.get('/public/app.b64')); |
| |
| var apps = '<div>'; |
| var icons = mklist(); |
| |
| (function displayentries(entries) { |
| if (isNull(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 = xmldatetime(cadr(assoc("'updated", entry))).toLocaleDateString(); |
| |
| var aratings = assoc("'info", assoc("'content", entry)); |
| var ar = assoc("'rating", aratings); |
| var ar1 = assoc("'rating1", aratings); |
| var ar2 = assoc("'rating2", aratings); |
| var ar3 = assoc("'rating3", aratings); |
| var ar4 = assoc("'rating4", aratings); |
| var rating = isNull(ar)? 0 : Number(cadr(ar)); |
| var reviews = (isNull(ar1)? 0 : Number(cadr(ar1))) + (isNull(ar2)? 0 : Number(cadr(ar2))) + (isNull(ar3)? 0 : Number(cadr(ar3))) + (isNull(ar4)? 0 : Number(cadr(ar4))); |
| |
| apps += '<div class="box">' |
| apps += '<div class="appicon">' |
| apps += ui.href('appicon_' + name, '/#view=info&app=' + name, '_view', '<img id="store_app_img_' + name + '" src="' + defappimg + '" width="50" height="50"></img>'); |
| //apps += '<br/><input type="button" class="lightbutton" value="Run" onclick="ui.navigate(\'/' + name + '/\', \'_blank\');"/>'; |
| apps += '</div>' |
| apps += '<div class="appdetails">'; |
| apps += '<span class="apptitle">' + ui.href('store_app_title_' + name, '/#view=info&app=' + name, '_view', name) + '</span>'; |
| if (catname != 'myapps') |
| apps += '<br/><span>' + 'by ' + author.split('@')[0] + '</span>'; |
| var ratingy = -20 * (4 - Math.floor(rating)); |
| apps += '<br/><span class="ratings" style="background-position: 0px ' + ratingy + 'px;"> </span>'; |
| apps += '<br/><span style="font-size: 10px;">' + reviews + (reviews > 1? ' ratings' : ' rating') + '</span>'; |
| /*apps += '<br/><span>' + updated + '</span>';*/ |
| apps += '</div>'; |
| apps += '</div>'; |
| |
| icons = cons(name, icons); |
| |
| return displayentries(cdr(entries)); |
| })(entries); |
| |
| apps += '</div>'; |
| $('apps').innerHTML = apps; |
| |
| ui.unmemo$('store_app_'); |
| |
| (function displayicons(icons) { |
| if (isNull(icons)) |
| return true; |
| geticon(car(icons)); |
| return displayicons(cdr(icons)); |
| })(reverse(icons)); |
| |
| onlinestatus(); |
| workingstatus(false); |
| } |
| |
| if (catname == 'myapps') |
| return dashboards.get('', display); |
| return store.get(catname, display); |
| })(); |
| |
| })(); |
| </script> |
| |
| </div> |