Created
December 1, 2012 23:34
-
-
Save brianjmiller/4185943 to your computer and use it in GitHub Desktop.
ML with total
This file contains hidden or 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
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