<script type="text/javascript" src="../../static/MochiKit/MochiKit.js"></script>
<script type="text/javascript">
MochiKit.DOM.addLoadEvent(location = "../../#config-rss");
</script>
<a href="${helpuri}Configure+RSS-0-7" id="help" target="_blank">$T('menu-help')</a>



<h3>$T('configRSS')</h3>

<!--#if $active_feed#-->

  <!--#set $feed = $active_feed#-->
  <div class="EntryBlock">

  <p><a href="#" onClick="javascript:lr('config/rss',''); return false;">&laquo; $T('back')</a></p>

<fieldset class="EntryFieldSet">


  <legend <!--#if $rss[$feed]['enable'] then 'class="feedEnabled"' else 'class="feedDisabled"'#-->><input type="checkbox" onclick="javascript:submitconfig('config/rss/toggle_rss_feed', '','update_$feed','1' )"  name="enable" <!--#if $rss[$feed]['enable'] then "CHECKED" else "" #-->/>
  $T('feed') $feed</legend>
  <hr />
  <div class="EntryBlock" id="update_$feed">

  <input type="text" size="92" name="uri" value="$rss[$feed]['uri']"/>
  <input type="submit" onclick="javascript:if (confirm('$T('confirm').replace("'","`") ')) {submitconfig('config/rss/del_rss_feed', '','update_$feed','1' )}" value="$T('button-delFeed')"/>
  <input type="submit" onClick="javascript:lr('config/rss/test_rss_feed','feed=$feed'); return false;" value="$T('button-preFeed')"/>
  <input type="submit" onClick="javascript:lr('config/rss/download_rss_feed','feed=$feed'); return false;" value="$T('button-forceFeed')"/>
  <br/><br/>

  <!--#if $rss[$feed]['pick_cat']#-->
    <select name="cat">
      <optgroup label="$T('category')">
        <!--#for $ct in $cat_list#-->
          <option value="$ct" <!--#if $ct == $rss[$feed]['cat'] then "selected" else ""#-->>$Tspec($ct)</option>
        <!--#end for#-->
      </optgroup>
    </select>
  <!--#end if#-->
  <select name="pp">
    <optgroup label="$T('pp')">
      <option value="" <!--#if $rss[$feed]['pp'] == "" then 'selected' else ''#-->>$T('default')</option>
      <option value="0" <!--#if $rss[$feed]['pp'] == "0" then 'selected' else ''#-->>$T('none')</option>
      <option value="1" <!--#if $rss[$feed]['pp'] == "1" then 'selected' else ''#-->>$T('pp-repair')</option>
      <option value="2" <!--#if $rss[$feed]['pp'] == "2" then 'selected' else ''#-->>$T('pp-unpack')</option>
      <option value="3" <!--#if $rss[$feed]['pp'] == "3" then 'selected' else ''#-->>$T('pp-delete')</option>
    </optgroup>
  </select>
  <!--#if $rss[$feed]['pick_script']#-->
    <select name="script">
      <optgroup label="$T('script')">
      <!--#for $sc in $script_list#-->
        <option value="$sc" <!--#if $sc == $rss[$feed]['script'] then "selected" else ""#-->>$Tspec($sc)</option>
      <!--#end for#-->
    </optgroup>
    </select>
  <!--#end if#-->
  <select name="priority">
  <optgroup label="$T('priority')">
    <option value="-100" <!--#if $rss[$feed]['priority'] == -100 then 'selected' else ''#-->>$T('default')</option>
    <option value="2" <!--#if $rss[$feed]['priority'] == 2 then 'selected' else ''#-->>$T('pr-force')</option>
    <option value="1" <!--#if $rss[$feed]['priority'] == 1 then 'selected' else ''#-->>$T('pr-high')</option>
    <option value="0" <!--#if $rss[$feed]['priority'] == 0 then 'selected' else ''#-->>$T('pr-normal')</option>
    <option value="-1" <!--#if $rss[$feed]['priority'] == -1 then 'selected' else ''#-->>$T('pr-low')</option>
    <option value="-2" <!--#if $rss[$feed]['priority'] == -2 then 'selected' else ''#-->>$T('pr-paused')</option>
  </optgroup>
  </select>
  <input type="hidden" name="feed" value="$feed"/>
  <!--<input type="checkbox" onclick="javascript:submitconfig('config/rss/toggle_rss_feed', '','update_$feed','1' )"  name="enable" <!--#if $rss[$feed]['enable'] then "CHECKED" else "" #-->/>Scheduled -->
  <input type="submit" value="$T('button-save')" onclick="javascript:submitconfig('config/rss/upd_rss_feed', this,'update_$feed','1' )" />

  </fieldset>

  </div>
  <br/>

  <table id="rssTable">
  <thead>
    <tr>
      <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
      <th>&nbsp;</th>
      <th>$T('rss-order')</th>
      <th>$T('rss-type')</th>
      <th>$T('rss-filter')</th>
      <!--#if $rss[$feed]['pick_cat']#--> <th>$T('category')</th> <!--#end if#-->
      <th>Mode</th>
      <!--#if $rss[$feed]['pick_script']#--> <th>$T('script')</th> <!--#end if#-->
      <th>$T('priority')</th>
      <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
    </tr>
  </thead>
  <tbody>
  <tr id="$feed+new_filter">
    <td></td>
    <td><input type="checkbox" name="enabled" value="1" checked="checked" /></td>
    <td></td>
    <td>
      <select name="filter_type">
        <option value="A" selected /> $T('rss-accept')</option>
        <option value="M" /> $T('rss-must')</option>
        <option value="R" /> $T('rss-reject')</option>
        <option value="C" /> $T('rss-mustcat')</option>
      </select>
    </td>
    <td><input type="text" size="40" class="filter_text fill-td" name="filter_text" value=""></td>
    <!--#if $rss[$feed]['pick_cat']#-->
      <td>
        <select name="cat">
        <!--#for $ct in $cat_list#-->
          <option value="$ct" <!--#if $ct == "Default" then "selected" else ""#-->>$Tspec($ct)</option>
        <!--#end for#-->
        </select>
      </td>
    <!--#end if#-->
    <td>
      <select name="pp">
        <option value="" selected>$T('default')</option>
        <option value="0">$T('none')</option>
        <option value="1">$T('pp-repair')</option>
        <option value="2">$T('pp-unpack')</option>
        <option value="3">$T('pp-delete')</option>
      </select>
    </td>
    <!--#if $rss[$feed]['pick_script']#-->
      <td>
        <select name="script">
        <!--#for $sc in $script_list#-->
          <option value="$sc" <!--#if $sc == "Default" then "selected" else ""#-->>$Tspec($sc)</option>
        <!--#end for#-->
        </select>
      </td>
    <td>
      <select name="priority">
        <option value="-100" selected>$T('default')</option>
        <option value="2" >$T('pr-force')</option>
        <option value="1" >$T('pr-high')</option>
        <option value="0" >$T('pr-normal')</option>
        <option value="-1">$T('pr-low')</option>
        <option value="-2">$T('pr-paused')</option>
      </select>
    </td>

  <!--#end if#-->
  <td>
  <input type="hidden" value="$rss[$feed]['filtercount']" name="index">
  <input type="hidden" value="$feed" name="feed">
  <input type="submit" value="$T('button-save')"  onclick="javascript:submitconfig('config/rss/upd_rss_filter', this,'$feed+new_filter','1' )">
  </td>
