Commit f36630f9 authored by Boris Kocherov's avatar Boris Kocherov

improve gadget_complex_demo_form.js

parent ea3510f6
...@@ -3,33 +3,78 @@ ...@@ -3,33 +3,78 @@
(function (window, rJS, jIO) { (function (window, rJS, jIO) {
"use strict"; "use strict";
function transform_olap_dimensions(g, dimensions) { function transform_olap_dimensions(g, dimensions) {
var dimension; var dimension,
hierarchies,
i;
for (dimension in dimensions) { for (dimension in dimensions) {
if (dimensions.hasOwnProperty(dimension)) { 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) return gadget.getDeclaredGadget(scope)
.push(function (g) { .push(function (g) {
return g.render({ 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) rJS(window)
.ready(function (g) { .ready(function (g) {
g.props = {}; g.props = {};
g.props.dimensions = { g.props.hierarchies = {};
g.props.axes = [];
transform_olap_dimensions(g, {
"Time": [ "Time": [
{title: 'Year', const: '[Time].[Time].[Year]'}, {title: 'Year', const: '[Time].[Time].[Year]'},
{title: 'Quarter', const: '[Time].[Time].[Quarter]'} {title: 'Quarter', const: '[Time].[Time].[Quarter]'}
...@@ -39,31 +84,19 @@ ...@@ -39,31 +84,19 @@
{title: 'Product Department', const: '[Product].[Products].[Product Department]'}, {title: 'Product Department', const: '[Product].[Products].[Product Department]'},
{title: 'Product Category', const: '[Product].[Products].[Product Category]'} {title: 'Product Category', const: '[Product].[Products].[Product Category]'}
] ]
});
g.state = {
columns: '[]',
rows: '[]'
}; };
g.props.dimensions = [ updateTextContent(g);
{title: 'Year', const: '[Time].[Time].[Year]'}, return new RSVP.Queue()
{title: 'Quarter', const: '[Time].[Time].[Quarter]'}, .push(function () {
{title: 'Product Family', const: '[Product].[Products].[Product Family]'}, return RSVP.all([
{title: 'Product Department', const: '[Product].[Products].[Product Department]'}, render_form(g, "columns", generate_schema(g, "columns", "columns:"), []),
{title: 'Product Category', const: '[Product].[Products].[Product Category]'} render_form(g, "rows", generate_schema(g, "rows", "rows:"), [])
]; ]);
});
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
}
})
]);
}) })
.allowPublicAcquisition("notifyValid", function (arr, scope) { .allowPublicAcquisition("notifyValid", function (arr, scope) {
}) })
...@@ -78,15 +111,35 @@ ...@@ -78,15 +111,35 @@
}) })
.push(function (ret) { .push(function (ret) {
var z = {}; var z = {};
z[scope] = ret; z[scope] = JSON.stringify(ret);
return gadget.changeState(z); return gadget.changeState(z);
}); });
} }
}) })
.onStateChange(function () { .onStateChange(function (modification_dict) {
var g = this; var g = this,
document.getElementById("json_document_content").textContent = scope,
JSON.stringify(g.state, null, 2); 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)); }(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