var tag = this;
var store = stores.transactionStore;
function parent(event){return _.invoke(tag.parent, event, tag)}
tag.toggle = function(){parent('toggle')}
tag.hide = function(){parent('hide')}
tag.save = function(){
if (this.parent.values.value) {
$('#currency-value-select-commitment').removeClass('has-error');
$('#currency-value-select-incoming').removeClass('has-error');
$('#currency-value-select-transaction').removeClass('has-error');
parent('save')
} else {
$('#currency-value-select-commitment').addClass('has-error');
$('#currency-value-select-incoming').addClass('has-error');
$('#currency-value-select-transaction').addClass('has-error');
$('.has-warning').addClass('has-error');
$('.has-warning').addClass('validation-error');
this.parent.trigger('setValidation', 'value', 'error', 'Amount value is not a set!')
}
}
/* For dropdown-select inclusions in yielded modal-content, passes the event and the data to the parent tag */
tag.on('setdropdown', function(event, data, child_tag){
tag.parent.trigger('setdropdown', event, data, child_tag)
})
/* Pass through any "set" events triggered */
this.on('set', function set(field, amount){tag.parent.trigger('set', field, amount)})
this.on('setCurrency', function(currency){this.trigger('set', 'currency', currency)})
this.on('setAmount', function(amount){this.trigger('set', 'value', amount)}) /* saved as 'value' in db, displayed as 'amount' */
tag.on('before-mount', function(){tag.toggleExtraFieldsOn = false});
tag.toggleExtraFields = function(){tag.update({toggleExtraFieldsOn: !tag.toggleExtraFieldsOn})}
tag.on('update', function set_default_settings(){
var get_choice = store.get_choice;
var values = tag.parent.values;
var choices = ["aid_type", "finance_type", "flow_type", "tied_status"]
var default_settings = _.map(choices, function(choice){ return get_choice(choice, _.get(values,choice)) })
tag.default_settings = _.join(_.compact(default_settings), ', ')
})
{% comment %}
Transaction Date Picker sends a "set" trigger to its parent when its value is changed
to set the 'transaction_date' and 'value_date' fields of its thingamagig
{% endcomment %}
Date
var tag = this;
tag.setDate = function(e){
tag.parent.trigger('set', 'transaction_date', e.target.value);
tag.parent.trigger('set', 'value_date', e.target.value);
}
tag.on('mount', function () {
tag.datepicker_opts = $.extend({
orientation: 'top left',
startView: 1,
autoclose: true,
format: 'yyyy-mm-dd',
clearBtn: false,
endDate:'0d'
}, tag.opts.datepicker_opts);
tag.datepicker = $('input.form-control', tag.root).datepicker(tag.datepicker_opts);
tag.datepicker.on('changeDate', function () {
var date = $(this).datepicker('getUTCDate');
var iso_date = moment(date).format('YYYY-MM-DD');
tag.setDate({target:{value:iso_date}})
tag.update();
});
});