angular.module('app').service('ApplyMassConfigDialogService', function($q, BackendService, AppService, L, SQEvents, ApplyMassConfigService) {

    this.loadSettings = function (callback) {
        ApplyMassConfigService.loadTasks(instance.config);

        BackendService.sendRequest("project/applyMassConfigLoad", null, function(response) {
            var xmlObj = xmlToObject(response.xmlConfig);
            var applyMassConfigObj = xmlObj.find('ApplyMassConfig')[0];

            ApplyMassConfigService.loadSettingsObj(applyMassConfigObj, instance.config);

            callback();
        });
    }     
    
    this.applyMassConfig = function (callback) {
        var xmlDoc = AppService.xmlDoc;
        var applyMassConfigObj = xmlDoc.createElement("ApplyMassConfig");

        ApplyMassConfigService.saveSettingsObj(applyMassConfigObj, instance.config);

        var data = {
            projectName: AppService.getProject(),
            xmlConfig: xmlToString(applyMassConfigObj)
        }

        BackendService.sendRequest("project/applyMassConfig", data, callback);
    }

    var instance = this;

    this.config = angular.copy(ApplyMassConfigService.config);

});