diff --git a/js/commerce_discount.js b/js/commerce_discount.js index e3dd0cd..19579b8 100644 --- a/js/commerce_discount.js +++ b/js/commerce_discount.js @@ -62,5 +62,47 @@ return Drupal.t('Incompatible with all'); } }); + $('fieldset#edit-commerce-discount-fields-additional-settings-discount-date', context).drupalSetSummary(function(context) { + var fromDate, + toDate, + fromDateTS, + toDateTS; + + fromDate = $('input[name="commerce_discount_fields[commerce_discount_date][und][0][value][date]"]').val(); + fromDateTS = fromDate ? new Date(fromDate) : 0; + toDate = $('input[name="commerce_discount_fields[commerce_discount_date][und][0][value2][date]"]').val(); + toDateTS = toDate ? new Date(toDate) : 0; + + options = { + '!from': fromDateTS < Date.now() ? Drupal.t('Started') : Drupal.t('Starts'), + '!to': toDateTS < Date.now() ? Drupal.t('Ended') : Drupal.t('Ends'), + '@fromDate': fromDate, + '@toDate': toDate + }; + + if (fromDate && toDate) { + options['!to'] = options['!to'].toLowerCase(); + return Drupal.t('!from @fromDate and !to @toDate', options); + } + else if (fromDate && !toDate) { + return Drupal.t('!from @fromDate', options); + } + else if (!fromDate && toDate) { + return Drupal.t('!to @toDate', options); + } + else { + return Drupal.t('Always active'); + } + }); + $('fieldset#edit-commerce-discount-fields-additional-settings-commerce-discount-usage', context).drupalSetSummary(function(context) { + var usagePerPerson = $('input[name="commerce_discount_fields[discount_usage_per_person][und][0][value]"]').val(), + overallUsage = $('input[name="commerce_discount_fields[discount_usage_limit][und][0][value]"]').val(), + vals = []; + + vals.push(Drupal.t('!usagePerPerson per person', {'!usagePerPerson': usagePerPerson > 0 ? Drupal.checkPlain(usagePerPerson) : '∞'})); + vals.push(Drupal.t('!overallUsage total', {'!overallUsage': overallUsage > 0 ? Drupal.checkPlain(overallUsage): '∞'})); + + return vals.join(', '); + }); }; }(jQuery, Drupal));