test if Embedly key exists, and if not show message

This commit is contained in:
Sacha Greif 2014-12-11 15:36:49 +09:00
parent 09885700b0
commit baf7aec813
5 changed files with 26 additions and 2 deletions

View file

@ -1,5 +1,6 @@
{
"thumbnail": "Thumbnail",
"thumbnailUrl": "Thumbnail",
"clear_thumbnail": "Clear Thumbnail"
"clear_thumbnail": "Clear Thumbnail",
"please_fill_in_embedly_key": "Please fill in your Embedly API key to enable thumbnails."
}

View file

@ -1,4 +1,6 @@
{
"thumbnail": "Aperçu",
"thumbnailUrl": "Aperçu"
"thumbnailUrl": "Aperçu",
"clear_thumbnail": "Effacer l'aperçu",
"please_fill_in_embedly_key": "Veuillez fournir une clé API Embedly pour activer les aperçus."
}

View file

@ -1,8 +1,12 @@
<template name="afPostThumbnail">
{{#if embedlyKeyExists}}
<div class="post-thumbnail-container" style="{{style}}">
<img src="{{this.value}}" class="post-thumbnail-preview" style="{{style}}"/>
<div class="post-thumbnail-loading">{{>spinner}}</div>
</div>
<input type="hidden" value="{{this.value}}" {{this.atts}}/>
<a href="#" class="remove-thumbnail-link">{{_ 'clear_thumbnail'}}</a>
{{else}}
<p>{{_ "please_fill_in_embedly_key"}}</p>
{{/if}}
</template>

View file

@ -2,6 +2,16 @@ AutoForm.addInputType("bootstrap-postthumbnail", {
template: "afPostThumbnail"
});
Template.afPostThumbnail.created = function () {
var instance = this;
instance.embedlyKeyExists = new ReactiveVar(false);
// embedly key is not published to client, so we need a method to test if it has been provided or not
Meteor.call('embedlyKeyExists', function (error, result) {
if (result)
instance.embedlyKeyExists.set(result);
});
}
Template.afPostThumbnail.helpers({
atts: function addFormControlAtts() {
var atts = _.clone(this.atts);
@ -13,6 +23,10 @@ Template.afPostThumbnail.helpers({
var thumbnailWidth = getSetting('thumbnailWidth', 200);
var thumbnailHeight = getSetting('thumbnailHeight', 125);
return "width: "+thumbnailWidth+"px; height: "+thumbnailHeight+"px;"
},
embedlyKeyExists: function () {
// haven't found a better way to do this yet…
return Template.instance().embedlyKeyExists.get();
}
});

View file

@ -45,6 +45,9 @@ Meteor.methods({
},
getEmbedlyData: function (url) {
return getEmbedlyData(url);
},
embedlyKeyExists: function () {
return !!getSetting('embedlyKey');
}
});