</tr>



  <!--#set $fnum = 0#-->


  <!--#for $filter in $rss[$feed].filters#-->
  <tr class="odd" id="$feed+$fnum">
    <td>
      <input type="submit" value="$T('rss-delFilter')" onclick="javascript:lr('config/rss/del_rss_filter','index=$fnum&feed=$feed')" />
    </td>
  <td>
    <input type="checkbox" name="enabled" value="1" <!--#if $filter[6] == '1' then 'checked="checked"' else ""#--> />
  </td>
  <td>
    <input type="text" size="3" name="new_index" value=$fnum>
  </td>
  <td>
    <select name="filter_type">
      <option value="A" <!--#if $filter[3] == "A" then "selected" else ""#--> /> $T('rss-accept')</option>
      <option value="M" <!--#if $filter[3] == "M" then "selected" else ""#--> /> $T('rss-must')</option>
      <option value="R" <!--#if $filter[3] == "R" then "selected" else ""#--> /> $T('rss-reject')</option>
      <option value="C" <!--#if $filter[3] == "C" then "selected" else ""#--> /> $T('rss-mustcat')</option>
    </select>
  </td>
  <td>
  <input type="text" size="40" class="filter_text fill-td" name="filter_text" value="$filter[4]"/></td>
  <!--#if $rss[$feed]['pick_cat']#-->
  <td>
    <select name="cat">
    <!--#for $ct in $cat_list#-->
      <option value="$ct" <!--#if $ct == $filter[0] then "selected" else ""#-->>$Tspec($ct)</option>
    <!--#end for#-->
    </select>
  </td>
  <!--#end if#-->

  <td>
    <select name="pp">
      <option value="" <!--#if $filter[1] == "0" then 'selected' else ''#-->>$T('default')</option>
      <option value="0" <!--#if $filter[1] == "0" then 'selected' else ''#-->>$T('none')</option>
      <option value="1" <!--#if $filter[1] == "1" then 'selected' else ''#-->>$T('pp-repair')</option>
      <option value="2" <!--#if $filter[1] == "2" then 'selected' else ''#-->>$T('pp-unpack')</option>
      <option value="3" <!--#if $filter[1] == "3" then 'selected' else ''#-->>$T('pp-delete')</option>
    </select>
  </td>
<!--#if $rss[$feed]['pick_script']#-->
  <td>
  <select name="script">
  <!--#for $sc in $script_list#-->
    <option value="$sc" <!--#if $sc == $filter[2] then "selected" else ""#-->>$Tspec($sc)</option>
  <!--#end for#-->
  </select>
</td>
<!--#end if#-->
<td>
  <select name="priority">
    <option value="-100" <!--#if $filter[5] == "-100" then 'selected' else ''#-->>$T('default')</option>
    <option value="2"    <!--#if $filter[5] == "2"    then "selected" else ""#-->>$T('pr-force')</option>
    <option value="1"    <!--#if $filter[5] == "1"    then "selected" else ""#-->>$T('pr-high')</option>
    <option value="0"    <!--#if $filter[5] == "0"    then "selected" else ""#-->>$T('pr-normal')</option>
    <option value="-1"   <!--#if $filter[5] == "-1"   then "selected" else ""#-->>$T('pr-low')</option>
    <option value="-2"   <!--#if $filter[5] == "-2"   then "selected" else ""#-->>$T('pr-paused')</option>
  </select>
</td>
<td>
<input type="hidden" name="index" value="$fnum"/>
<input type="hidden" name="feed" value="$feed"/>
<input type="submit" value="$T('button-save')" onclick="javascript:submitconfig('config/rss/upd_rss_filter', this,'$feed+$fnum','1' )"/>
<!--#if not $rss[$feed].filter_states[$fnum]#-->&nbsp;&nbsp;$T('Incorrect filter')<!--#end if#-->
</td>

  </tr>
    <!--#set $fnum = $fnum+1#-->
  <!--#end for#-->
