Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Created December 1, 2012 23:34
Show Gist options
  • Save brianjmiller/4185943 to your computer and use it in GitHub Desktop.
Save brianjmiller/4185943 to your computer and use it in GitHub Desktop.
ML with total
var Clazz = Y.namespace("OCLC.W.Cart.ML.Lines").Base = Y.Base.create(
"oclc-cart-ml-lines-base",
Y.ModelList,
[],
{
model: Y.OCLC.W.Cart.M.Line.Base,
initializer: function () {
Y.log("initializer", "debug", Clazz.NAME);
this.after(
[
Y.OCLC.W.Cart.M.Line.Base.NAME + ":subtotalChange",
"add",
"reset",
"remove"
],
function (e) {
Y.log("initializer - after model causing total change", "debug", Clazz.NAME);
this.calculateTotal();
},
this
);
this.calculateTotal();
},
destructor: function () {
Y.log("destructor", "debug", Clazz.NAME);
},
calculateTotal: function () {
Y.log("calculateTotal", "debug", Clazz.NAME);
var total = 0;
this.each(
function (m) {
total += m.get("subtotal");
}
);
this.set("total", total);
}
},
{
ATTRS: {
total: {
value: 0,
validator: Y.Lang.isNumber
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment