Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rjs_json_form
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Rafael Monnerat
rjs_json_form
Commits
47f0cb25
Commit
47f0cb25
authored
Feb 25, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove slapos code
parent
363830cf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
103 deletions
+23
-103
gadget_json_generated_form.js
gadget_json_generated_form.js
+23
-103
No files found.
gadget_json_generated_form.js
View file @
47f0cb25
...
...
@@ -270,16 +270,6 @@
return
gadget
.
processValidation
(
json_url
);
}
function
collapseParameter
(
element
)
{
$
(
element
).
parent
().
children
(
"
div
"
).
toggle
(
300
);
if
(
$
(
element
).
hasClass
(
"
slapos-parameter-dict-key-colapse
"
))
{
$
(
element
).
removeClass
(
"
slapos-parameter-dict-key-colapse
"
);
}
else
{
$
(
element
).
addClass
(
"
slapos-parameter-dict-key-colapse
"
);
}
return
element
;
}
function
addSubForm
(
element
)
{
var
subform_json
=
JSON
.
parse
(
atob
(
element
.
value
)),
input_text
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
),
...
...
@@ -342,24 +332,6 @@
return
RSVP
.
all
(
promise_list
);
}
function
getSoftwareTypeFromForm
(
element
)
{
var
input
=
element
.
querySelector
(
"
.slapos-software-type
"
);
if
(
input
!==
undefined
&&
input
!==
null
)
{
return
input
.
value
;
}
return
""
;
}
function
getSerialisationTypeFromForm
(
element
)
{
var
input
=
element
.
querySelector
(
"
.slapos-serialisation-type
"
);
if
(
input
!==
undefined
&&
input
!==
null
)
{
return
input
.
value
;
}
return
""
;
}
rJS
(
window
)
.
declareMethod
(
"
loadJSONSchema
"
,
function
(
url
)
{
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
...
...
@@ -368,42 +340,19 @@
});
})
.
declareMethod
(
"
validateJSONForSoftwareType
"
,
function
(
schema_url
,
softwaretype
,
generated_json
)
{
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
.
push
(
function
(
gadget
)
{
return
gadget
.
validateJSONForSoftwareType
(
schema_url
,
softwaretype
,
generated_json
);
});
})
.
declareMethod
(
"
loadSoftwareJSON
"
,
function
(
url
)
{
.
declareMethod
(
'
processValidation
'
,
function
(
schema_url
,
json_dict
)
{
var
g
=
this
;
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
.
push
(
function
(
gadget
)
{
return
gadget
.
loadSoftwareJSON
(
url
);
});
return
gadget
.
validateJSON
(
schema_url
,
json_dict
);
})
.
declareMethod
(
'
processValidation
'
,
function
(
json_url
)
{
var
g
=
this
,
software_type
=
getSoftwareTypeFromForm
(
g
.
element
),
json_dict
=
getFormValuesAsJSONDict
(
g
.
element
),
serialisation_type
=
getSerialisationTypeFromForm
(
g
.
element
);
if
(
software_type
===
""
)
{
if
(
g
.
options
.
value
.
parameter
.
shared
)
{
throw
new
Error
(
"
The software type is not part of the json (
"
+
software_type
+
"
as slave)
"
);
}
throw
new
Error
(
"
The software type is not part of the json (
"
+
software_type
+
"
)
"
);
}
return
g
.
validateJSONForSoftwareType
(
json_url
,
software_type
,
json_dict
)
.
push
(
function
(
validation
)
{
var
error_index
,
parameter_hash_input
=
g
.
element
.
querySelectorAll
(
'
.parameter_hash_output
'
)[
0
],
field_name
,
div
,
divm
,
missing_index
,
missing_field_name
,
xml_output
;
missing_field_name
;
$
(
g
.
element
.
querySelectorAll
(
"
span.error
"
)).
each
(
function
(
i
,
span
)
{
span
.
textContent
=
""
;
...
...
@@ -412,15 +361,8 @@
$
(
g
.
element
.
querySelectorAll
(
"
div.error-input
"
)).
each
(
function
(
i
,
div
)
{
div
.
setAttribute
(
"
class
"
,
""
);
});
if
(
serialisation_type
===
"
json-in-xml
"
)
{
xml_output
=
jsonDictToParameterJSONInXML
(
json_dict
);
}
else
{
xml_output
=
jsonDictToParameterXML
(
json_dict
);
}
parameter_hash_input
.
value
=
btoa
(
xml_output
);
// console.log(parameter_hash_input.value);
if
(
validation
.
valid
)
{
return
xml_output
;
return
"
VALID
"
;
}
for
(
error_index
in
validation
.
errors
)
{
if
(
validation
.
errors
.
hasOwnProperty
(
error_index
))
{
...
...
@@ -527,40 +469,28 @@
})
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
g
adget
=
this
,
var
g
=
this
,
queue
;
gadget
.
options
=
options
;
g
.
options
=
options
;
if
(
!
options
.
value
)
{
options
.
value
=
{};
}
if
(
options
.
schema
)
{
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
options
.
schema
;
});
}
else
{
queue
=
g
adget
.
loadJSONSchema
(
options
.
schema_url
);
queue
=
g
.
loadJSONSchema
(
options
.
schema_url
);
}
return
queue
.
push
(
function
(
schema
)
{
console
.
log
(
schema
);
return
gadget
.
renderParameterForm
(
schema
,
{});
})
.
push
(
function
()
{
var
i
,
div_list
=
gadget
.
element
.
querySelectorAll
(
'
.slapos-parameter-dict-key > div
'
),
label_list
=
gadget
.
element
.
querySelectorAll
(
'
label.slapos-parameter-dict-key
'
);
console
.
log
(
"
Collapse paramaters
"
);
for
(
i
=
0
;
i
<
div_list
.
length
;
i
=
i
+
1
)
{
$
(
div_list
[
i
]).
hide
();
}
for
(
i
=
0
;
i
<
label_list
.
length
;
i
=
i
+
1
)
{
$
(
label_list
[
i
]).
addClass
(
"
slapos-parameter-dict-key-colapse
"
);
}
return
gadget
;
g
.
options
.
schema
=
schema
;
return
g
.
renderParameterForm
(
schema
,
options
.
value
);
})
.
push
(
function
()
{
console
.
log
(
"
FINISHED TO RENDER, RETURNING THE GADGET
"
);
return
g
adget
;
return
g
;
});
})
...
...
@@ -569,24 +499,14 @@
})
.
declareMethod
(
'
getContent
'
,
function
()
{
var
gadget
=
this
;
return
gadget
.
getElement
()
.
push
(
function
(
element
)
{
var
text_content
=
element
.
querySelector
(
'
textarea[name=text_content]
'
);
if
(
text_content
!==
null
)
{
return
"
SKIP
"
;
}
return
gadget
.
processValidation
(
gadget
.
options
.
value
.
parameter
.
json_url
);
})
.
push
(
function
(
xml_result
)
{
if
(
xml_result
===
"
SKIP
"
)
{
/* The raw parameters are already on the request */
return
{};
}
return
{
"
text_content
"
:
xml_result
};
})
.
fail
(
function
(
e
)
{
return
{};
var
g
=
this
,
json_dict
=
getFormValuesAsJSONDict
(
g
.
element
);
return
g
.
processValidation
(
g
.
options
.
schema_url
,
json_dict
)
.
push
(
function
(
status
)
{
return
{
value
:
json_dict
,
status
:
status
};
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment