diff options
| author | Eric Anderson <ejona86@gmail.com> | 2010-10-09 17:19:40 -0500 | 
|---|---|---|
| committer | Eric Anderson <ejona86@gmail.com> | 2010-10-09 17:19:40 -0500 | 
| commit | dd4d8d9e3c8176bc444195499dc2f559d6f214b2 (patch) | |
| tree | da9ebb0ca67b6bb7af06a2c76a2f8bc418f7a75d /web/javascript/feed.js | |
| parent | 75d8efcf9f4d908736e1dfb3e2ae9b09fa8b1336 (diff) | |
| download | feed-transmission-master.tar.gz feed-transmission-master.zip  | |
Diffstat (limited to 'web/javascript/feed.js')
| -rw-r--r-- | web/javascript/feed.js | 113 | 
1 files changed, 113 insertions, 0 deletions
diff --git a/web/javascript/feed.js b/web/javascript/feed.js new file mode 100644 index 0000000..1f8c40f --- /dev/null +++ b/web/javascript/feed.js @@ -0,0 +1,113 @@ +function Feed(feedListParent, obj) { +    this.initialize(feedListParent, obj); +} + +Feed.prototype = +{ +	/*-------------------------------------------- +	 * +	 *  C O N S T R U C T O R +	 * +	 *--------------------------------------------*/ +	initialize: function(feedListParent, obj) { +	    this.matches = obj.matches; +	    this.url     = obj.url; +	    this.id      = obj.id; + +        var curThis = this; +	    var top_e = document.createElement('li'); +	    var feed_div = document.createElement('div'); +	    feed_div.appendChild(document.createTextNode(this.url)); +	    var create_new = document.createElement('button'); +	    create_new.appendChild(document.createTextNode("Add Matcher")); +	    create_new.onclick = function() { +	        curThis.showAddMatcher(); +	    }; +	    feed_div.appendChild(create_new); +	    top_e.appendChild(feed_div); +	    var sub_ul = document.createElement("ul"); +	    feed_div.onclick = function() { +	        $(sub_ul).toggle(300); +	    } +	    this._sub_ul = sub_ul; +	    $(this.matches).each(function(index, ele) { +	        curThis.addMatcherUI(ele); +	    }); +	    top_e.appendChild(sub_ul); +	    feedListParent.appendChild(top_e); +	}, +	 +	addMatcherUI: function(obj) { +        var li = document.createElement('li'); +        var del = document.createElement('button'); +        del.appendChild(document.createTextNode("Delete")); +        var curThis = this; +        del.onclick = function() { +	        sendMessage('feed-set', {matchRemove: [obj.id], ids: [curThis.id]}, +	            function(arguments) { +                    curThis.refresh(); +	            }); +        }; +        li.appendChild(del); +        li.appendChild(document.createTextNode(obj.value)); +        this._sub_ul.appendChild(li); +        obj.li = li; +	}, + +	showAddMatcher: function() { +	    this._add_matcher = document.createElement('li'); +        var input = document.createElement('input'); +        input.type = "text"; +        input.value = ".*match some text via a Regular Expression.*"; +	    this._add_matcher.appendChild(input); +	    var button = document.createElement('button'); +	    button.appendChild(document.createTextNode("Add")); +	    var curThis = this; +	    button.onclick = function() { +	        $(button).attr("disabled", "disabled"); +	        sendMessage('feed-set', {matchAdd: [{white: true, value: input.value}], ids: [curThis.id]}, function(arguments) { +                curThis.hideAddMatcher(); +                curThis.refresh(); +	        }); +	    } +	    this._add_matcher.appendChild(button); +	    this._sub_ul.appendChild(this._add_matcher); +	}, +	 +	hideAddMatcher: function() { +	    if (!this._add_matcher) +	        return; +        $(this._add_matcher).remove(); +        this._add_matcher = undefined; +	}, + +	refresh: function() { +	    var curThis = this; +	    sendMessage('feed-get', {fields: ['matches'], ids: [this.id]}, function(arguments) { +	        if (arguments.feeds.length < 1) +	            return +            $.each(arguments.feeds[0].matches, function(index, ele) { +                for (var i = 0; i < curThis.matches.length; i++) { +                    if (curThis.matches[i].id === ele.id) +                        return; +                } +                curThis.matches[curThis.matches.length] = ele; +                curThis.addMatcherUI(ele); +            }); +            var toDelete = []; +            var args = arguments; +            $.each(curThis.matches, function(index, ele) { +                for (var i = 0; i < args.feeds[0].matches.length; i++) { +                    if (args.feeds[0].matches[i].id === ele.id) +                        return; +                } +                toDelete[toDelete.length] = index; +            }); +            $.each(toDelete, function(index, ele) { +                $(curThis.matches[ele].li).remove(); +                delete curThis.matches[ele]; +            }); +	    }); +	} +}; +  | 
