Last active
February 17, 2016 21:28
-
-
Save green3g/f597e1987f78e48e79f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#if objectsPromise.isPending}} | |
<p>Loading...</p> | |
{{/if}} | |
{{#if objectsPromise.isResolved}} | |
{{#each objects}} | |
{{#each .}} | |
{{#if renderField(%key)}} | |
<td>{{formatValue(.)}}</td> | |
{{/if}} | |
{{/each}} | |
</tr> | |
{{/each}} | |
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const ViewModel = viewModel.extend({ | |
define: { | |
objectModel: { | |
value: null | |
}, | |
editable: { | |
type: 'boolean', | |
value: false | |
}, | |
filter: { | |
type: '*', | |
value: null | |
}, | |
group: { | |
type: 'string', | |
value: null | |
}, | |
objectsPromise: { | |
get: function() { | |
return this.attr('objectModel').findAll({ | |
filter: this.attr('filter') ? 'q=' + JSON.stringify(this.attr('filter')) : '', | |
group: this.attr('group') ? 'group=' + this.attr('group') : '' | |
}); | |
} | |
}, | |
objects: { | |
get: function(value, setAttr) { | |
this.attr('objectsPromise').then(setAttr); | |
} | |
}, | |
formSubmit: function(scope, form, event) { | |
var data = can.$(form).serializeArray(); | |
var edit_object = scope.attr('edit_object'); | |
for (var i = 0; i < data.length; i++) { | |
var newData = data[i]; | |
if (edit_object.attr(newData.name) !== newData.value) { | |
edit_object.attr(newData.name, newData.value); | |
} | |
} | |
console.log(edit_object.save()); | |
scope.attr('edit_object', null); | |
//prevent the form from submitting | |
return false; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment