community-app/app/scripts/controllers/organization/CurrencyConfigController.js
2013-09-13 10:49:03 +05:30

57 lines
2.0 KiB
JavaScript

(function(module) {
mifosX.controllers = _.extend(module, {
CurrencyConfigController: function(scope, resourceFactory) {
scope.selectedCurrOptions = [];
scope.allCurrOptions = [];
scope.hideview = false;
scope.selected = undefined;
resourceFactory.currencyConfigResource.get(function(data){
scope.selectedCurrOptions = data.selectedCurrencyOptions;
scope.allCurrOptions = data.currencyOptions;
});
scope.deleteCur = function (code){
for(var i=0; i<scope.selectedCurrOptions.length; i++){
if(scope.selectedCurrOptions[i].code == code){
scope.selectedCurrOptions.splice(i, 1); //removes 1 element at position i
break;
}
}
};
scope.addCur = function (){
if(scope.selected != undefined && scope.selected.hasOwnProperty('code')) {
scope.selectedCurrOptions.push(scope.selected);
for(var i=0; i<scope.allCurrOptions.length; i++){
if(scope.allCurrOptions[i].code == scope.selected.code){
scope.allCurrOptions.splice(i, 1); //removes 1 element at position i
break;
}
}
}
scope.selected = undefined;
};
scope.submit = function () {
var currencies = [];
for(var i=0; i < scope.selectedCurrOptions.length; i++){
currencies.push(scope.selectedCurrOptions[i].code);
}
resourceFactory.currencyConfigResource.update(currencies , function(data){
console.log('test');
});
};
}
});
mifosX.ng.application.controller('CurrencyConfigController', ['$scope', 'ResourceFactory', mifosX.controllers.CurrencyConfigController]).run(function($log) {
$log.info("CurrencyConfigController initialized");
});
}(mifosX.controllers || {}));