{% load i18n %} {% load static %}
/* manually call 'exec' to initiate this nested router */ var tag = this; this.on('mount', function(){route.exec('')})

{% trans 'There are no documents or images uploaded' %}

{% blocktrans %}Documents and images should include key supporting materials related to this {{activity_singular_lower}}{% endblocktrans %}

var tag = this; var store = stores.documentStore; tag.store = store; tag.documents = store[store.el]; var update = function(){ tag.update({documents: store[store.el]}) } tag.on('mount', function(){ store.on('documents-updated', update) }) tag.on('unmount', function(){ store.off('documents-updated', update) }) tag.save = function () { tag.document.iso_date = moment().format('YYYY-MM-DD'); // Tag document with iso-format date if (tag.state.new) { tag.store.create(tag, tag.editing.item); return; } tag.store.update(tag, tag.editing.item); }, tag.mixin('TabMixin');

{doc.title} {% trans 'Untitled' %}

Category: 1}>Categories: {cat[1]}.

{doc.iso_date} - {doc.file_type} - URL - {doc.display_file_size}
var tag = this; tag.icon_size = 85; var store = stores.documentStore; tag.store = store; tag.delete = function(e){ function remove(){ _.remove(tag.store[tag.store.el], {id: e.item.doc.id}); store.trigger('documents-updated'); } function del() { tag.store.save(tag, {method: 'DELETE', url:tag.store.urls.delete(e.item.doc.id)}).then(remove) } RiotControl.trigger('confirm-delete', { confirm: del, content: 'This document will be deleted permanently.' }); } function edit(e){route('documents/'+tag.opts.document.id);} function annotate(sourceDoc){ doc = _.clone(sourceDoc); doc.display_file_size = (doc.file_size / (1024 * 1024)).toFixed(2) + 'mb'; doc.icon_url = _.get(store.icons, doc.file_format, '{% static "img/text_doc.svg" %}'); doc.categories_verbose = _.map(doc.categories, function(cat){return [cat, store.get_choice('document_category', cat)]}) return doc; } tag.edit = edit; tag.on('before-mount', function(){ tag.doc = annotate(tag.opts.document); })
{% trans 'back' %}

var tag = this; var store = stores.documentStore; store.edited_document = defaultDoc(); tag.store = store; tag.mixin('TabMixin'); tag.mixin('ValidationMixin'); tag.validate_type = _.keys(store.icons); tag.validate_max_size = 15 * 1024 * 1024; // 15 Mb limit function add_category(code){ _.pull(tag.document.categories, code || '') if (_.isUndefined(tag.document.categories)){ tag.document.categories = []; } tag.document.categories.push(code || ''); tag.update(); } tag.on('onchoose', function(event, data, _tag){ /* Replace the existing tag */ var idx = _.indexOf(tag.document.categories, _tag.data); if (idx > -1){ tag.document.categories[idx] = data.code; return; } add_category(data.code) }) tag.remove_category = function(e){ if (_.has(e, 'item.category')){ _.pull(tag.document.categories, e.item.category); } } tag.add_empty_category = add_category; function defaultDoc(){ var categoriesPK = store.choices.document_category.map(function(tuple) { return tuple[0]; }); return { // default to A02: Objectives of activity for IATI-based deployments, otherwise default to the first category categories: categoriesPK.indexOf('A02') > -1 ? ['A02'] : [categoriesPK[0]], language: 'en' } } tag.on('route', function(document_id){ store.edited_document = document_id === 'create' ? defaultDoc() : _.find(store[store.el], {id:_.toInteger(document_id)}, defaultDoc()) var updates = { document:store.edited_document, document_id: document_id !== 'create' ? document_id : null, show_url_field: document_id === 'create' || !store.edited_document.url.startsWith('/media/by_organisation') } tag.update(updates) }) tag.validate_type = _.keys(store.icons); tag.validate_max_size = 15 * 1024 * 1024; // 15 Mb limit tag.save = function(){ var request; var doc = _.clone(tag.document); var serialize = function(){return _(tag.refs).mapValues(function(k){return k.value}).value()} doc.iso_date = moment().format('YYYY-MM-DD') doc.activity = stores.activityStore.activity.id; doc.categories = _.compact(doc.categories); doc.types = []; //{# ResourceType model - see openly_hamutuk milestones 17, 18 #} _.assign(doc, serialize()); _.assign(doc, store.edited_document); tag.fn_validate._validate_loudly(tag); tag.validate(); if (tag.validated === false || tag.validate_with_children() === false) { window.banner_message.show(gettext('There are validation errors on this tab.'), 'warning'); return; } request = _.isNull(tag.document_id) ? tag.store.create(tag, doc) : tag.store.update(tag, doc); request.done(function(){ store.edited_document = {}; route('documents') }) }

{% trans 'Documents' %}

{% trans 'Add a document' %}