Skip to content

Commit

Permalink
Merge pull request #2417 from adaptlearning/issue/2416
Browse files Browse the repository at this point in the history
Fix reading of asset type from schema
  • Loading branch information
tomgreenfield authored Oct 1, 2019
2 parents 234fdab + 0602be7 commit 725807f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ define(function(require) {
postRender: function() {
this.setupSubViews();
this.setupFilterAndSearchView();
if (this.options.assetType === "Asset:image" && Origin.scaffold.getCurrentModel().get('_component') === 'graphic') {
if (this.options.assetType === "image" && Origin.scaffold.getCurrentModel().get('_component') === 'graphic') {
this.setupImageAutofillButton();
}
this.resizePanels();
},

setupSubViews: function() {
this.search = {};
// Replace Asset and : so we can have both filtered and all asset types
var assetType = this.options.assetType.replace('Asset', '').replace(':', '');

var assetType = this.options.assetType;

if (assetType) {
var filters = [assetType];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ define(function(require) {
if (!fieldView) {
return;
}
if (fieldView.schema.inputType === 'ColourPicker') {
var inputType = fieldView.schema.inputType.type || fieldView.schema.inputType;
if (inputType === 'ColourPicker') {
fieldView.setValue(value);
} else if (typeof fieldView.schema.inputType === 'string' && fieldView.schema.inputType.indexOf('Asset:') > -1) {
} else if (inputType.indexOf('Asset') > -1) {
fieldView.setValue(value);
fieldView.render();
$('div[data-editor-id*="' + key + '"]').append(fieldView.editor.$el);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ define([

Origin.trigger('modal:open', AssetManagementModalView, {
collection: new AssetCollection,
assetType: 'Asset:image',
assetType: 'image',
_shouldShowScrollbar: false,
onUpdate: function(data) {
if (!data) return;
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/modules/scaffold/views/scaffoldAssetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ define([

var ScaffoldAssetView = Backbone.Form.editors.Base.extend({

assetType: null,

events: {
'change input': function() { this.trigger('change', this); },
'focus input': function() { this.trigger('focus', this); },
Expand Down Expand Up @@ -52,9 +54,13 @@ define([
var inputType = this.schema.inputType;
var dataUrl = Helpers.isAssetExternal(this.value) ? this.value : '';

this.assetType = typeof inputType === 'string' ?
inputType.replace(/Asset|:/g, '') :
inputType.media;

this.$el.html(Handlebars.templates[this.constructor.template]({
value: this.value,
type: inputType.media || inputType.replace('Asset:', ''),
type: this.assetType,
url: id ? 'api/asset/serve/' + id : dataUrl,
thumbUrl: id ? 'api/asset/thumb/' + id : dataUrl
}));
Expand Down Expand Up @@ -200,7 +206,7 @@ define([

Origin.trigger('modal:open', AssetManagementModalView, {
collection: new AssetCollection,
assetType: this.schema.inputType,
assetType: this.assetType,
_shouldShowScrollbar: false,
onUpdate: function(data) {
if (!data) return;
Expand Down
6 changes: 4 additions & 2 deletions lib/outputmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,13 @@ OutputPlugin.prototype.writeThemeVariables = function(courseId, theme, themeVari
function(seriesCallback) {
// Create LESS for properties
async.each(Object.keys(props), function(prop, innerCallback) {
var themeProperty = theme.properties.variables[prop];
var inputType = themeProperty.inputType;
// Check if the user has customised any properties
if (savedSettings.hasOwnProperty(prop) && theme.properties.variables[prop].default !== savedSettings[prop]) {
if (savedSettings.hasOwnProperty(prop) && themeProperty.default !== savedSettings[prop]) {
// The user has customised this property
// Check if processing an image asset
if (theme.properties.variables[prop].inputType === 'Asset:image') {
if (inputType.media === 'image' || inputType === 'Asset:image') {
// Split the path so we can process the filename
var assetPathArray = savedSettings[prop].split('/');
// Encode the filename (removing spaces, etc.)
Expand Down

0 comments on commit 725807f

Please sign in to comment.