From 3245e7e9f2ae3a9dc23e1aefb7826606b5a85724 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Mon, 26 Jan 2015 10:37:14 +0000 Subject: [PATCH 01/29] Add require-sources instance setting The per-field sourcing feature is opt-in so we want it to be disabled by default. --- lib/apps/about.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/apps/about.js b/lib/apps/about.js index 11b80c6d..69b46207 100644 --- a/lib/apps/about.js +++ b/lib/apps/about.js @@ -24,6 +24,7 @@ module.exports = function () { "contact_phone": { type: "textbox", label: "Contact Phone" }, "disclaimer": { type: "textarea", label: "Override disclaimer" }, "no-spider": { type: "checkbox", label: "Do Not Spider" }, + "require-sources": { type: "checkbox", label: "Require sources" }, "license": { type: "textarea", label: "License text" }, }; From 58b801fb3d2b184a6f591a95905a1945935706da Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Mon, 26 Jan 2015 12:28:13 +0000 Subject: [PATCH 02/29] Add source fields to person edit page --- instance-app/views/field_source/edit.html | 12 ++++++++++++ instance-app/views/person/form.html | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 instance-app/views/field_source/edit.html diff --git a/instance-app/views/field_source/edit.html b/instance-app/views/field_source/edit.html new file mode 100644 index 00000000..eadc661c --- /dev/null +++ b/instance-app/views/field_source/edit.html @@ -0,0 +1,12 @@ +<% if (popit.setting('require-sources')) { %> +
+ <% if (value) { %> + Change source + <% } else { %> + Add source + <% } %> +
+ +
+
+<% } %> diff --git a/instance-app/views/person/form.html b/instance-app/views/person/form.html index 5df771fb..45ddd51a 100644 --- a/instance-app/views/person/form.html +++ b/instance-app/views/person/form.html @@ -10,6 +10,7 @@ + <%= render('field_source/edit.html', { field: 'field_sources[name]', value: person.get('field_sources.name') }) %> @@ -39,6 +40,7 @@ <% _.each(person.other_names, function(name, i) { %>
  • <%= render('other_name/edit.html', {name: name, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[other_names][' + i + ']', value: person.get('field_sources.other_names.' + i) }) %> Delete
  • <% }) %> @@ -49,18 +51,21 @@
    + <%= render('field_source/edit.html', { field: 'field_sources[summary]', value: person.get('field_sources.summary') }) %>
    + <%= render('field_source/edit.html', { field: 'field_sources[birth_date]', value: person.get('field_sources.birth_date') }) %>
    + <%= render('field_source/edit.html', { field: 'field_sources[death_date]', value: person.get('field_sources.death_date') }) %>
    @@ -78,6 +83,7 @@ <% _.each(person.links, function(link, i) { %>
  • <%= render('link/edit.html', {link: link, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[links][' + i + ']', value: person.get('field_sources.links.' + i) }) %> Delete
  • <% }) %> @@ -100,6 +106,7 @@ <% _.each(person.contact_details, function(contact, i) { %>
  • <%= render('contact/edit.html', {contact: contact, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[contact_details][' + i + ']', value: person.get('field_sources.contact_details.' + i) }) %> Delete
  • <% }) %> @@ -122,6 +129,7 @@ <% if (validMembership(membership, person.id)) { %>
  • <%= render('membership/new.html', { membership: membership, member: person, organization: relatedObject(membership, person, lang, defaultLang), type: 'person', i: i }) %> + <%= render('field_source/edit.html', { field: 'field_sources[memberships][' + i + ']', value: person.get('field_sources.memberships.' + i) }) %>
  • <% } %> <% }); %> @@ -164,6 +172,7 @@ <% _.each(person.identifiers, function(identifier, i) { %>
  • <%= render('identifier/edit.html', {identifier: identifier, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[identifier][' + i + ']', value: person.get('field_sources.identifier.' + i) }) %> Delete
  • <% }) %> From cf686424ca746c649ec4e82c13dbc25ae2023843 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Mon, 26 Jan 2015 12:56:33 +0000 Subject: [PATCH 03/29] Add toggle for sources popup --- instance-app/views/field_source/edit.html | 6 +++--- public/js/augmenters/source-field.js | 16 ++++++++++++++++ public/js/run-instance-admin.js | 3 ++- public/sass/_people-and-organizations.scss | 13 +++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 public/js/augmenters/source-field.js diff --git a/instance-app/views/field_source/edit.html b/instance-app/views/field_source/edit.html index eadc661c..a2d93cb5 100644 --- a/instance-app/views/field_source/edit.html +++ b/instance-app/views/field_source/edit.html @@ -1,11 +1,11 @@ <% if (popit.setting('require-sources')) { %>
    <% if (value) { %> - Change source + Change source <% } else { %> - Add source + Add source <% } %> -
    +
    diff --git a/public/js/augmenters/source-field.js b/public/js/augmenters/source-field.js new file mode 100644 index 00000000..48d16b48 --- /dev/null +++ b/public/js/augmenters/source-field.js @@ -0,0 +1,16 @@ +require(['jquery'], function($) { + "use strict"; + + var linkSelector = '.js-source__link'; + var popupSelector = '.js-source__popup'; + var popupDisplayClass = 'source__popup--display'; + + $(function() { + $(document).on('click', linkSelector, function showSourceField(e) { + e.preventDefault(); + var $this = $(this); + var popup = $this.next(popupSelector); + popup.toggleClass(popupDisplayClass); + }); + }); +}); diff --git a/public/js/run-instance-admin.js b/public/js/run-instance-admin.js index 4121668d..efed4c44 100644 --- a/public/js/run-instance-admin.js +++ b/public/js/run-instance-admin.js @@ -5,7 +5,8 @@ require([ 'augmenters/migration', 'augmenters/slug-validation', 'augmenters/edit-in-place', - 'augmenters/enter-to-save' + 'augmenters/enter-to-save', + 'augmenters/source-field' ]); // PopIt editing app - load it and add bits needed diff --git a/public/sass/_people-and-organizations.scss b/public/sass/_people-and-organizations.scss index aa612cca..7cdb3546 100644 --- a/public/sass/_people-and-organizations.scss +++ b/public/sass/_people-and-organizations.scss @@ -689,3 +689,16 @@ $entity-photo-sidebar-width: 285px; height: 5em; } } + +// Per-field sourcing +.source__popup { + display: none; +} + +.source__popup--display { + display: block; +} + +.source__link { + cursor: pointer; +} From 9f74fc7dc64bfd48a00a79d4b3d793c60b48af66 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Mon, 26 Jan 2015 15:14:01 +0000 Subject: [PATCH 04/29] Filter out blank values before saving field_sources --- lib/apps/generic_document.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/apps/generic_document.js b/lib/apps/generic_document.js index 68964ff8..dbf769e8 100644 --- a/lib/apps/generic_document.js +++ b/lib/apps/generic_document.js @@ -123,6 +123,31 @@ module.exports = function (opts) { next(); }); + // Remove blank values from field_sources object + app.put('/:id(*)', function(req, res, next) { + function removeBlanks(obj) { + var ret = {}; + _.each(obj, function(val, key) { + if (_.isArray(val)) { + var filtered = _.compact(val); + if (filtered.length > 0) { + ret[key] = filtered; + } + } else if (_.isObject(val)) { + ret[key] = removeBlanks(val); + } else { + if (val) { + ret[key] = val; + } + } + }); + return ret; + } + + req.body.field_sources = removeBlanks(req.body.field_sources); + next(); + }); + function save_as_multilingual(body, obj, lang, defaultLang) { if (!body) { return; From c5b79384d5ee152693fa4faebe71ccf7855a79e2 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Mon, 26 Jan 2015 15:39:01 +0000 Subject: [PATCH 05/29] Add field source to view page --- instance-app/views/contact/list.html | 7 +++++-- instance-app/views/field_source/view.html | 12 ++++++++++++ instance-app/views/identifier/list.html | 7 +++++-- instance-app/views/link/list.html | 7 +++++-- instance-app/views/other_name/list.html | 7 +++++-- instance-app/views/person/view.html | 15 ++++++++++----- 6 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 instance-app/views/field_source/view.html diff --git a/instance-app/views/contact/list.html b/instance-app/views/contact/list.html index 074fda6a..d408c487 100644 --- a/instance-app/views/contact/list.html +++ b/instance-app/views/contact/list.html @@ -1,6 +1,9 @@
      - <% _.each( contact_details, function (item) { %> -
    • <%= render( 'contact/view.html', { item: item }) %>
    • + <% _.each( contact_details, function (item, i) { %> +
    • + <%= render( 'contact/view.html', { item: item }) %> + <%= render('field_source/view.html', { value: object.get('field_sources.contact_details.' + i) }) %> +
    • <% }); %>
    • Add <% if ( contact_details.length > 0 ) { %>more <% } %>contact details diff --git a/instance-app/views/field_source/view.html b/instance-app/views/field_source/view.html new file mode 100644 index 00000000..4b6d4fa6 --- /dev/null +++ b/instance-app/views/field_source/view.html @@ -0,0 +1,12 @@ +<% if (popit.setting('require-sources')) { %> +
      + <% if (value) { %> + Show source + <% } else { %> + No source + <% } %> +
      + <%- value %> +
      +
      +<% } %> diff --git a/instance-app/views/identifier/list.html b/instance-app/views/identifier/list.html index db7a4c4e..ccfba5a0 100644 --- a/instance-app/views/identifier/list.html +++ b/instance-app/views/identifier/list.html @@ -1,6 +1,9 @@
        - <% _.each( identifiers, function (item) { %> -
      • <%= render( 'identifier/view.html', { item: item }) %>
      • + <% _.each( identifiers, function (item, i) { %> +
      • + <%= render( 'identifier/view.html', { item: item }) %> + <%= render('field_source/view.html', { value: object.get('field_sources.identifiers.' + i) }) %> +
      • <% }); %>
      • Add an<% if(identifiers.length){ %>other<% } %> identifier diff --git a/instance-app/views/link/list.html b/instance-app/views/link/list.html index 16043283..4a4e66d3 100644 --- a/instance-app/views/link/list.html +++ b/instance-app/views/link/list.html @@ -1,6 +1,9 @@
    @@ -172,7 +177,7 @@

    <% } %>
    - <%= render( 'link/list.html', { links: person.links } ) %> + <%= render( 'link/list.html', { links: person.links, object: person } ) %>
    @@ -187,7 +192,7 @@

    <% } %>
    - <%= render( 'contact/list.html', { contact_details: person.contact_details } ) %> + <%= render( 'contact/list.html', { contact_details: person.contact_details, object: person } ) %>
    @@ -204,7 +209,7 @@

    <% } %>
    - <%= render( 'source/list.html', { sources: person.sources } ) %> + <%= render( 'source/list.html', { sources: person.sources, object: person } ) %>
    @@ -219,7 +224,7 @@

    <% } %>
    - <%= render( 'identifier/list.html', { identifiers: person.identifiers } ) %> + <%= render( 'identifier/list.html', { identifiers: person.identifiers, object: person } ) %>
    From 12c13ca1bb7595a52e45d18cb9191b23669d9294 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Mon, 26 Jan 2015 15:58:22 +0000 Subject: [PATCH 06/29] Add source fields to organization --- instance-app/views/organization/form.html | 10 ++++++++++ instance-app/views/organization/view.html | 15 ++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/instance-app/views/organization/form.html b/instance-app/views/organization/form.html index 12739b9a..784ca8d3 100644 --- a/instance-app/views/organization/form.html +++ b/instance-app/views/organization/form.html @@ -13,6 +13,7 @@

    + <%= render('field_source/edit.html', { field: 'field_sources[name]', value: organization.get('field_sources.name') }) %>
    @@ -25,6 +26,7 @@

    What type of organization is <%- organization.name %>? <% } %>

    + <%= render('field_source/edit.html', { field: 'field_sources[classification]', value: organization.get('field_sources.classification') }) %>
    @@ -69,6 +71,7 @@

    <% _.each(organization.other_names, function(name, i) { %>
  • <%= render('other_name/edit.html', {name: name, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[other_names][' + i + ']', value: organization.get('field_sources.other_names.' + i) }) %> Delete
  • <% }) %> @@ -84,6 +87,7 @@

    <% } %>

    + <%= render('field_source/edit.html', { field: 'field_sources[parent_id]', value: organization.get('field_sources.parent_id') }) %>

    @@ -91,6 +95,7 @@

    <%- organization.founding_date || '' %>

    + <%= render('field_source/edit.html', { field: 'field_sources[founding_date]', value: organization.get('field_sources.founding_date') }) %>

    @@ -98,6 +103,7 @@

    <%- organization.dissolution_date || '' %>

    + <%= render('field_source/edit.html', { field: 'field_sources[dissolution_date]', value: organization.get('field_sources.dissolution_date') }) %>

    @@ -108,6 +114,7 @@

    <% if (validMembership(membership, organization.id)) { %>
  • <%= render('membership/new.html', { membership: membership, organization: organization, member: relatedObject(membership, organization, lang, defaultLang), type: 'organization', i: i }) %> + <%= render('field_source/edit.html', { field: 'field_sources[memberships][' + i + ']', value: organization.get('field_sources.memberships.' + i) }) %>
  • <% } %> <% }); %> @@ -149,6 +156,7 @@

    <% _.each(organization.links, function(link, i) { %>
  • <%= render('link/edit.html', {link: link, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[links][' + i + ']', value: organization.get('field_sources.links.' + i) }) %> Delete
  • <% }) %> @@ -170,6 +178,7 @@

    <% _.each(organization.contact_details, function(contact, i) { %>
  • <%= render('contact/edit.html', {contact: contact, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[contact_details][' + i + ']', value: organization.get('field_sources.contact_details.' + i) }) %> Delete
  • <% }) %> @@ -212,6 +221,7 @@

    <% _.each(organization.identifiers, function(identifier, i) { %>
  • <%= render('identifier/edit.html', {identifier: identifier, i: i}) %> + <%= render('field_source/edit.html', { field: 'field_sources[identifier][' + i + ']', value: organization.get('field_sources.identifier.' + i) }) %> Delete
  • <% }) %> diff --git a/instance-app/views/organization/view.html b/instance-app/views/organization/view.html index c60d2ab5..c9e8e1c2 100644 --- a/instance-app/views/organization/view.html +++ b/instance-app/views/organization/view.html @@ -65,6 +65,7 @@

    <%- organization.name %>

    + <%= render('field_source/view.html', { value: organization.get('field_sources.name') }) %> @@ -79,6 +80,7 @@

    What type of organization is <%- organization.name %>? <% } %>

    + <%= render('field_source/view.html', { value: organization.get('field_sources.classification') }) %>
    @@ -118,7 +120,7 @@

    - <%= render( 'other_name/list.html', { other_names: organization.other_names } ) %> + <%= render( 'other_name/list.html', { other_names: organization.other_names, object: organization } ) %>
    @@ -129,6 +131,7 @@

    <% } %>

    + <%= render('field_source/view.html', { value: organization.get('field_sources.parent_id') }) %>

    @@ -136,6 +139,7 @@

    <%- organization.founding_date || '' %>

    + <%= render('field_source/view.html', { value: organization.get('field_sources.founding_date') }) %>

    @@ -143,6 +147,7 @@

    <%- organization.dissolution_date || '' %>

    + <%= render('field_source/view.html', { value: organization.get('field_sources.dissolution_date') }) %>

    @@ -195,7 +200,7 @@

    <% } %>
    - <%= render( 'link/list.html', { links: organization.links } ) %> + <%= render( 'link/list.html', { links: organization.links, object: organization } ) %>
    @@ -210,7 +215,7 @@

    <% } %>
    - <%= render( 'contact/list.html', { contact_details: organization.contact_details } ) %> + <%= render( 'contact/list.html', { contact_details: organization.contact_details, object: organization } ) %>
    @@ -225,7 +230,7 @@

    <% } %>
    - <%= render( 'source/list.html', { sources: organization.sources } ) %> + <%= render( 'source/list.html', { sources: organization.sources, object: organization } ) %>
    @@ -240,7 +245,7 @@

    <% } %>
    - <%= render( 'identifier/list.html', { identifiers: organization.identifiers } ) %> + <%= render( 'identifier/list.html', { identifiers: organization.identifiers, object: organization } ) %>
    From 7e0dad582eb07db3ffebbb0df363bb489fa51a47 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Thu, 5 Feb 2015 17:33:11 +0000 Subject: [PATCH 07/29] Don't save field_sources as multilingual --- lib/apps/generic_document.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/apps/generic_document.js b/lib/apps/generic_document.js index dbf769e8..233de9ea 100644 --- a/lib/apps/generic_document.js +++ b/lib/apps/generic_document.js @@ -158,7 +158,7 @@ module.exports = function (opts) { if ( !item && !body[field] ) { return; } - if ( ['other_names', 'identifiers', 'links', 'contact_details', 'sources'].indexOf(field) != -1 ) { + if ( ['other_names', 'identifiers', 'links', 'contact_details', 'sources', 'field_sources'].indexOf(field) != -1 ) { if ( _.isArray(body[field]) && body[field].length ) { var new_item = []; if ( _.isArray(item) && item.length ) { From b4452bf0a25200a05f76f26babf7c47245b07d00 Mon Sep 17 00:00:00 2001 From: Zarino Zappia Date: Mon, 2 Mar 2015 16:34:54 +0000 Subject: [PATCH 08/29] clean up person/organization editing read-mode/edit-mode elements At some point in the recent past, we switched from having read-mode and edit-mode elements next to each other, interspersed around the page, to having all the edit-mode elements in a separate template and collected at the end of the page, away from the read-mode ones. But many of the old read-mode and edit-mode elements were left in the templates, despite never actually being shown to users. This commit removes all the ones I could find. There might be more, but it's a start. --- instance-app/views/organization/form.html | 69 ++--------------------- instance-app/views/organization/view.html | 16 ------ instance-app/views/person/form.html | 43 -------------- instance-app/views/person/view.html | 66 ++++++++++------------ 4 files changed, 33 insertions(+), 161 deletions(-) diff --git a/instance-app/views/organization/form.html b/instance-app/views/organization/form.html index 784ca8d3..69cc6d02 100644 --- a/instance-app/views/organization/form.html +++ b/instance-app/views/organization/form.html @@ -7,29 +7,17 @@
    -

    - <%- organization.name %> - -

    - + <%= render('field_source/edit.html', { field: 'field_sources[name]', value: organization.get('field_sources.name') }) %>
    -

    - <% if (organization.classification) { %> - <%- organization.classification %> - - <% } else { %> - What type of organization is <%- organization.name %>? - <% } %> -

    - <%= render('field_source/edit.html', { field: 'field_sources[classification]', value: organization.get('field_sources.classification') }) %>
    + <%= render('field_source/edit.html', { field: 'field_sources[classification]', value: organization.get('field_sources.classification') }) %>