Skip to content

Instantly share code, notes, and snippets.

@elchele
Created July 30, 2015 20:09
Show Gist options
  • Save elchele/e50f938d0826f4ed915f to your computer and use it in GitHub Desktop.
Save elchele/e50f938d0826f4ed915f to your computer and use it in GitHub Desktop.
Controller for Preview view, used to conditionally hide fields on preview render.
({
/* File: ./custom/modules/Accounts/clients/base/views/preview/preview.js */
extendsFrom: 'PreviewView',
_renderPreview: function(model, collection, fetch, previewId){
var self = this;
// If there are drawers there could be multiple previews, make sure we are only rendering preview for active drawer
if(app.drawer && !app.drawer.isActive(this.$el)){
return; //This preview isn't on the active layout
}
// Close preview if we are already displaying this model
if(this.model && model && (this.model.get("id") == model.get("id") && previewId == this.previewId)) {
// Remove the decoration of the highlighted row
app.events.trigger("list:preview:decorate", false);
// Close the preview panel
app.events.trigger('preview:close');
return;
}
if (app.metadata.getModule(model.module).isBwcEnabled) {
// if module is in BWC mode, just return
return;
}
if (model) {
// Use preview view if available, otherwise fallback to record view
var viewName = 'preview',
previewMeta = app.metadata.getView(model.module, 'preview'),
recordMeta = app.metadata.getView(model.module, 'record');
if (_.isEmpty(previewMeta) || _.isEmpty(previewMeta.panels)) {
viewName = 'record';
}
this.meta = this._previewifyMetadata(_.extend({}, recordMeta, previewMeta));
if (fetch) {
model.fetch({
//Show alerts for this request
showAlerts: true,
success: function(model) {
//Get the value form "Type" field, if set to 'Customer', remove 'website' field
var custType = model.get('account_type');
if (custType === 'Customer')
{
_.each(self.meta.panels, function(panel){
panel.fields = _.filter(panel.fields, function(field){
return field.name != 'website';
});
});
}
self.renderPreview(model, collection);
},
//The view parameter is used at the server end to construct field list
view: viewName
});
} else {
this.renderPreview(model, collection);
}
}
this.previewId = previewId;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment