mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
@@ -1,6 +1,7 @@
|
||||
var Marionette = require('marionette');
|
||||
var StatusModel = require('../System/StatusModel');
|
||||
require('../Mixins/CopyToClipboard');
|
||||
require('../Mixins/TagInput');
|
||||
|
||||
module.exports = Marionette.Layout.extend({
|
||||
template : 'Calendar/CalendarFeedViewTemplate',
|
||||
@@ -8,6 +9,7 @@ module.exports = Marionette.Layout.extend({
|
||||
ui : {
|
||||
includeUnmonitored : '.x-includeUnmonitored',
|
||||
premiersOnly : '.x-premiersOnly',
|
||||
tags : '.x-tags',
|
||||
icalUrl : '.x-ical-url',
|
||||
icalCopy : '.x-ical-copy',
|
||||
icalWebCal : '.x-ical-webcal'
|
||||
@@ -15,12 +17,15 @@ module.exports = Marionette.Layout.extend({
|
||||
|
||||
events : {
|
||||
'click .x-includeUnmonitored' : '_updateUrl',
|
||||
'click .x-premiersOnly' : '_updateUrl'
|
||||
'click .x-premiersOnly' : '_updateUrl',
|
||||
'itemAdded .x-tags' : '_updateUrl',
|
||||
'itemRemoved .x-tags' : '_updateUrl'
|
||||
},
|
||||
|
||||
onShow : function() {
|
||||
this._updateUrl();
|
||||
this.ui.icalCopy.copyToClipboard(this.ui.icalUrl);
|
||||
this.ui.tags.tagInput({ allowNew: false });
|
||||
},
|
||||
|
||||
_updateUrl : function() {
|
||||
@@ -34,6 +39,10 @@ module.exports = Marionette.Layout.extend({
|
||||
icalUrl += 'premiersOnly=true&';
|
||||
}
|
||||
|
||||
if (this.ui.tags.val()) {
|
||||
icalUrl += 'tags=' + this.ui.tags.val() + '&';
|
||||
}
|
||||
|
||||
icalUrl += 'apikey=' + window.NzbDrone.ApiKey;
|
||||
|
||||
var icalHttpUrl = window.location.protocol + '//' + icalUrl;
|
||||
|
||||
@@ -41,6 +41,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">Tags</label>
|
||||
|
||||
<div class="col-sm-1 col-sm-push-5 help-inline">
|
||||
<i class="icon-sonarr-form-info" title="One or more tags only show matching series" />
|
||||
</div>
|
||||
|
||||
<div class="col-sm-5 col-sm-pull-1">
|
||||
<input type="text" class="form-control x-tags">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">iCal feed</label>
|
||||
<div class="col-sm-1 col-sm-push-8 help-inline">
|
||||
|
||||
+52
-42
@@ -4,10 +4,11 @@ var TagCollection = require('../Tags/TagCollection');
|
||||
var TagModel = require('../Tags/TagModel');
|
||||
require('bootstrap.tagsinput');
|
||||
|
||||
var substringMatcher = function() {
|
||||
var substringMatcher = function(tagCollection) {
|
||||
return function findMatches (q, cb) {
|
||||
var matches = _.select(TagCollection.toJSON(), function(tag) {
|
||||
return tag.label.toLowerCase().indexOf(q.toLowerCase()) > -1;
|
||||
q = q.replace(/[^-_a-z0-9]/gi, '').toLowerCase();
|
||||
var matches = _.select(tagCollection.toJSON(), function(tag) {
|
||||
return tag.label.toLowerCase().indexOf(q) > -1;
|
||||
});
|
||||
cb(matches);
|
||||
};
|
||||
@@ -33,22 +34,27 @@ var originalRemove = $.fn.tagsinput.Constructor.prototype.remove;
|
||||
var originalBuild = $.fn.tagsinput.Constructor.prototype.build;
|
||||
|
||||
$.fn.tagsinput.Constructor.prototype.add = function(item, dontPushVal) {
|
||||
var tagCollection = this.options.tagCollection;
|
||||
|
||||
if (!tagCollection) {
|
||||
originalAdd.call(this, item, dontPushVal);
|
||||
return;
|
||||
}
|
||||
var self = this;
|
||||
|
||||
if (typeof item === 'string' && this.options.tag) {
|
||||
var test = testTag(item);
|
||||
if (item === null || item === '' || !testTag(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var existing = _.find(TagCollection.toJSON(), { label : item });
|
||||
if (typeof item === 'string') {
|
||||
var existing = _.find(tagCollection.toJSON(), { label : item });
|
||||
|
||||
if (existing) {
|
||||
originalAdd.call(this, existing, dontPushVal);
|
||||
} else {
|
||||
} else if (this.options.allowNew) {
|
||||
if (item === null || item === '' || !testTag(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newTag = new TagModel();
|
||||
newTag.set({ label : item.toLowerCase() });
|
||||
TagCollection.add(newTag);
|
||||
tagCollection.add(newTag);
|
||||
|
||||
newTag.save().done(function() {
|
||||
item = newTag.toJSON();
|
||||
@@ -56,12 +62,10 @@ $.fn.tagsinput.Constructor.prototype.add = function(item, dontPushVal) {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
originalAdd.call(this, item, dontPushVal);
|
||||
originalAdd.call(self, item, dontPushVal);
|
||||
}
|
||||
|
||||
if (this.options.tag) {
|
||||
self.$input.typeahead('val', '');
|
||||
}
|
||||
self.$input.typeahead('val', '');
|
||||
};
|
||||
|
||||
$.fn.tagsinput.Constructor.prototype.remove = function(item, dontPushVal) {
|
||||
@@ -104,43 +108,49 @@ $.fn.tagsinput.Constructor.prototype.build = function(options) {
|
||||
};
|
||||
|
||||
$.fn.tagInput = function(options) {
|
||||
options = $.extend({}, { allowNew : true }, options);
|
||||
|
||||
var input = this;
|
||||
var model = options.model;
|
||||
var property = options.property;
|
||||
var tags = getExistingTags(model.get(property));
|
||||
|
||||
var tagInput = $(this).tagsinput({
|
||||
tag : true,
|
||||
freeInput : true,
|
||||
itemValue : 'id',
|
||||
itemText : 'label',
|
||||
trimValue : true,
|
||||
typeaheadjs : {
|
||||
tagCollection : TagCollection,
|
||||
freeInput : true,
|
||||
allowNew : options.allowNew,
|
||||
itemValue : 'id',
|
||||
itemText : 'label',
|
||||
trimValue : true,
|
||||
typeaheadjs : {
|
||||
name : 'tags',
|
||||
displayKey : 'label',
|
||||
source : substringMatcher()
|
||||
source : substringMatcher(TagCollection)
|
||||
}
|
||||
});
|
||||
|
||||
//Override the free input being set to false because we're using objects
|
||||
$(tagInput)[0].options.freeInput = true;
|
||||
|
||||
//Remove any existing tags and re-add them
|
||||
$(this).tagsinput('removeAll');
|
||||
_.each(tags, function(tag) {
|
||||
$(input).tagsinput('add', tag);
|
||||
});
|
||||
$(this).tagsinput('refresh');
|
||||
$(this).on('itemAdded', function(event) {
|
||||
var tags = model.get(property);
|
||||
tags.push(event.item.id);
|
||||
model.set(property, tags);
|
||||
});
|
||||
$(this).on('itemRemoved', function(event) {
|
||||
if (!event.item) {
|
||||
return;
|
||||
}
|
||||
var tags = _.without(model.get(property), event.item.id);
|
||||
model.set(property, tags);
|
||||
});
|
||||
if (model) {
|
||||
var tags = getExistingTags(model.get(property));
|
||||
|
||||
//Remove any existing tags and re-add them
|
||||
$(this).tagsinput('removeAll');
|
||||
_.each(tags, function(tag) {
|
||||
$(input).tagsinput('add', tag);
|
||||
});
|
||||
$(this).tagsinput('refresh');
|
||||
$(this).on('itemAdded', function(event) {
|
||||
var tags = model.get(property);
|
||||
tags.push(event.item.id);
|
||||
model.set(property, tags);
|
||||
});
|
||||
$(this).on('itemRemoved', function(event) {
|
||||
if (!event.item) {
|
||||
return;
|
||||
}
|
||||
var tags = _.without(model.get(property), event.item.id);
|
||||
model.set(property, tags);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user