</tbody>
  </table>
  </fieldset>

  <!--#if $error#-->
    <br/><b>$error</b><br/><br/>
  <!--#end if#-->

  <br/>
  <h3>$T('rss-matched')</h3>
  <table id="catTable">
    <tr>
      <th>&nbsp;</th>
      <th>&nbsp;$T('rss-skip')&nbsp;</th>
      <th>&nbsp;$T('rss-filter')&nbsp;</th>
      <th>$T('sort-title')</th>
    </tr>
  <!--#set $odd = False#-->
  <!--#for $job in $matched#-->
    <!--#set $odd = not $odd#-->
    <tr class="<!--#if $odd then "odd" else "even"#-->">
    <td><form action="config/rss/download" method="get">
      <input type="hidden" name="url" value="$job[0]"/>
      <input type="hidden" name="nzbname" value="$job[4]"/>
      <input type="hidden" name="feed" value="$feed"/>
      <input type="hidden" name="session" value="$session" />
      <input type="submit" value="$T('link-download')"/>
    </form>
    </td>
    <td>$job[2]</td>
    <td>$job[3]</td>
    <td>$job[1]</td>
    </tr>
  <!--#end for#-->
  </table>

  <br/>
  <h3>$T('rss-notMatched')</h3>
  <table id="catTable">
    <tr>
      <th>&nbsp;</th>
      <th>&nbsp;$T('rss-skip')&nbsp;</th>
      <th>&nbsp;$T('rss-filter')&nbsp;</th>
      <th>$T('sort-title')</th>
    </tr>
  <!--#set $odd = False#-->
  <!--#for $job in $unmatched#-->
    <!--#set $odd = not $odd#-->
    <tr class="<!--#if $odd then "odd" else "even"#-->">
    <td><form action="config/rss/download" method="get">
      <input type="hidden" name="url" value="$job[0]"/>
      <input type="hidden" name="nzbname" value="$job[4]"/>
      <input type="hidden" value="$feed" name="feed"/>
      <input type="hidden" name="session" value="$session" />
      <input type="submit" value="$T('link-download')"/>
    </form>
    </td>
    <td>$job[2]</td>
    <td>$job[3]</td>
    <td>$job[1]</td>
    </tr>
  <!--#end for#-->
  </table>

  <br/>
  <h3>$T('rss-done')</h3>
  <!--#if $downloaded#-->
    <form id="clean_rss_jobs">
      <input type="hidden" name="feed" value="$feed"/>
      <input type="hidden" name="session" value="$session" />
      <input type="submit" value="$T('button-clear')" onclick="javascript:submitconfig('config/rss/clean_rss_jobs', this,'clean_rss_jobs','1' ); return false;" />
    </form>
  <!--#end if#-->
  <table id="catTable">
    <tr>
      <th>$T('sort-title')</th>
    </tr>
  <!--#set $odd = False#-->
  <!--#for $job in $downloaded#-->
    <!--#set $odd = not $odd#-->
    <tr class="<!--#if $odd then "odd" else "even"#-->">
    <td>$job</td>
    </tr>
  <!--#end for#-->
  </table>

<!--#else#-->
  <div class="EntryBlock">
  <form id="add_feed">
  <fieldset class="EntryFieldSet">
  <legend>$T('newFeedURI')</legend>
    <input type="text" size="10" name="feed" value="$feed"/>&nbsp;
    <input type="text" size="104" name="uri" value=""/><br/><br/>
    <input type="hidden" name="session" value="$session" />
    <input type="submit" value="$T('button-add')" onclick="javascript:submitconfig('config/rss/add_rss_feed', this,'add_feed','1' )" />
  </fieldset>
  </form>
  </div>

  <p>$T('explain-RSS')</p>

  <div class="EntryBlock">
  <form id="save_rate">
  <fieldset class="EntryFieldSet">
  <legend>$T('opt-rss_rate')</legend>
    <input type="text" name="rss_rate" value="$rss_rate">
    <input type="hidden" name="session" value="$session" />
    <input type="submit" value="$T('button-save')" onclick="javascript:submitconfig('config/rss/save_rss_rate', this,'save_rate','1' )" />
    <br/>
    $T('explain-rss_rate')
  </fieldset>
  </form>
  </div>


  <table id="catTable">
    <tr>
      <th></th>
      <th>$T('enabled')</th>
      <th>$T('feed')</th>
      <th>URL</th>
    </tr>
  <!--#set $odd = False#-->
  <!--#for $feed in sorted($rss.keys(), cmp=lambda x,y: cmp(x.lower(), y.lower()))#-->
    <!--#set $odd = not $odd#-->
    <tr class="<!--#if $odd then "odd" else "even"#-->">
      <td><form id="delete_$feed">
        <input type="hidden" name="session" value="$session" />
        <input type="hidden" value="$feed" name="feed" />
        <input type="submit" value="$T('button-del')" onclick="if(confirm('$T('confirm').replace("'","`")')){javascript:submitconfig('config/rss/del_rss_feed', this,'delete_$feed','1' )} else return false;" />
      </form>
      </td>
      <td><form id="toggle_$feed">
        <input type="hidden" name="session" value="$session" />
        <input type="hidden" value="$feed" name="feed" />
        <input type="hidden" value="1" name="table" />
        <input type="checkbox" onclick="javascript:submitconfig('config/rss/toggle_rss_feed', this,'toggle_$feed','1' )" name="enable" <!--#if $rss[$feed]['enable'] then "CHECKED" else "" #-->/>
        </form>
      </td>
      <td><a href="#/config/rss/" onClick="lr('./config/rss/','feed=$rss[$feed]['link']', 0, 0);">$feed</a></td>
      <td>$rss[$feed]['uri']</td>
    </tr>
  <!--#end for#-->
</table>

<!--#end if#-->


