Skip to content
Snippets Groups Projects
Commit fcc13046 authored by Bertrand PINEL's avatar Bertrand PINEL
Browse files

Merge branch 'validatedForm'

Should be completely working but just with the required constraint
parents 9210c5dd efef8779
No related branches found
No related tags found
No related merge requests found
<button
class="btn btn-default"
class="btn btn-primary"
onclick={{action "sendAction" "delete" record}}>
Delete
</button>
......@@ -46,6 +46,14 @@ module.exports = {
addLineToFile(this, configPath, /'use strict';/, proxy);
addLineToFile(this, configPath, /when it is created/, "\t\tproxy: usingProxy(),");
let validatedFormConfig = '\t"ember-validated-form": {\n\t\tlabel: {\n\t\t\tsubmit: "label.save"\n\t\t},\n'+
'\t\tcss: {\n\t\t\tgroup: "form-group",\n\t\t\tradio: "radio",\n\t\t\tcontrol: "form-control",\n'+
'\t\t\tlabel: "col-form-label",\n\t\t\thelp: "small form-text text-danger",'+
'\n\t\t\thint: "small form-text text-muted",\n\t\t\tcheckbox: "checkbox",\n\t\t\tbutton: "btn btn-default",'+
'\n\t\t\tsubmit: "btn btn-primary",\n\t\t\tloading: "loading",\n\t\t\tvalid: "is-valid",'+
'\n\t\t\terror: "is-invalid"\n\t\t}\n\t},\n';
addLineToFile(this, configPath, /let ENV = {/, validatedFormConfig);
// Add import of ember_aws_ehipster.css to apps.css
let stylePath = (options.dummy) ? "tests/dummy/app/styles/app.css" : "app/styles/app.css";
let importcss = "@import 'ember-aws-ehipster.css';\n";
......
......@@ -2,10 +2,13 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { A } from '@ember/array';
import EmberObject from '@ember/object';
import <%=capitalizeEntityName%>Validations from "../../validations/<%=singularEntityName%>";
import { task } from "ember-concurrency";
export default Controller.extend({
isAddingEntry: false,
newEntry: EmberObject.create({<%=controllerInitEntity%>}),
<%=capitalizeEntityName%>Validations,
<%=controllerModelTable%>
......@@ -22,5 +25,12 @@ export default Controller.extend({
console.log('record is '+ record);
record.destroyRecord();
}
}
},
submitEntry: task(function*(model) {
yield model.save();
let newEntity = this.store.createRecord('<%=singularEntityName%>',yield model.get('data'));
yield newEntity.save();
console.log("new entry of id "+newEntity.get('id')+" created");
this.set('addEntryModal', false);
})
});
\ No newline at end of file
......@@ -22,9 +22,5 @@
{{#modal.body}}
<%=templateEntityForm%>
{{/modal.body}}
{{#modal.footer}}
{{#bs-button onClick=(action modal.close)}}Cancel{{/bs-button}}
{{#bs-button type="success" onClick=(action modal.submit)}}Save{{/bs-button}}
{{/modal.footer}}
{{/bs-modal}}
</div>
\ No newline at end of file
......@@ -57,6 +57,7 @@ module.exports = {
locals(options) {
let camelizedName = stringUtils.camelize(options.entity.name);
let capitizeName = stringUtils.capitalize(camelizedName);
/*
for (let name in entityOptions) {
......@@ -76,6 +77,7 @@ module.exports = {
*/
return {
singularEntityName: camelizedName,
capitalizeEntityName: capitizeName,
entityValidation: entityValidation(camelizedName, options.entity.options),
entityModel: entityModel(camelizedName, options.entity.options),
mirageFactory: mirageFactory(camelizedName, options.entity.options),
......@@ -160,7 +162,8 @@ function addLineToFile(ctx, filePath, markerString, addedLine) {
};
function templateEntityForm(name, options) {
let form = ['{{#bs-form formLayout="vertical" model=newEntry onSubmit=(action "submit") as |form|}}'];
let capitalizeName = stringUtils.capitalize(name);
let form = ['{{#validated-form model = (changeset newEntry '+capitalizeName+'Validations) on-submit = (perform submitEntry) as |f|}}'];
let attributes = [];
for (var prop in options) {
let type = options[prop].split(':')[0];
......@@ -168,18 +171,17 @@ function templateEntityForm(name, options) {
switch (type) {
case "string":
case "number":
form.push('{{form.element controlType="text" label=\"' + prop + '\" property=\"'+ prop + '\" value=' +
prop + ' onChange=(action (mut ' + prop + ')) placeholder=\"' + prop + '\"}}');
form.push('{{f.input label="'+prop+'" name="'+prop+'" }}');
break;
case "boolean":
form.push('{{form.element controlType="checkbox" label=\"' + prop + '\" property=\"'+ prop + '\" value=' +
prop + ' onChange=(action (mut ' + prop + ')) placeholder=\"' + prop + '\"}}');
form.push('\t\t{{f.input type="checkbox" label="'+prop+'" name="'+prop+'" }}');
break;
case "date":
form.push('<div class="row form-group"><label class="col-form-label col-md-4">' + prop +
'</label>{{pikaday-input useUTC=true format="DD/MM/YYYY" onSelection=(action (mut ' + prop + '))}}</div>');
form.push('\t\t{{#f.input label="'+prop+'" name="'+prop+'" as |fi|}}\n' +
'\t\t\t{{pikaday-input useUTC=true format="DD/MM/YYYY" onSelection=fi.update}}\n' +
'\t\t{{/f.input}}');
break;
case 'belongs-to':
......@@ -195,7 +197,7 @@ function templateEntityForm(name, options) {
break;
}
}
form.push("{{/bs-form}}");
form.push('\t\t{{f.submit class="btn btn-primary" label="Save"}}\n\t{{/validated-form}}');
return form.join('\n');
};
......
{
"name": "ember-aws-ehipster",
"version": "0.3.9",
"version": "0.3.17",
"description": "Attempt to build a complete web application using serverless architecture on AWS",
"keywords": [
"ember-addon",
......@@ -36,17 +36,17 @@
"ember-pikaday": "^2.3.0",
"jhipster-core": "^3.4.0",
"shelljs": "^0.8.2",
"ember-validated-form": "^2.0.0-alpha.3",
"ember-validated-form": "^1.4.2",
"ember-concurrency": "^0.8.26",
"ember-changeset": "^1.6.0",
"ember-changeset-validations": "^1.3.3"
"ember-changeset-validations": "^1.3.3",
"ember-cli-string-helpers": "^2.0.0",
"ember-composable-helpers": "^2.1.0"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^3.0.0",
"ember-auto-import": "^1.2.15",
"ember-changeset": "^1.6.0",
"ember-changeset-validations": "^1.3.3",
"ember-cli": "~3.1.4",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.2.1",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment