Commit 64584dbb authored by Boris Kocherov's avatar Boris Kocherov

fix jslint

parent 54c2a87e
......@@ -6,12 +6,12 @@
function decodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~1/g,'/').replace(/~0/g,'~');
return _str.replace(/~1/g, '/').replace(/~0/g, '~');
}
function encodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~/g,'~0').replace(/\//g,'~1');
return _str.replace(/~/g, '~0').replace(/\//g, '~1');
}
function getDocumentType(doc) {
......@@ -74,6 +74,56 @@
return input;
}
function addSubForm(options) {
var element = options.element,
g = options.gadget,
property_name,
parent_path = options.path || element.name,
scope,
input_element;
scope = parent_path + Math.random().toString(36).substr(2, 9);
if (options.parent_type !== "array") {
property_name = options.property_name;
if (!property_name) {
input_element = element.parentNode.querySelector("input[type='text']");
property_name = input_element.value;
}
if (!property_name) {
// XXX notify user
// you can't create property without property_name
return RSVP.Queue();
}
if (g.props.objects[parent_path].hasOwnProperty(property_name) && g.props.objects[parent_path][property_name] !== "") {
// XXX notify user
// you can't create property with existed property_name
return RSVP.Queue();
}
if (input_element) {
input_element.value = "";
}
}
return g.declareGadget('gadget_json_generated_form.html', {scope: scope})
.push(function (form_gadget) {
form_gadget.element.setAttribute("data-json-parent", parent_path);
if (options.parent_type === "array") {
g.props.arrays[parent_path] = 1;
} else {
g.props.objects[parent_path][property_name] = scope;
form_gadget.element.setAttribute("data-json-property-name", property_name);
}
// add to end of list
// element.parentNode.appendChild(form_gadget.element);
return form_gadget.renderForm({
schema: options.schema_part,
document: options.default_dict,
display_label: options.parent_type !== "array",
scope: scope
});
}); // XXX focus on first element subform
}
function render_array(gadget, json_field, default_array, root, path) {
var queue = RSVP.Queue(),
div,
......@@ -125,7 +175,7 @@
div.appendChild(div_input);
if (default_array) {
for (i = 0; i < default_array.length; i++) {
for (i = 0; i < default_array.length; i = i + 1) {
queue
.push(
addSubForm.bind(gadget, {
......@@ -141,7 +191,7 @@
}
}
root.appendChild(div);
// todo add failback rendering if default_array not array
// XXX add failback rendering if default_array not array
// input = render_textarea(json_field, default_value, "array");
return queue;
}
......@@ -225,7 +275,8 @@
json_field,
default_value,
div_input,
first_path + '/');
first_path + '/'
);
div.setAttribute("data-json-path", first_path + '/');
div.setAttribute("data-json-type", json_field.type);
}
......@@ -238,7 +289,8 @@
json_field,
default_value,
div_input,
first_path + '/');
first_path + '/'
);
});
div.setAttribute("data-json-path", first_path + '/');
}
......@@ -282,13 +334,13 @@
.push(function (z) {
return z.getContent()
.push(function (value) {
var key = value[scope];
used_properties[key] = "";
var property_name = value[scope];
used_properties[property_name] = "";
return addSubForm({
gadget: g,
property_name: key,
property_name: property_name,
path: path,
schema_part: json_field.properties[key]
schema_part: json_field.properties[property_name]
});
})
.push(function (element) {
......@@ -300,12 +352,12 @@
rerender: function () {
return g.getDeclaredGadget(scope)
.push(function (g) {
var key,
var property_name,
item_list = [["add property", "add property"]];
for (key in json_field.properties) {
if (json_field.properties.hasOwnProperty(key) &&
!used_properties.hasOwnProperty(key)) {
item_list.push([key, key]);
for (property_name in json_field.properties) {
if (json_field.properties.hasOwnProperty(property_name) &&
!used_properties.hasOwnProperty(property_name)) {
item_list.push([property_name, property_name]);
}
}
return g.render({
......@@ -333,7 +385,8 @@
function addAdditional(schema) {
var div,
div_input,
input;
input,
property_name;
div = document.createElement("div");
div.setAttribute("class", "subfield");
......@@ -373,18 +426,18 @@
div.appendChild(div_input);
for (key in default_dict) {
if (default_dict.hasOwnProperty(key) && !used_properties.hasOwnProperty(key)) {
used_properties[key] = "";
for (property_name in default_dict) {
if (default_dict.hasOwnProperty(property_name) && !used_properties.hasOwnProperty(property_name)) {
used_properties[property_name] = "";
queue
.push(
addSubForm.bind(g, {
gadget: g,
property_name: key,
property_name: property_name,
path: path,
element: input,
schema_part: schema,
default_dict: default_dict[key]
default_dict: default_dict[property_name]
})
)
.push(element_append);
......@@ -461,7 +514,7 @@
}
function getFormValuesAsJSONDict(g) {
var multi_level_dict = {"":{}},
var multi_level_dict = {"": {}},
scope,
options = g.props,
array,
......@@ -472,12 +525,12 @@
queue = RSVP.Queue();
function convertOnMultiLevel(d, key, value) {
var i,
var ii,
kk,
key_list = key.split("/");
for (i = 0; i < key_list.length; i += 1) {
kk = decodeJsonPointer(key_list[i]);
if (i === key_list.length - 1) {
for (ii = 0; ii < key_list.length; ii += 1) {
kk = decodeJsonPointer(key_list[ii]);
if (ii === key_list.length - 1) {
if (value === undefined) {
return d[kk];
} else {
......@@ -514,12 +567,12 @@
return gadget.getContent();
})
.push(function (jdict) {
var array = convertOnMultiLevel(multi_level_dict, parent_scope);
if (!(array instanceof Array)) {
array = [];
convertOnMultiLevel(multi_level_dict, parent_scope, array);
var arr = convertOnMultiLevel(multi_level_dict, parent_scope);
if (!(arr instanceof Array)) {
arr = [];
convertOnMultiLevel(multi_level_dict, parent_scope, arr);
}
array.push(jdict);
arr.push(jdict);
});
}
......@@ -528,7 +581,7 @@
array = g.element.querySelector("div[data-json-path='" + scope + "']")
.querySelectorAll("div[data-json-parent='" + scope + "']");
len = array.length;
for (i=0; i < len; i++) {
for (i = 0; i < len; i = i + 1) {
getContentAndPushArray(
array[i].getAttribute('data-gadget-scope'),
// slice remove concluding '/'
......@@ -554,7 +607,7 @@
return queue
.push(function () {
var json_dict = {},
key;
k;
g.props.inputs.forEach(function (input) {
if (input.name === "" || input.value !== "") {
if (input.type === 'number') {
......@@ -574,65 +627,15 @@
}
}
});
for (key in json_dict) {
if (json_dict.hasOwnProperty(key)) {
convertOnMultiLevel(multi_level_dict, key, json_dict[key]);
for (k in json_dict) {
if (json_dict.hasOwnProperty(k)) {
convertOnMultiLevel(multi_level_dict, k, json_dict[k]);
}
}
return multi_level_dict[""];
});
}
function addSubForm(options) {
var element = options.element,
g = options.gadget,
property_name,
parent_path = options.path || element.name,
scope,
input_element;
scope = parent_path + Math.random().toString(36).substr(2, 9);
if (options.parent_type !== "array") {
property_name = options.property_name;
if (!property_name) {
input_element = element.parentNode.querySelector("input[type='text']");
property_name = input_element.value;
}
if (!property_name) {
// TODO notify user
// you can't create property without property_name
return RSVP.Queue();
}
if (g.props.objects[parent_path].hasOwnProperty(property_name) && g.props.objects[parent_path][property_name] !== "") {
// TODO notify user
// you can't create property with existed property_name
return RSVP.Queue();
}
if (input_element) {
input_element.value = "";
}
}
return g.declareGadget('gadget_json_generated_form.html', {scope: scope})
.push(function (form_gadget) {
form_gadget.element.setAttribute("data-json-parent", parent_path);
if (options.parent_type === "array") {
g.props.arrays[parent_path] = 1;
} else {
g.props.objects[parent_path][property_name] = scope;
form_gadget.element.setAttribute("data-json-property-name", property_name);
}
// add to end of list
// element.parentNode.appendChild(form_gadget.element);
return form_gadget.renderForm({
schema: options.schema_part,
document: options.default_dict,
display_label: options.parent_type !== "array",
scope: scope
});
}); // TODO focus on first element subform
}
function getSubGadgetElement(g, scope) {
return g.element.querySelector("div[data-gadget-scope='" + scope + "']");
}
......@@ -662,9 +665,9 @@
if (objects.hasOwnProperty(parent)) {
parent = objects[parent];
if (parent.hasOwnProperty(options.new_name)) {
throw Error("property already exist");
throw new Error("property already exist");
}
// TODO validate property if property pattern
// XXX validate property if property pattern
for (property_name in parent) {
if (parent.hasOwnProperty(property_name) && parent[property_name] === options.scope) {
delete parent[property_name];
......@@ -672,7 +675,7 @@
return options.new_name;
}
}
throw Error("gadget not found for renaming");
throw new Error("gadget not found for renaming");
}
})
.declareMethod("rename", function (new_name, event) {
......@@ -688,7 +691,7 @@
return g.element.setAttribute('data-json-property-name', new_name);
})
.push(undefined, function (error) {
// TODO notify user
// XXX notify user
event.srcElement.value = name;
event.srcElement.focus();
});
......@@ -755,8 +758,8 @@
})
.push(function (ret) {
var loadschema_gadget = ret[0],
json_dict = ret[1];
return loadschema_gadget.validateJSON(schema_url, json_dict);
json_d = ret[1];
return loadschema_gadget.validateJSON(schema_url, json_d);
})
.push(function (validation) {
var index,
......
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