Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betobaz/b8d1c36338691eecfa00 to your computer and use it in GitHub Desktop.
Save betobaz/b8d1c36338691eecfa00 to your computer and use it in GitHub Desktop.
SugarCRM::Sidecar::list-bottom::Remove loading message
/*
* Your installation or use of this SugarCRM file is subject to the applicable
* terms available at
* http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
* If you do not agree to all of the applicable terms or do not have the
* authority to bind the entity as an authorized representative, then do not
* install or use this SugarCRM file.
*
* Copyright (C) SugarCRM Inc. All rights reserved.
*/
/**
* @class View.Views.Base.ListBottomView
* @alias SUGAR.App.view.views.BaseListBottomView
* @extends View.View
*/
({
events: {
'click [data-action="show-more"]': 'showMoreRecords'
},
initialize: function(options) {
this._super('initialize', [options]);
this._initPagination();
},
/**
* Initialize pagination component in order to react the show more link.
* @private
*/
_initPagination: function() {
this.paginationComponent = _.find(this.layout._components, function(component) {
return _.contains(component.plugins, 'Pagination');
}, this);
},
/**
* Retrieving the next page records by pagination plugin.
*
* Please see the {@link app.plugins.Pagination#getNextPagination}
* for detail.
*/
showMoreRecords: function() {
if (!this.paginationComponent) {
return;
}
this.paginateFetched = false;
this.render();
var options = {};
options.success = _.bind(function() {
this.layout.trigger('list:paginate:success');
this.paginateFetched = true;
this.render();
}, this);
this.paginationComponent.getNextPagination(options);
},
/**
* Assign proper label for 'show more' link.
* Label should be "More <module name>...".
*/
setShowMoreLabel: function() {
var model = this.collection.at(0),
module = model ? model.module : this.context.get('module');
this.showMoreLabel = app.lang.get('TPL_SHOW_MORE_MODULE', module, {
module: new Handlebars.SafeString(app.lang.getModuleName(module, {plural: true}).toLowerCase()),
count: this.collection.length,
offset: this.collection.next_offset >= 0
});
},
/**
* Reset previous collection handlers and
* bind the listeners for new collection.
*/
onCollectionChange: function() {
var prevCollection = this.context.previous('collection');
if (prevCollection) {
prevCollection.off(null, null, this);
}
this.collection = this.context.get('collection');
this.collection.on('add remove reset', this.render, this);
this.render();
},
/**
* {@inheritDoc}
*
* Bind listeners for collection updates.
* The pagination link synchronizes its visibility with the collection's
* status.
*/
bindDataChange: function() {
this.context.on('change:collection', this.onCollectionChange, this);
this.collection.on('add remove reset', this.render, this);
this.before('render', function() {
this.dataFetched = this.paginateFetched !== false && this.collection.dataFetched;
this.showLoadMsg = true;
var filterOptions = this.layout.context.get('filterOptions');
if( filterOptions && filterOptions.auto_apply === false){
this.showLoadMsg = false;
}
if (app.alert.$alerts[0].innerText || !app.acl.hasAccessToModel('list', this.model)) {
this.showLoadMsg = false;
}
var nextOffset = this.collection.next_offset || -1;
if (this.collection.dataFetched && nextOffset === -1) {
this._invisible = true;
this.hide();
return false;
}
this._invisible = false;
this.show();
this.setShowMoreLabel();
}, null, this);
},
/**
* {@inheritDoc}
*
* Avoid to be shown if the view is invisible status.
* Add dashlet placeholder's class in order to handle the custom css style.
*/
show: function() {
if (this._invisible) {
return;
}
this._super('show');
if (!this.paginationComponent) {
return;
}
this.paginationComponent.layout.$el.addClass('pagination');
},
/**
* {@inheritDoc}
*
* Remove pagination custom CSS class on dashlet placeholder.
*/
hide: function() {
this._super('hide');
if (!this.paginationComponent) {
return;
}
this.paginationComponent.layout.$el.removeClass('pagination');
}
})
({ extendsFrom: 'RecordView',
initialize: function(options){
this._super('initialize', [options]);
<other events here>
this.model.on('change:case_primary_contact_c', this.updateAccount, this);
},
updateAccount: function() {
if(!_.isEmpty(this.model.get('contact_id_c')) && !_.isEqual(this.model.get('contact_id_c'),this.model.previous('contact_id_c'))){
var contact_id = this.model.get('contact_id_c'),
url = app.api.buildURL('Contacts/'+contact_id+'/link/accounts_contacts/'),
self = this;
app.api.call('GET', url, null, {
success: _.bind( function (data){
if(data.records.length == 1){
//there is only one account related to the selected contact
//set the account name and id in the Account Relate field.
self.model.set('account_id', data.records[0].id);
self.model.set('account_name', data.records[0].name);
}else if(data.records.length > 1){
//there are multiple Accounts related to this Contact
//create a Collection with these accounts and open a selection list with this
//collection to choose from
var parentModel = self.model,
linkModule = 'Accounts',
accounts = app.data.createBeanCollection( "Accounts", data.records);
app.drawer.open({
layout: 'selection-list',
context: { module: linkModule,
parentModel: parentModel,
collection:accounts,
filterOptions:{
auto_apply:false,
},
}
}, function(selectedModel) {
if (!_.isEmpty(selectedModel)) {
self.model.set('account_id', selectedModel.id);
self.model.set('account_name', selectedModel.name);
}
});
}
}, this),
error:_.bind(function(o){
console.log("Error retrieving Account related to Contact" + o);
}, this),
});
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment