{% load i18n %} {% load common_text %} {% trans "sector" as label_lower %} {% blocktrans asvar placeholder %}Add a {{label_lower}}...{% endblocktrans%}

{% trans 'Sectors & Policy Markers' %}

{% trans 'Sectors represent the purpose of the activity'%}. {% trans 'They must add up to 100%' %}.

{{ 'non_iati_sector_text'|common_text }}

{% trans 'A policy or theme addressed by the activity. This element was designed for the reporting of OECD DAC CRS policy markers.' %}

var tag = this; tag.mixin('SerializerMixin'); tag.mixin('ValidationMixin'); tag.mixin('TabMixin'); tag.save = function() { /** Serialize the tags and send the serialized object to the activity update API. */ var xhr; var serialized_object = tag.serialize_object(); serialized_object['id'] = tag.store.activity_id; window.banner_message.show('Saving', 'info'); xhr = tag.put(serialized_object, {'update_done': 'sectors_update_done'}); xhr.done(function () { tag.validate(); tag.store.load_data(xhr.responseJSON); updateAllTheThings(); window.banner_message.show('Saved', 'success'); }); xhr.fail(function () { tag.update(); window.banner_message.show('Error while saving, please try again', 'danger'); }); return xhr; }; tag.serialize_object = function() { /** Return an object of serialized sectors ready to be sent to the API, like: * * {'sectors': [...], 'sector_working_groups': [...], 'policy_markers': [...]} */ var serialized_sectors = {}; var store = tag.store; var group_elements; store.group_names.forEach(function(group_name) { // remove the elements that have a null code var foreign_key_name = group_name.slice(0, group_name.length - 1); // strip the ending 's' serialized_sectors[group_name] = _.clone(store[group_name]); _.remove(serialized_sectors[group_name], function(element) { return !element[foreign_key_name].code; }); }); return serialized_sectors; } tag.add_row = function (event) { tag.store.add_row(event.target.dataset.group); tag.store.trigger('path_updated', {store:tag.store, path: tag.path}); tag.update(); }; function updateAllTheThings(){ tag.update(); _.map(tag.list_child_tags(), function(t){t.update()}) } tag.on('mount', function(){ tag.store.on('sectors_updated', updateAllTheThings)}) tag.on('unmount', function(){ tag.store.off('sectors_updated', updateAllTheThings)}) tag.discard = function(){ var store = tag.store; store.load_data(stores.activityStore.activity); } tag.has_changed = function(){ function removeBlankCodes(arr){ return _.filter(arr, function(thingLikeSector){ if (_.isNull(_.get(thingLikeSector, 'sector.code'))){return false}; if (_.isNull(_.get(thingLikeSector, 'sector_working_group.code'))){return false}; if (_.isNull(_.get(thingLikeSector, 'policy_marker.code'))){return false}; return true }) } function equality(sectorSet, anotherSectorSet) { return _.isEqual(removeBlankCodes(sectorSet), removeBlankCodes(anotherSectorSet)) } var s = tag.store; var i = tag.store._initial; // Because we add empty rows we will filter them out before comparison var unchanged = equality(s.sectors, i.sectors) && equality(s.policy_markers, i.policy_markers) && equality(s.sector_working_groups, i.sector_working_groups) return !unchanged; }
{errors}
{#