disable subs field syncying

This commit is contained in:
muhammad-ammar
2018-03-20 16:20:23 +05:00
parent 597566a34f
commit 9d7ed19b64
10 changed files with 43 additions and 363 deletions

View File

@@ -362,31 +362,6 @@ function($, Backbone, _, Utils, Editor, MetadataView, MetadataModel, MetadataCol
}).getValue();
expect(youtubeValue).toEqual('');
});
it('Timed Transcript field is updated', function() {
Utils.Storage.set('sub', 'test_value');
transcripts.syncAdvancedTab(metadataCollection);
var collection = metadataCollection.models,
subValue = collection[1].getValue();
expect(subValue).toEqual('test_value');
});
it('Timed Transcript field is updated just once', function() {
Utils.Storage.set('sub', 'test_value');
var collection = metadataCollection.models,
subModel = collection[1];
spyOn(subModel, 'setValue');
transcripts.syncAdvancedTab(metadataCollection);
transcripts.syncAdvancedTab(metadataCollection);
transcripts.syncAdvancedTab(metadataCollection);
expect(subModel.setValue.calls.count()).toEqual(1);
});
});
});
});

View File

@@ -75,7 +75,6 @@ function($, Backbone, _, Utils, MetadataView, MetadataCollection) {
var result = [],
getField = Utils.getField,
component_locator = this.$el.closest('[data-locator]').data('locator'),
subs = getField(metadataCollection, 'sub'),
values = {},
videoUrl, metadata, modifiedValues;
@@ -89,37 +88,6 @@ function($, Backbone, _, Utils, MetadataView, MetadataCollection) {
modifiedValues = metadataView.getModifiedMetadataValues();
var isSubsModified = (function(values) {
var isSubsChanged = subs.hasChanged('value');
return Boolean(
isSubsChanged &&
(
// If the user changes the field, `values.sub` contains
// string value;
// If the user clicks `clear` button, the field contains
// null value.
// Otherwise, undefined.
_.isString(values.sub) || _.isNull(subs.getValue())
)
);
}(modifiedValues));
// When we change value of `sub` field in the `Advanced`,
// we update data on backend. That provides possibility to remove
// transcripts.
if (isSubsModified) {
metadata = $.extend(true, {}, modifiedValues);
// Save module state
Utils.command('save', component_locator, null, {
metadata: metadata,
current_subs: _.pluck(
Utils.getVideoList(videoUrl.getDisplayValue()),
'video'
)
});
}
// Get values from `Advanced` tab fields (`html5_sources`,
// `youtube_id_1_0`) that should be synchronized.
var html5Sources = getField(metadataCollection, 'html5_sources').getDisplayValue();
@@ -151,17 +119,6 @@ function($, Backbone, _, Utils, MetadataView, MetadataCollection) {
// Synchronize other fields that has the same `field_name` property.
Utils.syncCollections(metadataCollection, this.collection);
if (isSubsModified) {
// When `sub` field is changed, clean Storage to avoid overwriting.
Utils.Storage.remove('sub');
// Trigger `change` event manually if `video_url` model
// isn't changed.
if (!videoUrl.hasChanged()) {
videoUrl.trigger('change');
}
}
},
/**
@@ -177,8 +134,6 @@ function($, Backbone, _, Utils, MetadataView, MetadataCollection) {
*/
syncAdvancedTab: function(metadataCollection, metadataView) {
var getField = Utils.getField,
subsValue = Utils.Storage.get('sub'),
subs = getField(metadataCollection, 'sub'),
html5Sources, youtube, videoUrlValue, result;
// if metadataCollection is not passed, just exit.
@@ -234,14 +189,6 @@ function($, Backbone, _, Utils, MetadataView, MetadataCollection) {
youtube.setValue(result);
}
// If Utils.Storage contain some subtitles, update them.
if (_.isString(subsValue)) {
subs.setValue(subsValue);
// After updating should be removed, because it might overwrite
// subtitles added by user manually.
Utils.Storage.remove('sub');
}
// Synchronize other fields that has the same `field_name` property.
Utils.syncCollections(this.collection, metadataCollection);
},

View File

@@ -104,7 +104,7 @@ function($, Backbone, _, AbstractEditor, Utils, MessageManager) {
self.messenger.render(resp.command, params);
self.checkIsUniqVideoTypes();
// Synchronize transcripts field in the `Advanced` tab.
Utils.Storage.set('sub', resp.subs);
// Utils.Storage.set('sub', resp.subs);
})
.fail(showServerError);
},