Created
July 13, 2012 01:24
-
-
Save awjrichards-zz/3102170 to your computer and use it in GitHub Desktop.
An attempt at using a template in formatUploadDescription()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/assets/www/js/upload.js b/assets/www/js/upload.js | |
index 5074a0a..1576a8a 100644 | |
--- a/assets/www/js/upload.js | |
+++ b/assets/www/js/upload.js | |
@@ -47,49 +47,45 @@ function dateYMD() { | |
} | |
function formatUploadDescription( monument, campaignConfig, username ) { | |
- var idTemplate = campaignConfig.idField, | |
- idField = idTemplate.replace( '$1', monument.id ), | |
- license = campaignConfig.defaultOwnWorkLicence, // note the typo in the API field | |
- ourCategories = [ | |
+ var ourCategories = [ | |
'Mobile upload', | |
'Uploaded with Android WLM App', | |
'UA: ' + navigator.userAgent.match( /Android (.*?)(?=\))/g ) | |
], | |
- cats = campaignConfig.defaultCategories. | |
- concat( campaignConfig.autoCategories ). | |
- concat( ourCategories ), | |
- autoWikiText = campaignConfig.autoWikiText; | |
- | |
- var desc = ''; | |
- desc += '=={{int:filedesc}}==\n'; | |
- desc += '{{Information\n'; | |
- desc += '|description='; | |
- | |
- desc += '{{' + monument.lang + '|1=' + monument.name + '}}\n'; | |
- desc += idField + '\n'; | |
- | |
- desc += '|date=' + dateYMD() + '\n'; | |
- desc += '|source={{own}}\n'; | |
- desc += '|author=[[User:' + username + ']]\n'; | |
- desc += '|permission=\n'; | |
- desc += '|other_versions=\n'; | |
- desc += '|other_fields=\n'; | |
- desc += '}}\n'; | |
- | |
- desc += '\n'; | |
- | |
- desc += '=={{int:license-header}}==\n'; | |
- desc += '{{self|' + license + '}}\n'; | |
- | |
- desc += '\n'; | |
- | |
- if ( autoWikiText.length ) { | |
- desc += autoWikiText + '\n'; | |
- } | |
- | |
- cats.forEach( function( cat ) { | |
- desc += '[[Category:' + cat + ']]\n'; | |
- }); | |
- | |
- return desc; | |
+ descData = { | |
+ idField: campaignConfig.idField.replace( '$1', monument.id ), | |
+ license: campaignConfig.defaultOwnWorkLicence, // note the typo in the API field | |
+ username: username, | |
+ autoWikiText: campaignConfig.autoWikiText, | |
+ cats: campaignConfig.defaultCategories. | |
+ concat( campaignConfig.autoCategories ). | |
+ concat( ourCategories ), | |
+ date: dateYMD() | |
+ }, | |
+ desc = "\ | |
+ =={{int:filedesc}}==\n \ | |
+ {{Information\n \ | |
+ |description={{<%= descData.description %>}}\n \ | |
+ <%= idField %>\n \ | |
+ |date=<%= descData.date %>\n \ | |
+ |source={{own}}\n \ | |
+ |author=[[User:<%= descData.username %>]]\n \ | |
+ |permission=\n \ | |
+ |other_versions=\n \ | |
+ |other_fields=\n \ | |
+ }}\n \ | |
+ \n\ | |
+ =={{int:license-header}}==\n \ | |
+ {{self|<%= descData.license %>}}\n \ | |
+ \n\ | |
+ <% if (descData.autoWikiText.length) { %> \ | |
+ <%= descData.autoWikiText %>\n \ | |
+ <% } %> \ | |
+ \ | |
+ <% ._each( descData.cats, function( cat ) { %> \ | |
+ [[Category:<%= cat %>]]\n \ | |
+ <% }); %> \ | |
+ "; | |
+ | |
+ return ._template( desc, { descData: descData } ); | |
} |
We're loading in the template in js anyway :) Also being an app page load problems go away...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Won't adding the template to index.html mean we're loading a bunch of unnecessary stuff when the app loads? Would it make sense to put this in a separate template?