Commit f36630f9 authored by Boris Kocherov's avatar Boris Kocherov

improve gadget_complex_demo_form.js

parent ea3510f6
......@@ -5,31 +5,76 @@
"use strict";
function transform_olap_dimensions(g, dimensions) {
var dimension;
var dimension,
hierarchies,
i;
for (dimension in dimensions) {
if (dimensions.hasOwnProperty(dimension)) {
hierarchies = dimensions[dimension];
for (i = 0; i < hierarchies.length; i += 1) {
hierarchies[i].dimension = dimension;
g.props.hierarchies[hierarchies[i].const] = hierarchies[i];
}
}
}
}
function generate_schema() {
function generate_schema(g, axis, title) {
console.log("render " + axis);
var used_dimensions = [],
h,
hierarchies = [],
i;
if (!g.props.axes.hasOwnProperty(axis)) {
g.props.axes[axis] = [];
}
for (i in g.props.axes) {
if (g.props.axes.hasOwnProperty(i) && i !== axis) {
used_dimensions = used_dimensions.concat(g.props.axes[i]);
}
}
for (i in g.props.hierarchies) {
if (g.props.hierarchies.hasOwnProperty(i)) {
h = g.props.hierarchies[i];
if (used_dimensions.indexOf(h.dimension) < 0) {
hierarchies.push(h);
}
}
}
return {
title: title,
type: "array",
uniqueItems: true,
items: {
oneOf: hierarchies
}
};
}
function render_form(gadget, scope, schema) {
function render_form(gadget, scope, schema, value) {
return gadget.getDeclaredGadget(scope)
.push(function (g) {
return g.render({
schema: schema
schema: schema,
value: value
});
});
}
function updateTextContent(g) {
document.getElementById("json_document_content").textContent =
JSON.stringify({
columns: JSON.parse(g.state.columns),
rows: JSON.parse(g.state.rows)
}, null, 2);
}
rJS(window)
.ready(function (g) {
g.props = {};
g.props.dimensions = {
g.props.hierarchies = {};
g.props.axes = [];
transform_olap_dimensions(g, {
"Time": [
{title: 'Year', const: '[Time].[Time].[Year]'},
{title: 'Quarter', const: '[Time].[Time].[Quarter]'}
......@@ -39,31 +84,19 @@
{title: 'Product Department', const: '[Product].[Products].[Product Department]'},
{title: 'Product Category', const: '[Product].[Products].[Product Category]'}
]
});
g.state = {
columns: '[]',
rows: '[]'
};
g.props.dimensions = [
{title: 'Year', const: '[Time].[Time].[Year]'},
{title: 'Quarter', const: '[Time].[Time].[Quarter]'},
{title: 'Product Family', const: '[Product].[Products].[Product Family]'},
{title: 'Product Department', const: '[Product].[Products].[Product Department]'},
{title: 'Product Category', const: '[Product].[Products].[Product Category]'}
];
updateTextContent(g);
return new RSVP.Queue()
.push(function () {
return RSVP.all([
render_form(g, "columns", {
title: "columns:",
type: "array",
items: {
oneOf: g.props.dimensions
}
}),
render_form(g, "rows", {
title: "rows:",
type: "array",
items: {
oneOf: g.props.dimensions
}
})
render_form(g, "columns", generate_schema(g, "columns", "columns:"), []),
render_form(g, "rows", generate_schema(g, "rows", "rows:"), [])
]);
});
})
.allowPublicAcquisition("notifyValid", function (arr, scope) {
})
......@@ -78,15 +111,35 @@
})
.push(function (ret) {
var z = {};
z[scope] = ret;
z[scope] = JSON.stringify(ret);
return gadget.changeState(z);
});
}
})
.onStateChange(function () {
var g = this;
document.getElementById("json_document_content").textContent =
JSON.stringify(g.state, null, 2);
.onStateChange(function (modification_dict) {
var g = this,
scope,
mod,
i,
dimension,
used_dimensions;
for (scope in modification_dict) {
if (modification_dict.hasOwnProperty(scope)) {
used_dimensions = [];
mod = JSON.parse(modification_dict[scope]);
for (i = 0; i < mod.length; i += 1) {
dimension = g.props.hierarchies[mod[i]].dimension;
used_dimensions.push(dimension);
}
g.props.axes[scope] = used_dimensions;
}
}
updateTextContent(g);
// if return used here then rendering cancel
RSVP.all([
render_form(g, "columns", generate_schema(g, "columns", "columns:")),
render_form(g, "rows", generate_schema(g, "rows", "rows:"))
]);
});
}(window, rJS, jIO));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment