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
Boris Kocherov
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 @@
...
@@ -270,16 +270,6 @@
return
gadget
.
processValidation
(
json_url
);
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
)
{
function
addSubForm
(
element
)
{
var
subform_json
=
JSON
.
parse
(
atob
(
element
.
value
)),
var
subform_json
=
JSON
.
parse
(
atob
(
element
.
value
)),
input_text
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
),
input_text
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
),
...
@@ -342,24 +332,6 @@
...
@@ -342,24 +332,6 @@
return
RSVP
.
all
(
promise_list
);
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
)
rJS
(
window
)
.
declareMethod
(
"
loadJSONSchema
"
,
function
(
url
)
{
.
declareMethod
(
"
loadJSONSchema
"
,
function
(
url
)
{
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
...
@@ -368,42 +340,19 @@
...
@@ -368,42 +340,19 @@
});
});
})
})
.
declareMethod
(
"
validateJSONForSoftwareType
"
,
function
(
schema_url
,
softwaretype
,
generated_json
)
{
.
declareMethod
(
'
processValidation
'
,
function
(
schema_url
,
json_dict
)
{
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
var
g
=
this
;
.
push
(
function
(
gadget
)
{
return
gadget
.
validateJSONForSoftwareType
(
schema_url
,
softwaretype
,
generated_json
);
});
})
.
declareMethod
(
"
loadSoftwareJSON
"
,
function
(
url
)
{
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
.
push
(
function
(
gadget
)
{
.
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
)
{
.
push
(
function
(
validation
)
{
var
error_index
,
var
error_index
,
parameter_hash_input
=
g
.
element
.
querySelectorAll
(
'
.parameter_hash_output
'
)[
0
],
field_name
,
field_name
,
div
,
div
,
divm
,
divm
,
missing_index
,
missing_index
,
missing_field_name
,
missing_field_name
;
xml_output
;
$
(
g
.
element
.
querySelectorAll
(
"
span.error
"
)).
each
(
function
(
i
,
span
)
{
$
(
g
.
element
.
querySelectorAll
(
"
span.error
"
)).
each
(
function
(
i
,
span
)
{
span
.
textContent
=
""
;
span
.
textContent
=
""
;
...
@@ -412,15 +361,8 @@
...
@@ -412,15 +361,8 @@
$
(
g
.
element
.
querySelectorAll
(
"
div.error-input
"
)).
each
(
function
(
i
,
div
)
{
$
(
g
.
element
.
querySelectorAll
(
"
div.error-input
"
)).
each
(
function
(
i
,
div
)
{
div
.
setAttribute
(
"
class
"
,
""
);
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
)
{
if
(
validation
.
valid
)
{
return
xml_output
;
return
"
VALID
"
;
}
}
for
(
error_index
in
validation
.
errors
)
{
for
(
error_index
in
validation
.
errors
)
{
if
(
validation
.
errors
.
hasOwnProperty
(
error_index
))
{
if
(
validation
.
errors
.
hasOwnProperty
(
error_index
))
{
...
@@ -527,40 +469,28 @@
...
@@ -527,40 +469,28 @@
})
})
.
declareMethod
(
'
render
'
,
function
(
options
)
{
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
g
adget
=
this
,
var
g
=
this
,
queue
;
queue
;
gadget
.
options
=
options
;
g
.
options
=
options
;
if
(
!
options
.
value
)
{
options
.
value
=
{};
}
if
(
options
.
schema
)
{
if
(
options
.
schema
)
{
queue
=
RSVP
.
Queue
()
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
options
.
schema
;
return
options
.
schema
;
});
});
}
else
{
}
else
{
queue
=
g
adget
.
loadJSONSchema
(
options
.
schema_url
);
queue
=
g
.
loadJSONSchema
(
options
.
schema_url
);
}
}
return
queue
return
queue
.
push
(
function
(
schema
)
{
.
push
(
function
(
schema
)
{
console
.
log
(
schema
);
g
.
options
.
schema
=
schema
;
return
gadget
.
renderParameterForm
(
schema
,
{});
return
g
.
renderParameterForm
(
schema
,
options
.
value
);
})
.
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
;
})
})
.
push
(
function
()
{
.
push
(
function
()
{
console
.
log
(
"
FINISHED TO RENDER, RETURNING THE GADGET
"
);
console
.
log
(
"
FINISHED TO RENDER, RETURNING THE GADGET
"
);
return
g
adget
;
return
g
;
});
});
})
})
...
@@ -569,24 +499,14 @@
...
@@ -569,24 +499,14 @@
})
})
.
declareMethod
(
'
getContent
'
,
function
()
{
.
declareMethod
(
'
getContent
'
,
function
()
{
var
gadget
=
this
;
var
g
=
this
,
return
gadget
.
getElement
()
json_dict
=
getFormValuesAsJSONDict
(
g
.
element
);
.
push
(
function
(
element
)
{
return
g
.
processValidation
(
g
.
options
.
schema_url
,
json_dict
)
var
text_content
=
element
.
querySelector
(
'
textarea[name=text_content]
'
);
.
push
(
function
(
status
)
{
if
(
text_content
!==
null
)
{
return
{
return
"
SKIP
"
;
value
:
json_dict
,
}
status
:
status
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
{};
});
});
});
});
...
...
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