From 84cd296c5853a35a2ccb4a961da30812e69ba34b Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 28 Apr 2014 15:16:31 +0100 Subject: [PATCH] Minor tweaks to shadow warning infrastructure 1. Moved some methods out of boot.js because they are not needed until after bootup 2. Added alternate message for editing an overridden shadow tiddler 3. Minor style tweaks --- boot/boot.js | 32 ------------------------ core/language/en-GB/EditTemplate.multids | 3 ++- core/language/en-GB/Misc.multids | 2 +- core/modules/tiddler.js | 4 +++ core/modules/utils/utils.js | 19 +++++++++++++- core/modules/widgets/navigator.js | 2 +- core/modules/wiki.js | 21 ++++++++++++++++ core/ui/EditTemplate/shadow.tid | 19 ++++++++++++++ core/ui/EditTemplate/shadowWarning.tid | 11 -------- core/wiki/tags/EditTemplate.tid | 2 +- 10 files changed, 67 insertions(+), 48 deletions(-) create mode 100644 core/ui/EditTemplate/shadow.tid delete mode 100644 core/ui/EditTemplate/shadowWarning.tid diff --git a/boot/boot.js b/boot/boot.js index c54fa53d6..658f8e980 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -85,18 +85,6 @@ $tw.utils.each = function(object,callback) { } }; -/* -Check if an array is equal by value and by reference. -*/ -$tw.utils.isArrayEqual = function(array1,array2) { - if(array1 === array2) { return true; } - array1 = array1 || []; array2 = array2 || []; - if(array1.length !== array2.length) { return false; } - return array1.every(function(value,index) { - return value === array2[index]; - }); -}; - /* Helper for making DOM elements tag: tag name @@ -791,10 +779,6 @@ $tw.Tiddler.prototype.hasField = function(field) { return $tw.utils.hop(this.fields,field); }; -$tw.Tiddler.prototype.isDraft = function() { - return this.hasField("draft.of"); -}; - /* Register and install the built in tiddler field modules */ @@ -1124,22 +1108,6 @@ $tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) { } }; -$tw.Wiki.prototype.isModifiedTiddler = function(title) { - var tiddler = this.getTiddler(title); - if(!tiddler.isDraft()) { - return false; - } - var ignoredFields = ["created", "modified", "title", "draft.title", "draft.of", "tags"], - origTiddler = this.getTiddler(tiddler.fields["draft.of"]); - if(!$tw.utils.isArrayEqual(tiddler.fields.tags,origTiddler.fields.tags)) { - return true; - } - return !Object.keys(tiddler.fields).every(function(field) { - if(ignoredFields.indexOf(field) >= 0) { return true; } - return tiddler.fields[field] === origTiddler.fields[field]; - }); -}; - /* Register the built in tiddler deserializer modules */ diff --git a/core/language/en-GB/EditTemplate.multids b/core/language/en-GB/EditTemplate.multids index d6eb2a525..e5625c351 100644 --- a/core/language/en-GB/EditTemplate.multids +++ b/core/language/en-GB/EditTemplate.multids @@ -4,11 +4,12 @@ Body/Hint: Use [[wiki text|http://tiddlywiki.com/static/WikiText.html]] to add f Body/Placeholder: Type the text for this tiddler Body/Preview/Button/Hide: hide preview Body/Preview/Button/Show: show preview -Body/ShadowWarning: You are editing a shadow tiddler. Any changes will override the default version. Fields/Add/Button: add Fields/Add/Name/Placeholder: field name Fields/Add/Prompt: Add a new field: Fields/Add/Value/Placeholder: field value +Shadow/Warning: This is a shadow tiddler. Any changes will override the default version +Shadow/OverriddenWarning: This is a modified shadow tiddler. You can revert to the default version by deleting this tiddler Tags/Add/Button: add Tags/Add/Placeholder: tag name Type/Placeholder: content type diff --git a/core/language/en-GB/Misc.multids b/core/language/en-GB/Misc.multids index 35502b737..0718b08b8 100644 --- a/core/language/en-GB/Misc.multids +++ b/core/language/en-GB/Misc.multids @@ -6,7 +6,7 @@ CloseAll/Button: close all ConfirmCancelTiddler: Do you wish to discard changes to the tiddler "<$text text=<>/>"? ConfirmDeleteTiddler: Do you wish to delete the tiddler "<$text text=<<title>>/>"? ConfirmOverwriteTiddler: Do you wish to overwrite the tiddler "<$text text=<<title>>/>"? -ConfirmEditShadowTiddler: Your about to edit a ShaddowTiddler. This will override the default system making upgrading non-trivial. Are you sure you want to edit "<$text text=<<title>>/>"? +ConfirmEditShadowTiddler: You are about to edit a ShadowTiddler. Any changes will override the default system making future upgrades non-trivial. Are you sure you want to edit "<$text text=<<title>>/>"? InvalidFieldName: Illegal characters in field name "<$text text=<<fieldName>>/>". Fields can only contain lowercase letters and the characters underscore (`_`), hyphen (`-`) and period (`.`) MissingTiddler/Hint: Missing tiddler "<$text text=<<currentTiddler>>/>" - click {{$:/core/images/edit-button}} to create RecentChanges/DateFormat: DDth MMM YYYY diff --git a/core/modules/tiddler.js b/core/modules/tiddler.js index 7b59b8c77..6529970d3 100644 --- a/core/modules/tiddler.js +++ b/core/modules/tiddler.js @@ -20,6 +20,10 @@ exports.isPlugin = function() { return this.fields.type === "application/json" && this.hasField("plugin-type"); } +exports.isDraft = function() { + return this.hasField("draft.of"); +}; + exports.getFieldString = function(field) { var value = this.fields[field]; // Check for a missing field diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index cf92a95b7..5a01fd387 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -33,6 +33,23 @@ exports.count = function(object) { return s; }; +/* +Check if an array is equal by value and by reference. +*/ +exports.isArrayEqual = function(array1,array2) { + if(array1 === array2) { + return true; + } + array1 = array1 || []; + array2 = array2 || []; + if(array1.length !== array2.length) { + return false; + } + return array1.every(function(value,index) { + return value === array2[index]; + }); +}; + /* Push entries onto an array, removing them first if they already exist in the array array: array to modify (assumed to be free of duplicates) @@ -481,6 +498,6 @@ exports.timer = function(base) { m = m - base; } return m; -} +}; })(); diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index 40aaae9cf..584e45dbe 100755 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -315,7 +315,7 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) { {title: draftTitle} } )); - } else if(!this.wiki.isModifiedTiddler(title)) { + } else if(!this.wiki.isDraftModified(title)) { event.type = "tw-cancel-tiddler"; this.dispatchEvent(event); } else if(isConfirmed) { diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 75b6411b2..c838a9d29 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1060,4 +1060,25 @@ exports.readFile = function(file,callback) { } }; +/* +Check whether the specified draft tiddler has been modified +*/ +$tw.Wiki.prototype.isDraftModified = function(title) { + var tiddler = this.getTiddler(title); + if(!tiddler.isDraft()) { + return false; + } + var ignoredFields = ["created", "modified", "title", "draft.title", "draft.of", "tags"], + origTiddler = this.getTiddler(tiddler.fields["draft.of"]); + if(!$tw.utils.isArrayEqual(tiddler.fields.tags,origTiddler.fields.tags)) { + return true; + } + return !Object.keys(tiddler.fields).every(function(field) { + if(ignoredFields.indexOf(field) >= 0) { + return true; + } + return tiddler.fields[field] === origTiddler.fields[field]; + }); +}; + })(); diff --git a/core/ui/EditTemplate/shadow.tid b/core/ui/EditTemplate/shadow.tid new file mode 100644 index 000000000..8592e0ad8 --- /dev/null +++ b/core/ui/EditTemplate/shadow.tid @@ -0,0 +1,19 @@ +title: $:/core/ui/EditTemplate/shadow +tags: $:/tags/EditTemplate + +\define lingo-base() $:/language/EditTemplate/Shadow/ +<$list filter="[all[current]get[draft.of]is[shadow]!is[tiddler]]"> +<div class="tw-message-box"> + +<<lingo Warning>> + +</div> +</$list> + +<$list filter="[all[current]get[draft.of]is[shadow]is[tiddler]]"> +<div class="tw-message-box"> + +<<lingo OverriddenWarning>> + +</div> +</$list> diff --git a/core/ui/EditTemplate/shadowWarning.tid b/core/ui/EditTemplate/shadowWarning.tid deleted file mode 100644 index ba4da6a99..000000000 --- a/core/ui/EditTemplate/shadowWarning.tid +++ /dev/null @@ -1,11 +0,0 @@ -title: $:/core/ui/EditTemplate/shadowWarning -tags: $:/tags/EditTemplate - -\define lingo-base() $:/language/EditTemplate/ -<$list filter="[all[current]get[draft.of]is[shadow]]"> -<div class="tw-message-box"> - -<<lingo Body/ShadowWarning>> - -</div> -</$list> diff --git a/core/wiki/tags/EditTemplate.tid b/core/wiki/tags/EditTemplate.tid index 9a405fb2d..e9c6af98a 100644 --- a/core/wiki/tags/EditTemplate.tid +++ b/core/wiki/tags/EditTemplate.tid @@ -1,2 +1,2 @@ title: $:/tags/EditTemplate -list: [[$:/core/ui/EditTemplate/controls]] [[$:/core/ui/EditTemplate/title]] [[$:/core/ui/EditTemplate/tags]] [[$:/core/ui/EditTemplate/shadowWarning]] [[$:/core/ui/ViewTemplate/classic]] [[$:/core/ui/EditTemplate/body]] [[$:/core/ui/EditTemplate/type]] [[$:/core/ui/EditTemplate/fields]] +list: [[$:/core/ui/EditTemplate/controls]] [[$:/core/ui/EditTemplate/title]] [[$:/core/ui/EditTemplate/tags]] [[$:/core/ui/EditTemplate/shadow]] [[$:/core/ui/ViewTemplate/classic]] [[$:/core/ui/EditTemplate/body]] [[$:/core/ui/EditTemplate/type]] [[$:/core/ui/EditTemplate/fields]]