mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
reorganize files
This commit is contained in:
-434
@@ -1,434 +0,0 @@
|
||||
/**
|
||||
* @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
|
||||
* Released under MIT license, http://github.com/requirejs/almond/LICENSE
|
||||
*/
|
||||
//Going sloppy to avoid 'use strict' string cost, but strict practices should
|
||||
//be followed.
|
||||
/*global setTimeout: false */
|
||||
|
||||
var requirejs, require, define;
|
||||
(function (undef) {
|
||||
var main, req, makeMap, handlers,
|
||||
defined = {},
|
||||
waiting = {},
|
||||
config = {},
|
||||
defining = {},
|
||||
hasOwn = Object.prototype.hasOwnProperty,
|
||||
aps = [].slice,
|
||||
jsSuffixRegExp = /\.js$/;
|
||||
|
||||
function hasProp(obj, prop) {
|
||||
return hasOwn.call(obj, prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a relative module name, like ./something, normalize it to
|
||||
* a real name that can be mapped to a path.
|
||||
* @param {String} name the relative name
|
||||
* @param {String} baseName a real name that the name arg is relative
|
||||
* to.
|
||||
* @returns {String} normalized name
|
||||
*/
|
||||
function normalize(name, baseName) {
|
||||
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
|
||||
foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
|
||||
baseParts = baseName && baseName.split("/"),
|
||||
map = config.map,
|
||||
starMap = (map && map['*']) || {};
|
||||
|
||||
//Adjust any relative paths.
|
||||
if (name) {
|
||||
name = name.split('/');
|
||||
lastIndex = name.length - 1;
|
||||
|
||||
// If wanting node ID compatibility, strip .js from end
|
||||
// of IDs. Have to do this here, and not in nameToUrl
|
||||
// because node allows either .js or non .js to map
|
||||
// to same file.
|
||||
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
||||
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
||||
}
|
||||
|
||||
// Starts with a '.' so need the baseName
|
||||
if (name[0].charAt(0) === '.' && baseParts) {
|
||||
//Convert baseName to array, and lop off the last part,
|
||||
//so that . matches that 'directory' and not name of the baseName's
|
||||
//module. For instance, baseName of 'one/two/three', maps to
|
||||
//'one/two/three.js', but we want the directory, 'one/two' for
|
||||
//this normalization.
|
||||
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
|
||||
name = normalizedBaseParts.concat(name);
|
||||
}
|
||||
|
||||
//start trimDots
|
||||
for (i = 0; i < name.length; i++) {
|
||||
part = name[i];
|
||||
if (part === '.') {
|
||||
name.splice(i, 1);
|
||||
i -= 1;
|
||||
} else if (part === '..') {
|
||||
// If at the start, or previous value is still ..,
|
||||
// keep them so that when converted to a path it may
|
||||
// still work when converted to a path, even though
|
||||
// as an ID it is less than ideal. In larger point
|
||||
// releases, may be better to just kick out an error.
|
||||
if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
|
||||
continue;
|
||||
} else if (i > 0) {
|
||||
name.splice(i - 1, 2);
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
//end trimDots
|
||||
|
||||
name = name.join('/');
|
||||
}
|
||||
|
||||
//Apply map config if available.
|
||||
if ((baseParts || starMap) && map) {
|
||||
nameParts = name.split('/');
|
||||
|
||||
for (i = nameParts.length; i > 0; i -= 1) {
|
||||
nameSegment = nameParts.slice(0, i).join("/");
|
||||
|
||||
if (baseParts) {
|
||||
//Find the longest baseName segment match in the config.
|
||||
//So, do joins on the biggest to smallest lengths of baseParts.
|
||||
for (j = baseParts.length; j > 0; j -= 1) {
|
||||
mapValue = map[baseParts.slice(0, j).join('/')];
|
||||
|
||||
//baseName segment has config, find if it has one for
|
||||
//this name.
|
||||
if (mapValue) {
|
||||
mapValue = mapValue[nameSegment];
|
||||
if (mapValue) {
|
||||
//Match, update name to the new value.
|
||||
foundMap = mapValue;
|
||||
foundI = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundMap) {
|
||||
break;
|
||||
}
|
||||
|
||||
//Check for a star map match, but just hold on to it,
|
||||
//if there is a shorter segment match later in a matching
|
||||
//config, then favor over this star map.
|
||||
if (!foundStarMap && starMap && starMap[nameSegment]) {
|
||||
foundStarMap = starMap[nameSegment];
|
||||
starI = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundMap && foundStarMap) {
|
||||
foundMap = foundStarMap;
|
||||
foundI = starI;
|
||||
}
|
||||
|
||||
if (foundMap) {
|
||||
nameParts.splice(0, foundI, foundMap);
|
||||
name = nameParts.join('/');
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
function makeRequire(relName, forceSync) {
|
||||
return function () {
|
||||
//A version of a require function that passes a moduleName
|
||||
//value for items that may need to
|
||||
//look up paths relative to the moduleName
|
||||
var args = aps.call(arguments, 0);
|
||||
|
||||
//If first arg is not require('string'), and there is only
|
||||
//one arg, it is the array form without a callback. Insert
|
||||
//a null so that the following concat is correct.
|
||||
if (typeof args[0] !== 'string' && args.length === 1) {
|
||||
args.push(null);
|
||||
}
|
||||
return req.apply(undef, args.concat([relName, forceSync]));
|
||||
};
|
||||
}
|
||||
|
||||
function makeNormalize(relName) {
|
||||
return function (name) {
|
||||
return normalize(name, relName);
|
||||
};
|
||||
}
|
||||
|
||||
function makeLoad(depName) {
|
||||
return function (value) {
|
||||
defined[depName] = value;
|
||||
};
|
||||
}
|
||||
|
||||
function callDep(name) {
|
||||
if (hasProp(waiting, name)) {
|
||||
var args = waiting[name];
|
||||
delete waiting[name];
|
||||
defining[name] = true;
|
||||
main.apply(undef, args);
|
||||
}
|
||||
|
||||
if (!hasProp(defined, name) && !hasProp(defining, name)) {
|
||||
throw new Error('No ' + name);
|
||||
}
|
||||
return defined[name];
|
||||
}
|
||||
|
||||
//Turns a plugin!resource to [plugin, resource]
|
||||
//with the plugin being undefined if the name
|
||||
//did not have a plugin prefix.
|
||||
function splitPrefix(name) {
|
||||
var prefix,
|
||||
index = name ? name.indexOf('!') : -1;
|
||||
if (index > -1) {
|
||||
prefix = name.substring(0, index);
|
||||
name = name.substring(index + 1, name.length);
|
||||
}
|
||||
return [prefix, name];
|
||||
}
|
||||
|
||||
//Creates a parts array for a relName where first part is plugin ID,
|
||||
//second part is resource ID. Assumes relName has already been normalized.
|
||||
function makeRelParts(relName) {
|
||||
return relName ? splitPrefix(relName) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a name map, normalizing the name, and using a plugin
|
||||
* for normalization if necessary. Grabs a ref to plugin
|
||||
* too, as an optimization.
|
||||
*/
|
||||
makeMap = function (name, relParts) {
|
||||
var plugin,
|
||||
parts = splitPrefix(name),
|
||||
prefix = parts[0],
|
||||
relResourceName = relParts[1];
|
||||
|
||||
name = parts[1];
|
||||
|
||||
if (prefix) {
|
||||
prefix = normalize(prefix, relResourceName);
|
||||
plugin = callDep(prefix);
|
||||
}
|
||||
|
||||
//Normalize according
|
||||
if (prefix) {
|
||||
if (plugin && plugin.normalize) {
|
||||
name = plugin.normalize(name, makeNormalize(relResourceName));
|
||||
} else {
|
||||
name = normalize(name, relResourceName);
|
||||
}
|
||||
} else {
|
||||
name = normalize(name, relResourceName);
|
||||
parts = splitPrefix(name);
|
||||
prefix = parts[0];
|
||||
name = parts[1];
|
||||
if (prefix) {
|
||||
plugin = callDep(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
//Using ridiculous property names for space reasons
|
||||
return {
|
||||
f: prefix ? prefix + '!' + name : name, //fullName
|
||||
n: name,
|
||||
pr: prefix,
|
||||
p: plugin
|
||||
};
|
||||
};
|
||||
|
||||
function makeConfig(name) {
|
||||
return function () {
|
||||
return (config && config.config && config.config[name]) || {};
|
||||
};
|
||||
}
|
||||
|
||||
handlers = {
|
||||
require: function (name) {
|
||||
return makeRequire(name);
|
||||
},
|
||||
exports: function (name) {
|
||||
var e = defined[name];
|
||||
if (typeof e !== 'undefined') {
|
||||
return e;
|
||||
} else {
|
||||
return (defined[name] = {});
|
||||
}
|
||||
},
|
||||
module: function (name) {
|
||||
return {
|
||||
id: name,
|
||||
uri: '',
|
||||
exports: defined[name],
|
||||
config: makeConfig(name)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
main = function (name, deps, callback, relName) {
|
||||
var cjsModule, depName, ret, map, i, relParts,
|
||||
args = [],
|
||||
callbackType = typeof callback,
|
||||
usingExports;
|
||||
|
||||
//Use name if no relName
|
||||
relName = relName || name;
|
||||
relParts = makeRelParts(relName);
|
||||
|
||||
//Call the callback to define the module, if necessary.
|
||||
if (callbackType === 'undefined' || callbackType === 'function') {
|
||||
//Pull out the defined dependencies and pass the ordered
|
||||
//values to the callback.
|
||||
//Default to [require, exports, module] if no deps
|
||||
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
|
||||
for (i = 0; i < deps.length; i += 1) {
|
||||
map = makeMap(deps[i], relParts);
|
||||
depName = map.f;
|
||||
|
||||
//Fast path CommonJS standard dependencies.
|
||||
if (depName === "require") {
|
||||
args[i] = handlers.require(name);
|
||||
} else if (depName === "exports") {
|
||||
//CommonJS module spec 1.1
|
||||
args[i] = handlers.exports(name);
|
||||
usingExports = true;
|
||||
} else if (depName === "module") {
|
||||
//CommonJS module spec 1.1
|
||||
cjsModule = args[i] = handlers.module(name);
|
||||
} else if (hasProp(defined, depName) ||
|
||||
hasProp(waiting, depName) ||
|
||||
hasProp(defining, depName)) {
|
||||
args[i] = callDep(depName);
|
||||
} else if (map.p) {
|
||||
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
||||
args[i] = defined[depName];
|
||||
} else {
|
||||
throw new Error(name + ' missing ' + depName);
|
||||
}
|
||||
}
|
||||
|
||||
ret = callback ? callback.apply(defined[name], args) : undefined;
|
||||
|
||||
if (name) {
|
||||
//If setting exports via "module" is in play,
|
||||
//favor that over return value and exports. After that,
|
||||
//favor a non-undefined return value over exports use.
|
||||
if (cjsModule && cjsModule.exports !== undef &&
|
||||
cjsModule.exports !== defined[name]) {
|
||||
defined[name] = cjsModule.exports;
|
||||
} else if (ret !== undef || !usingExports) {
|
||||
//Use the return value from the function.
|
||||
defined[name] = ret;
|
||||
}
|
||||
}
|
||||
} else if (name) {
|
||||
//May just be an object definition for the module. Only
|
||||
//worry about defining if have a module name.
|
||||
defined[name] = callback;
|
||||
}
|
||||
};
|
||||
|
||||
requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
|
||||
if (typeof deps === "string") {
|
||||
if (handlers[deps]) {
|
||||
//callback in this case is really relName
|
||||
return handlers[deps](callback);
|
||||
}
|
||||
//Just return the module wanted. In this scenario, the
|
||||
//deps arg is the module name, and second arg (if passed)
|
||||
//is just the relName.
|
||||
//Normalize module name, if it contains . or ..
|
||||
return callDep(makeMap(deps, makeRelParts(callback)).f);
|
||||
} else if (!deps.splice) {
|
||||
//deps is a config object, not an array.
|
||||
config = deps;
|
||||
if (config.deps) {
|
||||
req(config.deps, config.callback);
|
||||
}
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback.splice) {
|
||||
//callback is an array, which means it is a dependency list.
|
||||
//Adjust args if there are dependencies
|
||||
deps = callback;
|
||||
callback = relName;
|
||||
relName = null;
|
||||
} else {
|
||||
deps = undef;
|
||||
}
|
||||
}
|
||||
|
||||
//Support require(['a'])
|
||||
callback = callback || function () {};
|
||||
|
||||
//If relName is a function, it is an errback handler,
|
||||
//so remove it.
|
||||
if (typeof relName === 'function') {
|
||||
relName = forceSync;
|
||||
forceSync = alt;
|
||||
}
|
||||
|
||||
//Simulate async callback;
|
||||
if (forceSync) {
|
||||
main(undef, deps, callback, relName);
|
||||
} else {
|
||||
//Using a non-zero value because of concern for what old browsers
|
||||
//do, and latest browsers "upgrade" to 4 if lower value is used:
|
||||
//http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
|
||||
//If want a value immediately, use require('id') instead -- something
|
||||
//that works in almond on the global level, but not guaranteed and
|
||||
//unlikely to work in other AMD implementations.
|
||||
setTimeout(function () {
|
||||
main(undef, deps, callback, relName);
|
||||
}, 4);
|
||||
}
|
||||
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* Just drops the config on the floor, but returns req in case
|
||||
* the config return value is used.
|
||||
*/
|
||||
req.config = function (cfg) {
|
||||
return req(cfg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose module registry for debugging and tooling
|
||||
*/
|
||||
requirejs._defined = defined;
|
||||
|
||||
define = function (name, deps, callback) {
|
||||
if (typeof name !== 'string') {
|
||||
throw new Error('See almond README: incorrect module build, no module name');
|
||||
}
|
||||
|
||||
//This module may not have dependencies
|
||||
if (!deps.splice) {
|
||||
//deps is not an array, so probably means
|
||||
//an object literal or factory function for
|
||||
//the value. Adjust args.
|
||||
callback = deps;
|
||||
deps = [];
|
||||
}
|
||||
|
||||
if (!hasProp(defined, name) && !hasProp(waiting, name)) {
|
||||
waiting[name] = [name, deps, callback];
|
||||
}
|
||||
};
|
||||
|
||||
define.amd = {
|
||||
jQuery: true
|
||||
};
|
||||
}());
|
||||
@@ -1,56 +0,0 @@
|
||||
$navbar-height: 40px;
|
||||
$main-color: #875A7B;
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Web Client */
|
||||
.o_web_client {
|
||||
font-family: sans-serif;
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template-rows: $navbar-height auto;
|
||||
}
|
||||
|
||||
/* Navbar */
|
||||
.o_navbar {
|
||||
background-color: $main-color;
|
||||
color: white;
|
||||
display: flex;
|
||||
line-height: $navbar-height;
|
||||
|
||||
span.title {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
display: inline-flex;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
li {
|
||||
margin: 0 4px;
|
||||
font-size: 20px;
|
||||
&:hover {
|
||||
background-color: darken($main-color, 10);
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 0 5px;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Odoo Web Core Demo</title>
|
||||
<script src="almond.js"></script>
|
||||
<script src="main.js"></script>
|
||||
<link rel="stylesheet" href="app.css">
|
||||
<script>
|
||||
require('main');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Env } from "../../src/core/Widget";
|
||||
import QWeb from "../../src/core/qweb_vdom";
|
||||
import Router from "./services/router";
|
||||
import actions from "./services/actions";
|
||||
|
||||
const qweb = new QWeb();
|
||||
const router = new Router();
|
||||
|
||||
const env: Env = {
|
||||
qweb: qweb,
|
||||
services: { router, actions }
|
||||
};
|
||||
|
||||
export default env;
|
||||
@@ -1,9 +0,0 @@
|
||||
///<amd-module name="main" />
|
||||
|
||||
import RootWidget from "./widgets/RootWidget";
|
||||
import env from "./env";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async function() {
|
||||
const rootWidget = new RootWidget(env);
|
||||
await rootWidget.mount(document.body);
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
import CRM from "../widgets/CRM";
|
||||
import Discuss from "../widgets/Discuss";
|
||||
import Widget from "../../../src/core/Widget";
|
||||
|
||||
export interface Action {
|
||||
id: number;
|
||||
title: string;
|
||||
Widget: typeof Widget;
|
||||
default?: boolean;
|
||||
}
|
||||
|
||||
const actions: Action[] = [
|
||||
{ id: 1, title: "Discuss", Widget: Discuss, default: true },
|
||||
{ id: 2, title: "CRM", Widget: CRM }
|
||||
];
|
||||
|
||||
export default actions;
|
||||
@@ -1,64 +0,0 @@
|
||||
export type Route = string;
|
||||
export type Query = { [key: string]: string };
|
||||
|
||||
export interface RouteInfo {
|
||||
route: Route;
|
||||
query: Query;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export default class Router {
|
||||
listeners: { owner: any; callback: (info: RouteInfo) => void }[] = [];
|
||||
|
||||
constructor() {
|
||||
window.addEventListener("popstate", this.onUrlChange.bind(this));
|
||||
}
|
||||
|
||||
onUrlChange() {
|
||||
const info = this.getRouteInfo();
|
||||
for (let listener of this.listeners) {
|
||||
listener.callback.call(listener.owner, info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Route} route relative route: for example, /web/
|
||||
* @param {Query} query
|
||||
*/
|
||||
navigate(info: Partial<RouteInfo>) {
|
||||
const currentRouteInfo = this.getRouteInfo();
|
||||
const route = info.route || currentRouteInfo.route;
|
||||
const query = info.query || {};
|
||||
const title = info.title || currentRouteInfo.title;
|
||||
const url = this.formatURL(route, query);
|
||||
window.history.pushState(null, title, url);
|
||||
}
|
||||
register(owner: any, callback: (info: RouteInfo) => void) {
|
||||
this.listeners.push({ owner, callback });
|
||||
}
|
||||
|
||||
unregister(owner: any) {
|
||||
this.listeners = this.listeners.filter(l => l.owner !== owner);
|
||||
}
|
||||
|
||||
formatURL(route: Route, query: Query): string {
|
||||
let url = route;
|
||||
let hasHash = false;
|
||||
for (let key in query) {
|
||||
url = url + (hasHash ? "&" : "#");
|
||||
url = url + `${key}=${query[key]}`;
|
||||
hasHash = true;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
getRouteInfo(): RouteInfo {
|
||||
const route = window.location.pathname.slice(1);
|
||||
const query = {};
|
||||
for (let part of window.location.hash.slice(1).split("?")) {
|
||||
let [key, value] = part.split("=");
|
||||
query[key] = value;
|
||||
}
|
||||
return { route, query, title: document.title };
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import Widget from "../../../src/core/Widget";
|
||||
|
||||
const template = `
|
||||
<div class="o_crm">
|
||||
<span>CRM!!!!</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class Discuss extends Widget {
|
||||
name = "crm";
|
||||
template = template;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import Widget from "../../../src/core/Widget";
|
||||
|
||||
const template = `
|
||||
<div>
|
||||
<button t-on-click="increment(-1)">-</button>
|
||||
<span style="font-weight:bold">Value: <t t-esc="state.counter"/></span>
|
||||
<button t-on-click="increment(1)">+</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class Counter extends Widget {
|
||||
name = "counter";
|
||||
template = template;
|
||||
state = {
|
||||
counter: 0
|
||||
};
|
||||
|
||||
constructor(parent: Widget | null, props: {initialState?: number}) {
|
||||
super(parent);
|
||||
this.state.counter = props.initialState || 0;
|
||||
}
|
||||
|
||||
increment(delta: number) {
|
||||
this.updateState({ counter: this.state.counter + delta });
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import Widget from "../../../src/core/Widget";
|
||||
import Counter from "./Counter";
|
||||
|
||||
const template = `
|
||||
<div class="o_discuss">
|
||||
<span>Root Widget</span>
|
||||
<button t-on-click="resetCounter">Reset</button>
|
||||
<button t-on-click="resetCounterAsync">Reset in 3s</button>
|
||||
<button t-on-click="toggle">Toggle Counter</button>
|
||||
<input/>
|
||||
<t t-if="state.validcounter">
|
||||
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>
|
||||
</t>
|
||||
<t t-else="1">
|
||||
<t t-widget="Counter" t-ref="counter" t-props="{initialState:7}"/>
|
||||
</t>
|
||||
<div ref="target"/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class Discuss extends Widget {
|
||||
name = "discuss";
|
||||
template = template;
|
||||
widgets = { Counter };
|
||||
state = { validcounter: true };
|
||||
|
||||
resetCounter(ev: MouseEvent) {
|
||||
this.refs.counter.updateState({ counter: 3 });
|
||||
}
|
||||
|
||||
resetCounterAsync(ev: MouseEvent) {
|
||||
setTimeout(() => {
|
||||
this.refs.counter.updateState({ counter: 3 });
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.updateState({ validcounter: !this.state.validcounter });
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import Widget from "../../../src/core/Widget";
|
||||
import { Action } from "../services/actions";
|
||||
|
||||
const template = `
|
||||
<div class="o_navbar">
|
||||
<span class="title">Odoo</span>
|
||||
<ul>
|
||||
<li t-foreach="env.services.actions" t-as="action">
|
||||
<a t-att-href="getUrl(action)"><t t-esc="action.title"/></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class Navbar extends Widget {
|
||||
name = "navbar";
|
||||
template = template;
|
||||
|
||||
getUrl(action: Action) {
|
||||
const action_id = action.id;
|
||||
return this.env.services.router.formatURL("web", { action_id });
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import Widget, { Env } from "../../../src/core/Widget";
|
||||
import Navbar from "./Navbar";
|
||||
import { Action } from "../services/actions";
|
||||
|
||||
const template = `
|
||||
<div class="o_web_client">
|
||||
<t t-widget="Navbar"/>
|
||||
<div class="o_content">
|
||||
<t t-widget="Content"/>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class RootWidget extends Widget {
|
||||
name = "root";
|
||||
template = template;
|
||||
widgets = { Navbar };
|
||||
state = { validcounter: true };
|
||||
|
||||
constructor(env: Env) {
|
||||
super(env);
|
||||
this.setMainWidget();
|
||||
}
|
||||
|
||||
mounted() {
|
||||
this.env.services.router.register(this, this.onUrlChange);
|
||||
}
|
||||
|
||||
setMainWidget() {
|
||||
const action = this.getAction();
|
||||
(<any>this.widgets).Content = action.Widget;
|
||||
}
|
||||
|
||||
onUrlChange() {
|
||||
this.setMainWidget();
|
||||
// notice that this can only be safely done because the root widget is
|
||||
// mounted now.
|
||||
this.render();
|
||||
}
|
||||
|
||||
getAction(): Action {
|
||||
const routeInfo = this.env.services.router.getRouteInfo();
|
||||
const actionID = parseInt(routeInfo.query.action_id);
|
||||
let actions: Action[] = this.env.services.actions;
|
||||
let action = actions.find(a => a.id === actionID);
|
||||
if (!action) {
|
||||
action = actions.find(a => a.default === true);
|
||||
if (!action) {
|
||||
throw new Error("No valid action!");
|
||||
}
|
||||
}
|
||||
return action;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user