Skip to content

Commit

Permalink
feat(annotation: note): extend support for dynamic type to other schemas
Browse files Browse the repository at this point in the history
Note dialog is shared by all schemas

BREAKING CHANGE: Note dialog is share by all schemas and it need to account for their variations.
  • Loading branch information
lucaju committed Jul 20, 2020
1 parent d541a29 commit 14c0e6e
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 255 deletions.
2 changes: 2 additions & 0 deletions src/js/dialogs/dialogForm/dialogForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ DialogForm.prototype = {

save: function() {
this.$el.trigger('beforeSave', [this]);
if (!this.isValid) return;

DialogForm.processForm(this);

if (this.isValid === true) {
Expand Down
55 changes: 0 additions & 55 deletions src/js/schema/cwrcEntry/dialogs/note.js

This file was deleted.

42 changes: 21 additions & 21 deletions src/js/schema/cwrcEntry/dialogs_map.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
var citation = require('./dialogs/citation.js');
var correction = require('./dialogs/correction.js');
var date = require('./dialogs/date.js');
var keyword = require('./dialogs/keyword.js');
var link = require('./dialogs/link.js');
var note = require('./dialogs/note.js');
var org = require('./dialogs/org.js');
var person = require('./dialogs/person.js');
var place = require('./dialogs/place.js');
var title = require('./dialogs/title.js');
const citation = require('./dialogs/citation.js');
const correction = require('./dialogs/correction.js');
const date = require('./dialogs/date.js');
const keyword = require('./dialogs/keyword.js');
const link = require('./dialogs/link.js');
const note = require('../sharedDialogs/note.js');
const org = require('./dialogs/org.js');
const person = require('./dialogs/person.js');
const place = require('./dialogs/place.js');
const title = require('./dialogs/title.js');

module.exports = {
citation: citation,
correction: correction,
date: date,
keyword: keyword,
link: link,
note: note,
org: org,
person: person,
place: place,
title: title
};
citation,
correction,
date,
keyword,
link,
note,
org,
person,
place,
title,
};
55 changes: 0 additions & 55 deletions src/js/schema/orlando/dialogs/note.js

This file was deleted.

42 changes: 21 additions & 21 deletions src/js/schema/orlando/dialogs_map.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
var citation = require('./dialogs/citation.js');
var correction = require('./dialogs/correction.js');
var date = require('./dialogs/date.js');
var keyword = require('./dialogs/keyword.js');
var link = require('./dialogs/link.js');
var note = require('./dialogs/note.js');
var org = require('./dialogs/org.js');
var person = require('./dialogs/person.js');
var place = require('./dialogs/place.js');
var title = require('./dialogs/title.js');
const citation = require('./dialogs/citation.js');
const correction = require('./dialogs/correction.js');
const date = require('./dialogs/date.js');
const keyword = require('./dialogs/keyword.js');
const link = require('./dialogs/link.js');
const note = require('../sharedDialogs/note.js');
const org = require('./dialogs/org.js');
const person = require('./dialogs/person.js');
const place = require('./dialogs/place.js');
const title = require('./dialogs/title.js');

module.exports = {
citation: citation,
correction: correction,
date: date,
keyword: keyword,
link: link,
note: note,
org: org,
person: person,
place: place,
title: title
};
citation,
correction,
date,
keyword,
link,
note,
org,
person,
place,
title,
};
Original file line number Diff line number Diff line change
@@ -1,30 +1,52 @@
const $ = require('jquery');
const DialogForm = require('../../../dialogs/dialogForm/dialogForm');


const defaultTypeOptions = [
{ value: 'researchNote', label: 'Research Note', title: 'Internal to projects' },
{ value: 'scholarNote', label: 'Scholarly Note', title: 'Footnotes/endnotes' },
{ value: 'annotation', label: 'Annotation', title: 'Informal notes' },
{ value: 'other', label: 'Other', title: 'Other Notes' },
];
const DialogForm = require('../../dialogs/dialogForm/dialogForm');

module.exports = function(writer, parentEl) {

const type = 'note';

const atts = writer.schemaManager.getAttributesForTag(type);
const typeAtt = atts.find(({name}) => name === 'type');

const typeRequired = (typeAtt.required) ? 'required' : '';


const typeRequired = () => {
const mappingID = writer.schemaManager.mapper.currentMappingsId;
if (mappingID === 'orlando' || mappingID === 'cwrcEntry') return 'required'
return (typeAtt?.required) ? 'required' : '';
}

const defaultTypeOptions = () => {
const mappingID = writer.schemaManager.mapper.currentMappingsId;
let options;

if (mappingID === 'orlando' || mappingID === 'cwrcEntry') {
options = [
{ value: 'RESEARCHNOTE', label: 'Research Note', title: 'Internal to projects' },
{ value: 'SCHOLARNOTE', label: 'Scholarly Note', title: 'Footnotes/endnotes' },
];
} else {
options = [
{ value: 'researchNote', label: 'Research Note', title: 'Internal to projects' },
{ value: 'scholarNote', label: 'Scholarly Note', title: 'Footnotes/endnotes' },
{ value: 'annotation', label: 'Annotation', title: 'Informal notes' },
{ value: 'other', label: 'Other', title: 'Other Notes' },
];
}

return options;
}

const typeDataMapping = () => {
const mappingID = writer.schemaManager.mapper.currentMappingsId;
if (mappingID === 'orlando' || mappingID === 'cwrcEntry') return 'prop.tag';
return 'type';
}

const id = writer.getUniqueId('noteForm_');
const html = `
<div class="annotationDialog">
<div>
<label for="${id}_type"><b>Type</b></label>
<select id="${id}_type" name="${id}_type" data-type="select" data-mapping="type" ${typeRequired}></select>
<label for="${id}_type"><b>Type${typeRequired() && '*'}</b></label>
<select id="${id}_type" name="${id}_type" data-type="select" data-mapping="${typeDataMapping()}" ${typeRequired()}></select>
<div id="${id}_noteOtherTypeSlot">
<br/>
<label for="${id}_noteOtherType"><b>Define Type</b></label>
Expand Down Expand Up @@ -59,7 +81,7 @@ module.exports = function(writer, parentEl) {

dialog.$el.on('buildDynamicFields', (e, config, dialog) => {
//TYPE
const typeChoices = (typeAtt.choices) ? typeAtt.choices : defaultTypeOptions;
const typeChoices = (typeAtt?.choices) ? typeAtt.choices : defaultTypeOptions();
const choiceOptions = generateTypeOptions(typeChoices);
optionsTypeElement.html(choiceOptions)
});
Expand All @@ -71,15 +93,20 @@ module.exports = function(writer, parentEl) {

//other type
const typeValue = optionsTypeElement.val();
const showOtherTypeTextFiel = (!typeAtt.choices && typeValue === 'other') ? true : false
const showOtherTypeTextFiel = (!typeAtt?.choices && typeValue === 'other') ? true : false
toggleOtherTypeTextField(showOtherTypeTextFiel);

});

dialog.$el.on('beforeSave', (e, dialog) => {
//replace other type option for custom defined value
if (!typeAtt.choices && optionsTypeElement.val() === 'other') {
const otherTypeFieldValue= dialog.$el.find(`#${id}_noteOtherType`).val();
//type value
const typeValue = dialog.$el.find(`#${id}_type`).val();
dialog.isValid = (!!typeRequired() && typeValue === null) ? false : true;
if (!dialog.isValid) return;

//replace other type option for custom defined value
if (!typeAtt?.choices && optionsTypeElement.val() === 'other') {
const otherTypeFieldValue = dialog.$el.find(`#${id}_noteOtherType`).val();
const typeCutstomOption = `<option value="${otherTypeFieldValue}" selected>${otherTypeFieldValue}</option>`;
optionsTypeElement.html(typeCutstomOption);
}
Expand All @@ -93,7 +120,7 @@ module.exports = function(writer, parentEl) {

//toggle other type text field
optionsTypeElement.change((e) => {
if (typeAtt.choices) return;
if (typeAtt?.choices) return;
const target = $(e.target);
const otherTypeSelected = (target.val() === 'other') ? true : false;
toggleOtherTypeTextField(otherTypeSelected);
Expand Down Expand Up @@ -121,13 +148,17 @@ module.exports = function(writer, parentEl) {
const generateTypeOptions = (choices) => {

let html = '<option value="" disabled selected hidden>Please Choose...</option>';
html += '<option value=""></option>';

//empty choice
const mappingID = writer.schemaManager.mapper.currentMappingsId;
if (mappingID !== 'orlando' && mappingID !== 'cwrcEntry') html += '<option value=""></option>';

//choices
choices.map((choice) => {
const value = (typeof choice === 'string') ? choice : choice.value;
const label = (typeof choice === 'string') ? choice : choice.label;

const defaultChoice = (typeAtt.defaultValue === value) ? true : false;
const defaultChoice = (typeAtt?.defaultValue === value) ? true : false;
const selected = defaultChoice ? 'selected' : '';

html += `<option value="${value}" data-default="${defaultChoice}" ${selected}>${label}</option>`;
Expand Down
2 changes: 1 addition & 1 deletion src/js/schema/tei/dialogs_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const correction = require('./dialogs/correction.js');
const date = require('./dialogs/date.js');
const keyword = require('./dialogs/keyword.js');
const link = require('./dialogs/link.js');
const note = require('./dialogs/note.js');
const note = require('../sharedDialogs/note.js');
const org = require('./dialogs/org.js');
const person = require('./dialogs/person.js');
const place = require('./dialogs/place.js');
Expand Down
Loading

0 comments on commit 14c0e6e

Please sign in to comment.