Skip to content

Instantly share code, notes, and snippets.

@evilbloodydemon
Created May 14, 2012 05:38
Show Gist options
  • Select an option

  • Save evilbloodydemon/2691988 to your computer and use it in GitHub Desktop.

Select an option

Save evilbloodydemon/2691988 to your computer and use it in GitHub Desktop.
knockout view model
var MassVM = app.Class.extend({
init: function() {
this._fields = [
'lastPaid',
'paymentPeriod',
'lastTrial',
'trialPeriod',
'clickbank',
'paypal',
'notes'
];
_.each(this._fields, function(v, k) {
this[v] = ko.observable('');
this[v + 'On'] = ko.observable(false);
}, this);
this.anyChecked = ko.computed(function() {
var result = false;
_.each(this._fields, function(v, k) {
if (this[v + 'On']()) {
result = true;
}
}, this);
return result;
}, this);
this.controlsDisabled = ko.observable(false);
this.okEnabled = ko.computed(function() {
return this.anyChecked() && !this.controlsDisabled();
}, this);
this.cancelEnabled = ko.computed(function() {
return !this.controlsDisabled();
}, this);
},
getData: function() {
var result = {};
_.each(this._fields, function(v, k) {
if (this[v + 'On']()) {
result[v] = this[v]();
}
}, this);
return result;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment