@@ -18,7 +18,7 @@ $(function () {
1818 // Note these are currently all Stripe TEST product Ids and need to be updated to
1919 // the live strip product IDs
2020
21- const productToButtonNameMap = {
21+ const productToCheckboxNameMap = {
2222 [ products . AWS . stripeProductId ] : products . AWS . key ,
2323 [ products . ProSupport . stripeProductId ] : products . ProSupport . key ,
2424 [ products . RefArch . stripeProductId ] : products . RefArch . key ,
@@ -78,10 +78,10 @@ $(function () {
7878 if ( rawCart ) {
7979 const products = JSON . parse ( rawCart ) ;
8080 for ( const product of products ) {
81- const buttonName = productToButtonNameMap [ product . productId ] ;
81+ const checkboxName = productToCheckboxNameMap [ product . productId ] ;
8282
83- if ( buttonName ) {
84- $ ( '.addon-button [name="' + buttonName + '"]' ) . click ( ) ;
83+ if ( checkboxName ) {
84+ $ ( '.addon-checkbox [name="' + checkboxName + '"]' ) . prop ( 'checked' , true ) . trigger ( "change" ) ;
8585 }
8686 }
8787 }
@@ -91,43 +91,20 @@ $(function () {
9191 }
9292
9393 // Listen to Addon button clicks
94- $ ( ".addon-button " ) . on ( "click " , function ( ) {
94+ $ ( ".addon-checkbox " ) . on ( "change " , function ( ) {
9595 var updateCheckoutOptions = { } ;
9696
97- var actionType = $ ( this ) . data ( "addon-action-type" ) ;
9897 var productId = $ ( this ) . data ( "product-id" ) ;
98+ var productKey = this . name ;
9999
100- // Process the add action and switch the addon button so user can clear their selection
101- function _handleAddAction ( button ) {
102- updateCheckoutOptions [ button . name ] = true ;
103- $ ( button ) . text ( "Remove" ) ;
104- $ ( button ) . addClass ( "addon-remove-button" ) ;
105- $ ( button ) . data ( "addon-action-type" , "Remove" ) ;
100+ if ( this . checked ) {
101+ updateCheckoutOptions [ productKey ] = true ;
106102 _addToCart ( productId ) ;
107- }
108-
109- // Process the remove action and switch the addon button so user can make a selection
110- function _handleRemoveAction ( button ) {
111- updateCheckoutOptions [ button . name ] = false ;
112- $ ( button )
113- . text ( "Add to Subscription " )
114- . append (
115- "<i class='fa fa-angle-double-right fa-lg' aria-hidden='true'></i>"
116- ) ;
117- $ ( button ) . removeClass ( "addon-remove-button" ) ;
118- $ ( button ) . data ( "addon-action-type" , "Add" ) ;
103+ } else {
104+ updateCheckoutOptions [ productKey ] = false ;
119105 _removeFromCart ( productId ) ;
120106 }
121107
122- switch ( actionType ) {
123- case "Add" :
124- _handleAddAction ( this ) ;
125- break ;
126- case "Remove" :
127- _handleRemoveAction ( this ) ;
128- break ;
129- default : // Do nothing
130- }
131108 _updateCheckout ( updateCheckoutOptions ) ;
132109 } ) ;
133110
@@ -158,70 +135,11 @@ $(function () {
158135 function _updateCheckout ( newOptions ) {
159136 checkoutOptions = Object . assign ( { } , checkoutOptions , newOptions ) ;
160137
161- _updateUI ( ) ;
162138 _updatePrice ( ) ;
163139 }
164140
165- function _updateUI ( ) {
166- var support = checkoutOptions . pro_support ;
167- var refarch = checkoutOptions . setup_deployment ;
168- var compliance = checkoutOptions . setup_compliance ;
169-
170- $ ( ".grunty-sprite" ) . attr ( "data-sprite" , 0 ) ;
171- $ ( "#subscription_type" ) . val ( checkoutOptions . subscription_type ) ;
172-
173- // updates addon switch
174- $ ( "[data-switch]" + '[name="pro_support"]' ) . prop ( "checked" , support ) ;
175- $ ( "[data-switch]" + '[name="setup_deployment"]' ) . prop ( "checked" , refarch ) ;
176- $ ( "[data-switch]" + '[name="setup_compliance"]' ) . prop (
177- "checked" ,
178- compliance
179- ) ;
180-
181- if ( support ) {
182- $ ( ".grunty-sprite" ) . attr ( "data-sprite" , 2 ) ;
183- $ ( "#subscription-addon-1" ) . removeClass ( "check-list-disabled" ) ;
184- } else {
185- $ ( "#subscription-addon-1" ) . addClass ( "check-list-disabled" ) ;
186- }
187-
188- if ( refarch ) {
189- $ ( ".grunty-sprite" ) . attr ( "data-sprite" , 1 ) ;
190-
191- $ ( "#checkout-price-addon" ) . show ( ) ;
192- $ ( "#checkout-price-addon--mobile" ) . show ( ) . css ( "display" , "block" ) ;
193- $ ( ".checkout-price-view" ) . addClass ( "move-up" ) ;
194-
195- $ ( "#subscription-addon-2" ) . removeClass ( "check-list-disabled" ) ;
196- } else {
197- $ ( "#checkout-price-addon" ) . hide ( ) ;
198- $ ( "#checkout-price-addon--mobile" ) . hide ( ) ;
199- $ ( ".checkout-price-view" ) . removeClass ( "move-up" ) ;
200-
201- $ ( "#subscription-addon-2" ) . addClass ( "check-list-disabled" ) ;
202- }
203-
204- if ( compliance ) {
205- $ ( "#subscription-addon-3" ) . removeClass ( "check-list-disabled" ) ;
206-
207- // Update Refarch texts to reflect CIS selection
208- $ ( "#subscription-addon-3-text" ) . text ( "CIS Reference Architecture" ) ;
209- $ ( "#addon-text-refarch" ) . text ( "CIS Reference Architecture" ) ;
210- } else {
211- $ ( "#subscription-addon-3" ) . addClass ( "check-list-disabled" ) ;
212-
213- // Update Refarch texts to reflect CIS selection removal
214- $ ( "#subscription-addon-3-text" ) . text ( "Reference Architecture" ) ;
215- $ ( "#addon-text-refarch" ) . text ( "Reference Architecture" ) ;
216- }
217-
218- if ( support && refarch ) {
219- $ ( ".grunty-sprite" ) . attr ( "data-sprite" , 3 ) ;
220- }
221- }
222-
223141 function _updatePrice ( ) {
224- var monthlyTotal , dueNowTotal ;
142+ var monthlyTotal ;
225143
226144 switch ( checkoutOptions . subscription_type ) {
227145 case "standard" :
@@ -244,18 +162,13 @@ $(function () {
244162 monthlyTotal += pricing . subscriptions . standard . cis_compliance_price . value ;
245163 }
246164
247- dueNowTotal = monthlyTotal ;
248-
249165 if ( checkoutOptions . setup_deployment ) {
250- dueNowTotal += 4950 ;
251- $ ( "#due-monthly-block" ) . show ( ) ;
166+ $ ( '#js-one-time-total' ) . show ( ) ;
252167 } else {
253- // only show the monthly disclaimer when it differs from due now
254- $ ( "#due-monthly-block" ) . hide ( ) ;
168+ $ ( "#js-one-time-total" ) . hide ( ) ;
255169 }
256170
257- $ ( "#due-now" ) . text ( dueNowTotal . toLocaleString ( ) ) ;
258- $ ( ".monthly-total" ) . text ( monthlyTotal . toLocaleString ( ) ) ;
171+ $ ( "#js-monthly-total" ) . text ( monthlyTotal . toLocaleString ( ) ) ;
259172 }
260173
261174 _setDefaults ( ) ;
0 commit comments