Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making the external assets form optional #2602

Merged
merged 5 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/asset_manager/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,8 @@ export default {
// var stopUpload = true;
// if(stopUpload) return false;
// }
beforeUpload: null
beforeUpload: null,

// Toggles visiblity of assets url input
showUrlInput: true
};
25 changes: 16 additions & 9 deletions src/asset_manager/view/AssetsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ export default Backbone.View.extend({
},

template({ pfx, ppfx, em, ...view }) {
let form = '';
if (this.config.showUrlInput) {
form = `
<form class="${pfx}add-asset">
<div class="${ppfx}field ${pfx}add-field">
<input placeholder="${em && em.t('assetManager.inputPlh')}"/>
</div>
<button class="${ppfx}btn-prim">${em &&
em.t('assetManager.addButton')}</button>
<div style="clear:both"></div>
</form>
`;
}

return `
<div class="${pfx}assets-cont">
<div class="${pfx}assets-header">
<form class="${pfx}add-asset">
<div class="${ppfx}field ${pfx}add-field">
<input placeholder="${em && em.t('assetManager.inputPlh')}"/>
</div>
<button class="${ppfx}btn-prim">${em &&
em.t('assetManager.addButton')}</button>
<div style="clear:both"></div>
</form>
${form}
</div>
<div class="${pfx}assets" data-el="assets"></div>
<div style="clear:both"></div>
Expand Down Expand Up @@ -46,7 +53,7 @@ export default Backbone.View.extend({
handleSubmit(e) {
e.preventDefault();
const input = this.getAddInput();
const url = input.value.trim();
const url = input && input.value.trim();
const handleAdd = this.config.handleAdd;

if (!url) {
Expand Down
65 changes: 56 additions & 9 deletions test/specs/asset_manager/view/AssetsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('AssetsView', () => {
globalCollection: new Assets([]),
fu: new FileUploader({})
});
obj = obj;
document.body.innerHTML = '<div id="fixtures"></div>';
obj.render();
document.body.querySelector('#fixtures').appendChild(obj.el);
Expand Down Expand Up @@ -68,16 +67,64 @@ describe('AssetsView', () => {
expect(obj.getAssetsEl()).toBeTruthy();
});

test('Returns not empty url input', () => {
expect(obj.getAddInput()).toBeTruthy();
describe('Assets input is enabled', () => {
var obj;
var coll;
coll = new Assets([]);

beforeEach(() => {
var config = {
showUrlInput: true
};

obj = new AssetsView({
config: config,
collection: coll,
globalCollection: new Assets([]),
fu: new FileUploader({})
});
document.body.innerHTML = '<div id="fixtures"></div>';
obj.render();
document.body.querySelector('#fixtures').appendChild(obj.el);
});

test('Returns not empty url input', () => {
expect(obj.getAddInput()).toBeTruthy();
});

test('Add image asset from input string', () => {
obj.getAddInput().value = 'test';
obj.handleSubmit({
preventDefault() {}
});
var asset = obj.options.globalCollection.at(0);
expect(asset.get('src')).toEqual('test');
});
});

test('Add image asset from input string', () => {
obj.getAddInput().value = 'test';
obj.handleSubmit({
preventDefault() {}
describe('Assets inputs is disabled', () => {
var obj;
var coll;

beforeEach(() => {
var config = {
showUrlInput: false
};

coll = new Assets([]);
obj = new AssetsView({
config: config,
collection: coll,
globalCollection: new Assets([]),
fu: new FileUploader({})
});
document.body.innerHTML = '<div id="fixtures"></div>';
obj.render();
document.body.querySelector('#fixtures').appendChild(obj.el);
});

test('No presence of url input', () => {
expect(obj.getAddInput()).toBeFalsy();
});
var asset = obj.options.globalCollection.at(0);
expect(asset.get('src')).toEqual('test');
});
});