Commit 630c7fb3 authored by Boris Kocherov's avatar Boris Kocherov

demo: fix demo to work with latest version gadget

parent a1c09cf7
...@@ -47,6 +47,35 @@ ...@@ -47,6 +47,35 @@
}); });
} }
function updateTextContent(g) {
return g.getDeclaredGadget("form_view")
.push(function (form_view) {
return form_view.getContent();
})
.push(function (ret) {
var valid = g.state.valid,
changed = g.state.changed;
if (typeof valid === "boolean") {
if (valid) {
valid = "form filed valid";
} else {
valid = "form filed invalid";
}
} else {
valid = "valid status unknown";
}
if (changed) {
changed = 'changed\n';
} else {
changed = '';
}
document.getElementById("json_document_content").textContent =
valid + '\n' +
changed +
JSON.stringify(ret, null, 2);
});
}
rJS(window) rJS(window)
.ready(function (g) { .ready(function (g) {
g.props = {}; g.props = {};
...@@ -85,11 +114,19 @@ ...@@ -85,11 +114,19 @@
]); ]);
}); });
}) })
.allowPublicAcquisition("notifyValid", function () { .allowPublicAcquisition("notifyValid", function (arr, scope) {
return; if (scope === "form_view") {
this.changeState({
valid: true
});
}
}) })
.allowPublicAcquisition("notifyInvalid", function () { .allowPublicAcquisition("notifyInvalid", function (arr, scope) {
return; if (scope === "form_view") {
this.changeState({
valid: false
});
}
}) })
.allowPublicAcquisition("notifyChange", function (arr, scope) { .allowPublicAcquisition("notifyChange", function (arr, scope) {
var gadget = this; var gadget = this;
...@@ -99,12 +136,11 @@ ...@@ -99,12 +136,11 @@
return g.getContent(); return g.getContent();
}) })
.push(function (ret) { .push(function (ret) {
if (ret !== gadget.props.schemas[0]) { if (ret !== gadget.props.schemas[0] &&
ret !== gadget.state.schema_url) {
return gadget.changeState({ return gadget.changeState({
schema_url: ret, schema_url: ret,
json_document: JSON.parse( json_document: gadget.state.json_document
document.getElementById("json_document_content").textContent
)
}); });
} }
}); });
...@@ -134,46 +170,48 @@ ...@@ -134,46 +170,48 @@
json_document: json_document json_document: json_document
})); }));
return RSVP.all(tasks); return RSVP.all(tasks);
})
.push(function () {
return render_document_selection_form(gadget);
}); });
} }
if (scope === "form_view") { if (scope === "form_view") {
return this.getDeclaredGadget("form_view") return gadget.changeState({
.push(function (g) { changed: true
return g.getContent(); })
}) .push(function () {
.push(function (ret) { return updateTextContent(gadget);
if (ret === undefined) {
ret = {};
}
document.getElementById("json_document_content").textContent =
JSON.stringify(ret, null, " ");
}); });
} }
return;
}) })
.onStateChange(function () { .onStateChange(function (modification) {
var g = this; var g = this,
return g.getDeclaredGadget("form_view") queue = RSVP.Queue();
.push(function (form_view) { if (modification.hasOwnProperty('json_document') ||
return form_view.render({ modification.hasOwnProperty('schema') ||
value: g.state.json_document, modification.hasOwnProperty('schema_url')) {
schema_url: g.state.schema_url queue
.push(function () {
return g.getDeclaredGadget("form_view");
}) })
.push(function () { .push(function (form_view) {
return form_view.getContent(); return form_view.render({
}) value: g.state.json_document,
.push(function (ret) { schema: g.state.schema,
if (ret === undefined) { schema_url: g.state.schema_url
ret = {};
}
g.state.json_document = ret;
document.getElementById("json_document_content").textContent =
JSON.stringify(ret, null, " ");
}); });
}); })
.push(undefined, function (error) {
console.log(error);
})
.push(function () {
return updateTextContent(g);
});
}
if (modification.hasOwnProperty('valid')) {
queue
.push(function () {
return updateTextContent(g);
});
}
return queue;
}); });
}(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