Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ module.exports = function (sails) {
modelName: req.params.model,
modelSchema: modelSchema,
cms: model.cms || {},
models: models
models: models,
primaryKey: model.primaryKey
}));
return res.ok(html);
});
Expand Down Expand Up @@ -95,15 +96,17 @@ module.exports = function (sails) {
delete modelSchema.updatedAt;

//FindOne model
sails.models[req.params.model]
model = sails.models[req.params.model]
model
.findOne(req.params.modelId)
.exec(function(err, model){
if(err) return res.negotiate(err);
.exec(function(err, item){
if(err || (item == undefined)) return res.negotiate(err);
var jadeFn = jadeAsync.compileFile(path.join(__dirname, 'views/model.edit.jade'));
jadeFn(extendJadeLocals({
modelName: req.params.model,
modelSchema: modelSchema,
model:model
item:item,
primaryKey:model.primaryKey
})).done(function (html) {
return res.send(html);
});
Expand Down Expand Up @@ -144,7 +147,7 @@ module.exports = function (sails) {

//FindOne model
sails.models[req.params.model]
.destroy(parseInt(req.params.modelId, 10))
.destroy(req.params.modelId)
.exec(function(err, model){
if(err) return res.negotiate(err);
return res.redirect('/admin/' + req.params.model);
Expand Down
9 changes: 9 additions & 0 deletions jade-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ module.exports = function(sails) {
value: value
});
}
//if is LONGTEXT or MEDIUMTEXT or TEXT
} else if(attr.type == 'longtext' || attr.type == 'mediumtext' || attr.type == 'text') {
return jadeFormPartials({
element: 'textarea',
name: name,
attr: attr,
value: value
});


//if is DATE or DATETIME
} else if(attr.type == 'date' || attr.type == 'datetime') {
return jadeFormPartials({
Expand Down
10 changes: 10 additions & 0 deletions partials/forms.jade
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ mixin input(name, attr, type, value)

step=(attr.type === 'float'? "any" : undefined)
)

mixin textarea(name, attr, value)
fieldset.form-group
label.capitalize(for='#{name}') #{name}
textarea.form-control(
name="#{name}",
required=(attr.required ? "required" : undefined)
)=value

mixin select(name, attr, options, value)
fieldset.form-group
Expand Down Expand Up @@ -44,6 +52,8 @@ mixin date(name, attr, value)
case element
when 'input'
+input(name, attr, type, value)
when 'textarea'
+textarea(name, attr, value)
when 'datetime'
+datetime(name, attr, value)
when 'date'
Expand Down
2 changes: 1 addition & 1 deletion views/model.create.jade
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mixin model-create-form
p.text-warning It appears that your #{modelName} schema is empty. Please specify some attributes.
p For more information refer to the <a href="http://sailsjs.org/documentation/concepts/models-and-orm/attributes">sails documentation on Model's attributes.</a>
else
form(action="/admin/#{modelName}/store", method="POST")
form(action="/admin/#{modelName}/store", method="POST", id="model-form" )
each attr, attrName in modelSchema
div !{helpers.form.getElement(attrName, attr)}

Expand Down
4 changes: 2 additions & 2 deletions views/model.edit.jade
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ block content
h2.text-capitalize Edit #{modelName}
.row
.col-md-8.col-centered
form(action="/admin/#{modelName}/update/#{model.id}", method="POST")
form(action="/admin/#{modelName}/update/#{item[primaryKey]}", method="POST", id="model-form")
each attr, attrName in modelSchema
div !{helpers.form.getElement(attrName, attr, model[attrName])}
div !{helpers.form.getElement(attrName, attr, item[attrName])}

button.btn.btn-primary(type="submit") Save