Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google News dashlet for Sugar 7.8+
<?php
/* File: ./custom/Extension/application/Ext/Language/en_us.news.lang.ext.php */
$app_strings['LBL_DASHLET_NEWS_NAME'] = 'Google News';
$app_strings['LBL_DASHLET_NEWS_DESC'] = 'Google News search results for the current Account record.';
?>
{{!--
/* File: ./custom/clients/base/views/news/news.hbs
*
* Date: July 27, 2016
*
* Author: Angel Magaña
*
* Description: Adjustment to News dashlet Handlebars template
*
*/
--}}
{{#if feed.entries}}
{{#each feed.entries}}
<div class="news-article">
<h5><a href="{{link}}">{{{title}}}</a></h5>
<p>{{{description}}}</p>
</div>
{{/each}}
{{else}}
<div class="block-footer">{{str "LBL_NO_DATA_AVAILABLE"}}</div>
{{/if}}
({
/* File: ./custom/clients/base/views/news/news.js
*
* Date: April 4, 2017
*
* Author: Angel Magaña
*
* Description: Adjustment to News dashlet to use RSS instead of retired Google API
*
*/
plugins: ['Dashlet'],
initDashlet: function() {
this.model.on("change:name", this.loadData, this);
},
loadData: function (options) {
var self = this;
if(_.isUndefined(this.model)){
return;
}
var name = this.model.get("account_name") || this.model.get('name') || this.model.get('full_name'),
limit = parseInt(this.settings.get('limit') || 5, 10);
if (_.isEmpty(name)) {
return;
}
//Need to clean up spaces
name = name.replace(/ /g, '+');
var url = encodeURIComponent('https://news.google.com/news/section?q=' + name + '&output=rss');
app.api.call('GET', app.api.buildURL('rssfeed?feed_url=' + url), {}, {
success: function(data){
_.extend(self, data);
self.render();
}
});
}
})
<?php
/* File: ./custom/clients/base/views/news/news.php */
$viewdefs['base']['view']['news'] = array(
'dashlets' => array(
array(
'label' => 'LBL_DASHLET_NEWS_NAME',
'description' => 'LBL_DASHLET_NEWS_DESC',
'config' => array(
),
'preview' => array(
),
'filter' => array(
'module' => array(
'Accounts',
),
'view' => 'record'
),
),
),
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment