From a645ac59b4994f44dcae532fd929dbdaa1b8a5c8 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Sat, 5 Apr 2014 07:50:53 +0300 Subject: web client: avoid using 'data-main' attribute not valid XHTML --- web/client.js | 375 +++++++++++++++++++++++++++---------------------------- web/client.xhtml | 19 ++- 2 files changed, 204 insertions(+), 190 deletions(-) diff --git a/web/client.js b/web/client.js index 9746846..cbd8fa2 100644 --- a/web/client.js +++ b/web/client.js @@ -3,22 +3,7 @@ * See LICENSE file for license details */ -requirejs.config({ - baseUrl: "lib", - paths: {aconf: ".."}, - shim: { - underscore: {exports: "_"}, - "jquery-bbq": {deps: ["jquery"]}, - "jquery-blockui": {deps: ["jquery"]}, - "jquery-ui/core": {deps: ["jquery"]}, - "jquery-ui/datepicker": {deps: ["jquery-ui/core"]}, - "jquery-ui/mouse": {deps: ["jquery-ui/widget"]}, - "jquery-ui/sortable": {deps: ["jquery-ui/core", "jquery-ui/mouse"]}, - "jquery-ui/widget": {deps: ["jquery"]} - } -}); - -require( +define( [ "aconf/dom", "aconf/error", @@ -37,202 +22,214 @@ require( function( dom, formatError, navi, pth, statusBar, txnMgr, type, Inline, $, _ ) { - $("#login").submit(function() { - - $.ajax("/login", { - type: "POST", - data: JSON.stringify({ - username: $("#username").val(), - password: $("#password").val() - }) - }).done(function(data, status, xhr) { - - txnMgr = txnMgr( - xhr.getResponseHeader("X-AConf-Auth-Token"), - xhr.getResponseHeader("X-AConf-Save-Required") == "1" - ); - - - var objPath; - - function renderObject(path, data) { - if (path) objPath = path; - - return ( - data ? $.Deferred().resolve(data) : txnMgr.query(objPath) - ).done(function(data) { - var layout = data.meta.widget; - var name = pth.split(objPath).pop(); - (layout ? - require("aconf/layout/" + layout) : - Inline).extend({ - createEl: function() { - return $("#content").empty(); - }, - wrap: function() { return this.el; }, - requestData: function(value, meta) { - return $.Deferred().resolve(data, data.meta); - } - }).new( - { - get: function(name) { return objPath; }, - status: function(name) { return null; }, - match: function(filter) { return true; } - }, - name, - {}, - 0, - true, - false - ); - }).fail(function() { - var comps = pth.split(objPath); - comps.pop(); - comps.unshift("/"); - navi.setPath(pth.join.apply(undefined, comps)); + return function() { + $("#login").submit(function() { + + $.ajax("/login", { + type: "POST", + data: JSON.stringify({ + username: $("#username").val(), + password: $("#password").val() + }) + }).done(function(data, status, xhr) { + + txnMgr = txnMgr( + xhr.getResponseHeader("X-AConf-Auth-Token"), + xhr.getResponseHeader("X-AConf-Save-Required") == "1" + ); + + + var objPath; + + function renderObject(path, data) { + if (path) objPath = path; + + return ( + data ? $.Deferred().resolve(data) : + txnMgr.query(objPath) + ).done(function(data) { + var layout = data.meta.widget; + var name = pth.split(objPath).pop(); + (layout ? + require("aconf/layout/" + layout) : + Inline).extend({ + createEl: function() { + return $("#content").empty(); + }, + wrap: function() { return this.el; }, + requestData: function(value, meta) { + return $.Deferred() + .resolve(data, data.meta); + } + }).new( + { + get: function(name) { return objPath; }, + status: function(name) { return null; }, + match: function(filter) { return true; } + }, + name, + {}, + 0, + true, + false + ); + }).fail(function() { + var comps = pth.split(objPath); + comps.pop(); + comps.unshift("/"); + navi.setPath(pth.join.apply(undefined, comps)); + }); + }; + + $("#content").on("reload", function(event, txnValid) { + statusBar.validationReady(txnValid); + renderObject(); + event.stopPropagation(); }); - }; - $("#content").on("reload", function(event, txnValid) { - statusBar.validationReady(txnValid); - renderObject(); - event.stopPropagation(); - }); + function render() { + var path = navi.getPath(); - function render() { - var path = navi.getPath(); + function renderMenu( + target, path, current, selectFirst + ) { + var def = $.Deferred(); - function renderMenu(target, path, current, selectFirst) { - var def = $.Deferred(); + txnMgr.query(path).done(function(data) { + if (data.meta.type != "model") { + def.reject(data); + return; + } - txnMgr.query(path).done(function(data) { - if (data.meta.type != "model") { - def.reject(data); - return; - } + var tnFields = []; + var extraFields = false; - var tnFields = []; - var extraFields = false; + _.each(data.meta.fields, function(field) { + if (!field.visible) return; - _.each(data.meta.fields, function(field) { - if (!field.visible) return; + if (!type.isTreeNode(field)) + extraFields = true; + else if (data.data[field.name]) + tnFields.push(field); + }); - if (!type.isTreeNode(field)) - extraFields = true; - else if (data.data[field.name]) - tnFields.push(field); - }); + if (!tnFields.length) { + def.reject(data); + return; + } - if (!tnFields.length) { - def.reject(data); - return; - } + function addItem( + path, ui_name, status, current + ) { + var el = $("
  • ").html( + dom.objectRef(path).text(ui_name) + ); + dom.setStatus(el, status); + if (current) el.addClass("current"); + target.append(el); + } + + if (extraFields) { + addItem(path, "General", null, !current); + selectFirst = false; + } + + _.each(tnFields, function(field, i) { + addItem( + data.get(field.name), + field["ui-name"], + data.status(field.name), + current == field.name || ( + !current && !i && selectFirst + ) + ); + field.visible = false; + }); - function addItem(path, ui_name, status, current) { - var el = $("
  • ").html( - dom.objectRef(path).text(ui_name) + def.resolve( + extraFields ? data : tnFields[0].name ); - dom.setStatus(el, status); - if (current) el.addClass("current"); - target.append(el); - } + }); - if (extraFields) { - addItem(path, "General", null, !current); - selectFirst = false; - } + return def; + } - _.each(tnFields, function(field, i) { - addItem( - data.get(field.name), - field["ui-name"], - data.status(field.name), - current == field.name || ( - !current && !i && selectFirst - ) - ); - field.visible = false; - }); - def.resolve(extraFields ? data : tnFields[0].name); + if (path > "/") $("#content").text("Loading..."); + + txnMgr.start().done(function() { + var comps = pth.split(path); + renderMenu( + $("#modules").empty(), "/", comps[0], false + ); + var tabs = $("#tabs").empty(); + + if (path == "/") return; + + function renderTabs(p) { + p = pth.join(p, comps.shift()); + renderMenu(tabs, p, comps[0], true) + .done(function(data) { + var tabLevel = !comps.length; + renderObject( + ( + tabLevel && _.isString(data) + ) ? pth.join(p, data) : path, + tabLevel && _.isObject(data) ? + data : null + ); + }) + .fail(function(data) { + if (comps.length) renderTabs(p); + else renderObject(p, data); + }); + } + renderTabs("/"); }); - - return def; } - - if (path > "/") $("#content").text("Loading..."); - - txnMgr.start().done(function() { - var comps = pth.split(path); - renderMenu($("#modules").empty(), "/", comps[0], false); - var tabs = $("#tabs").empty(); - - if (path == "/") return; - - function renderTabs(p) { - p = pth.join(p, comps.shift()); - renderMenu(tabs, p, comps[0], true) - .done(function(data) { - var tabLevel = !comps.length; - renderObject( - ( - tabLevel && _.isString(data) - ) ? pth.join(p, data) : path, - tabLevel && _.isObject(data) ? - data : null - ); - }) - .fail(function(data) { - if (comps.length) renderTabs(p); - else renderObject(p, data); - }); - } - renderTabs("/"); + + function clearState() { + statusBar.reset(); + render(); + $.unblockUI(); + } + + $("#commit").click(function() { + $.blockUI(); + txnMgr.commit().done(clearState).fail(function(xhr) { + statusBar.setError( + formatError("Commit failed", xhr), "txn" + ); + }) }); - } - - - function clearState() { - statusBar.reset(); - render(); - $.unblockUI(); - } - - $("#commit").click(function() { - $.blockUI(); - txnMgr.commit().done(clearState).fail(function(xhr) { - statusBar.setError( - formatError("Commit failed", xhr), "txn" - ); - }) - }); - $("#revert").click(function() { - $.blockUI(); - txnMgr.abort(); - clearState(); - }); - - $("#logout").click(function() { - txnMgr.logout().done(function() { - $("body").html($("

    ").text("Logged out")); + $("#revert").click(function() { + $.blockUI(); + txnMgr.abort(); + clearState(); }); - }); - - statusBar.reset(); - $("#content").empty(); + + $("#logout").click(function() { + txnMgr.logout().done(function() { + $("body").html($("

    ").text("Logged out")); + }); + }); + + statusBar.reset(); + $("#content").empty(); - $(window).bind("hashchange", render); - navi.setPath("/"); + $(window).bind("hashchange", render); + navi.setPath("/"); - }).fail(function() { - statusBar.setError("Login failed", "login"); - }); + }).fail(function() { + statusBar.setError("Login failed", "login"); + }); - return false; - }); + return false; + }); - $("#username").focus(); + $("#username").focus(); + } } ); diff --git a/web/client.xhtml b/web/client.xhtml index dbdf4c4..99fc58a 100644 --- a/web/client.xhtml +++ b/web/client.xhtml @@ -9,7 +9,24 @@ -

    -- cgit v1.2.3