summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/site/EditSubscriptionModal.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/ui/site/EditSubscriptionModal.js')
-rw-r--r--public/assets/javascripts/ui/site/EditSubscriptionModal.js60
1 files changed, 55 insertions, 5 deletions
diff --git a/public/assets/javascripts/ui/site/EditSubscriptionModal.js b/public/assets/javascripts/ui/site/EditSubscriptionModal.js
index af3b99e..539a8ae 100644
--- a/public/assets/javascripts/ui/site/EditSubscriptionModal.js
+++ b/public/assets/javascripts/ui/site/EditSubscriptionModal.js
@@ -8,6 +8,7 @@ var EditSubscriptionModal = ModalView.extend({
fixedClose: true,
subscriber: null,
+ tempSubscriber: null,
events: {
"click [data-role='addLayouts']": 'addLayouts',
@@ -19,16 +20,62 @@ var EditSubscriptionModal = ModalView.extend({
"click [data-role=showLayoutsMenu]": "layoutsMode",
"click [data-role=showPlanMenu]": "planMode",
- "click [data-role=closeMenu]": "reset",
+ "click [data-role=closeMenu]": "resetMode",
"input [data-role=basicLayoutInput]": "updateQuantity",
"input [data-role=proLayoutInput]": "updateQuantity",
- "click [data-role=buyLayouts]": "saveLayouts",
+ "click [data-role=saveQuantity]": "saveQuantity",
"input [name=planRadio]": "updatePlan",
"click [data-role=changePlan]": "savePlan",
},
-
+
+ resetMode: function(e){
+ e.preventDefault()
+ this.$paidPlan.removeClass("editLayouts editPlan")
+ this.reset()
+ },
+
+ layoutsMode: function(e){
+ e.preventDefault()
+ this.$paidPlan.addClass("editLayouts")
+ this.tempSubscriber = defaults({}, this.subscriber)
+ this.$basicLayoutInput.val( this.subscriber.basic_layouts )
+ this.$proLayoutInput.val( this.subscriber.pro_layouts )
+ },
+ updateQuantity: function(e){
+ e.preventDefault()
+ this.tempSubscriber.basic_layouts = this.$proLayoutInput.int()
+ this.tempSubscriber.pro_layouts = this.$basicLayoutInput.int()
+
+ var plan = this.getPlan( this.tempSubscriber.plan_type )
+ this.displayTotals(this.tempSubscriber, plan)
+ },
+ saveQuantity: function(e){
+ e.preventDefault()
+ // blabla.. save
+ this.subscriber = this.tempSubscriber
+ this.resetMode()
+ },
+
+ planMode: function(e){
+ e.preventDefault()
+ this.$paidPlan.addClass("editPlan")
+ this.$planRadio.val( this.subscriber.plan_type )
+ this.tempSubscriber = defaults({}, this.subscriber)
+ },
+ updatePlan: function(e){
+ e.preventDefault()
+ var plan = this.getPlan( this.$("[name=planRadio]").val() )
+ this.displayTotals(this.tempSubscriber, plan)
+ },
+ savePlan: function(e){
+ e.preventDefault()
+ this.subscriber.plan_type = this.$("[name=planRadio]").val()
+ this.subscriber = this.tempSubscriber
+ this.resetMode()
+ },
+
initialize: function(){
// this.parent = opt.parent
this.__super__.initialize.call(this)
@@ -137,8 +184,11 @@ var EditSubscriptionModal = ModalView.extend({
},
reset: function(){
var subscriber = this.subscriber
- var plan = this.plans[ this.plan_levels[ subscriber.plan_type ] ]
- this.displayTotals(subscriber)
+ var plan = this.getPlan(subscriber.plan_type)
+ this.displayTotals(subscriber, plan)
+ },
+ getPlan: function(plan_type){
+ return this.plans[ this.plan_levels[ plan_type ] ]
},
calculateTotals: function(subscriber, plan){
var t = {}