script rewrite & tidy
This commit is contained in:
parent
dc7cb69e4b
commit
b45db15f85
|
@ -1,9 +1,9 @@
|
|||
Package: sweeper
|
||||
Priority: optional
|
||||
Section: misc
|
||||
Version: 1.0.11
|
||||
Version: 1.0.12
|
||||
Architecture: mipsel
|
||||
Maintainer: af123@hummypkg.org.uk
|
||||
Depends: webif(>=1.0.14)
|
||||
Depends: webif(>=1.0.14-2)
|
||||
Description: Automatically manage single recording files. [Web Interface. Multi-folder support.]
|
||||
Tags: http://hummy.tv/forum/threads/3843/
|
||||
|
|
|
@ -106,9 +106,9 @@ puts {
|
|||
<div class=hidden id=newrule title="Add New Rule">
|
||||
Rule Type:
|
||||
<input name=newrule_type id=newrule_type_file type=radio
|
||||
value='file' checked/>File
|
||||
value='file' checked />Process Files
|
||||
<input name=newrule_type id=newrule_type_folder type=radio
|
||||
value='folder' />Folder
|
||||
value='folder' />Process Folders
|
||||
<br>
|
||||
Description:
|
||||
<input name=newrule_comment id=newrule_comment size=80 maxlength=255 />
|
||||
|
|
|
@ -13,17 +13,17 @@ if {$dir eq "" || $dir eq $root} {
|
|||
set cf "/mod/etc/sweeper.conf"
|
||||
} else {
|
||||
set cf "$dir/.sweeper"
|
||||
if {![string match "$root/*/.sweeper" $cf]} {
|
||||
puts "Bad directory, $dir"
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
if {![string match "$root/*" $cf]} {
|
||||
puts "Bad directory, $dir"
|
||||
exit
|
||||
}
|
||||
set data [cgi_get data "-"]
|
||||
|
||||
if {$data eq "-" || $data eq ""} {
|
||||
if {[file exists $cf]} { file delete $cf }
|
||||
puts "Configuration file $cf deleted."
|
||||
puts "Configuration file $cf deleted successfully."
|
||||
exit
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,6 @@ if {[catch {set fp [open $cf w]} msg]} {
|
|||
} else {
|
||||
$fp puts -nonewline $data
|
||||
close $fp
|
||||
puts "Configuration file $cf saved."
|
||||
puts "Configuration file $cf saved successfully."
|
||||
}
|
||||
|
||||
|
|
|
@ -9,215 +9,27 @@ function quot(str)
|
|||
return '{' + str + '}';
|
||||
}
|
||||
|
||||
function updateupdown()
|
||||
function fixupdown()
|
||||
{
|
||||
$('#ruleset a.uprule').enable().filter(':first').disable();
|
||||
$('#ruleset a.downrule').enable().filter(':last').disable();
|
||||
}
|
||||
|
||||
function update_buttons(changed)
|
||||
function changed(c)
|
||||
{
|
||||
if (changed)
|
||||
if (typeof(changed.last) == 'number' && c == changed.last)
|
||||
return;
|
||||
if (c)
|
||||
{
|
||||
$('#b_save,#b_revert').enable();
|
||||
$('#pendingnote').show();
|
||||
$('#b_save')
|
||||
.jConfirmAction({
|
||||
question: 'Save changes?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
$.post('save.jim', {
|
||||
dir: $('span.dir').text(),
|
||||
data: conffile()
|
||||
}, function(data) {
|
||||
$('#output').html(data)
|
||||
.delay(5000).fadeOut('slow');
|
||||
update_buttons(0);
|
||||
});
|
||||
});
|
||||
$('#b_revert')
|
||||
.jConfirmAction({
|
||||
question: 'Discard changes?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
loadrules($('span.dir').text());
|
||||
update_buttons(0);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#b_save,#b_revert').disable();
|
||||
$('#pendingnote').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function update_rulehooks(obj)
|
||||
{
|
||||
if (!obj)
|
||||
obj = $('#ruleset');
|
||||
|
||||
obj.find('a.delclause').jConfirmAction({
|
||||
question: 'Delete criterion?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
var rule = $(el).closest('div.rule');
|
||||
$(el).closest('tr.clause').fadeOut('slow', function() {
|
||||
$(this).remove();
|
||||
rawrefresh(rule);
|
||||
update_buttons(1);
|
||||
});
|
||||
});
|
||||
|
||||
obj.find('a.editclause').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
edit_clause($(this).closest('tr.clause'));
|
||||
});
|
||||
|
||||
obj.find('button.addcriterion')
|
||||
.button({icons: { primary: "ui-icon-plus"}})
|
||||
.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var rule = $(this).closest('div.rule');
|
||||
edit_select(rule, 'Select new criterion',
|
||||
select_criteria, '', function(rule, val) {
|
||||
var id = rule.attr('id');
|
||||
rule.find('table.criteria tbody')
|
||||
.append(criterion({
|
||||
cmd: val,
|
||||
arg: schema.criterion[val].def
|
||||
}));
|
||||
update_rulehooks(rule);
|
||||
update_buttons(1);
|
||||
});
|
||||
});
|
||||
|
||||
obj.find('a.delrule').jConfirmAction({
|
||||
question: 'Delete entire rule?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
$(el).closest('div.rule').slideUp('slow', function() {
|
||||
$(this).remove();
|
||||
update_buttons(1);
|
||||
updateupdown();
|
||||
if ($('div.rule').length < 1)
|
||||
$('#ruleset').attr('empty', true)
|
||||
.html('<i>No rules defined for this ' +
|
||||
'folder.</i>');
|
||||
});
|
||||
});
|
||||
|
||||
obj.find('a.editcomment').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
edit_text($(this), 'Edit rule name',
|
||||
$(this).siblings('span.comment').text(),
|
||||
function(obj, text) {
|
||||
$(obj).siblings('span.comment').text(text);
|
||||
update_buttons(1);
|
||||
});
|
||||
});
|
||||
|
||||
obj.find('a.uprule').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
if ($(this).hasClass('ui-state-disabled'))
|
||||
return false;
|
||||
var rule = $(this).closest('div.rule');
|
||||
var target = $(rule).prev('div.rule');
|
||||
if (!target || !target.length)
|
||||
return false;
|
||||
$(rule).addClass('hl').slideUp('slow', function() {
|
||||
$(this).insertBefore($(target))
|
||||
.slideDown('slow', function() {
|
||||
$(this).removeClass('hl');
|
||||
updateupdown();
|
||||
update_buttons(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
obj.find('a.downrule').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
if ($(this).hasClass('ui-state-disabled'))
|
||||
return false;
|
||||
var rule = $(this).closest('div.rule');
|
||||
var target = $(rule).next('div.rule');
|
||||
if (!target || !target.length)
|
||||
return false;
|
||||
$(rule).addClass('hl').slideUp('slow', function() {
|
||||
$(this).insertAfter($(target))
|
||||
.slideDown('slow', function() {
|
||||
$(this).removeClass('hl');
|
||||
updateupdown();
|
||||
update_buttons(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
obj.find('a.editaction').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var rule = $(this).closest('div.rule');
|
||||
var type = rule.attr('type');
|
||||
|
||||
if (type == 'folder')
|
||||
options = select_folder_actions;
|
||||
else
|
||||
options = select_file_actions;
|
||||
|
||||
$('#edit_action_act').empty();
|
||||
$.each(options, function(k, v) {
|
||||
$('#edit_action_act').append(
|
||||
$('<option></option>').attr('value', k).text(v)
|
||||
);
|
||||
});
|
||||
|
||||
var cmd = rule.find('tr.action th').attr('cmd');
|
||||
var arg = rule.find('tr.action td.val').html();
|
||||
|
||||
if (schema.action[cmd].argtype == 'none')
|
||||
arg = '';
|
||||
|
||||
if (schema.action[cmd].argtype == 'folder' &&
|
||||
arg == 'Media Root')
|
||||
arg = '';
|
||||
|
||||
$('#edit_action_act').val(cmd);
|
||||
$('#edit_action_arg').val(arg);
|
||||
|
||||
$('#edit_action').dialog({
|
||||
height: 'auto', width: 'auto',
|
||||
draggable: false, resizable: false,
|
||||
autoOpen: true,
|
||||
position: {
|
||||
my: 'bottom left',
|
||||
at: 'top right',
|
||||
of: rule
|
||||
},
|
||||
buttons: {
|
||||
"Save": function() {
|
||||
cmd = $('#edit_action_act').val();
|
||||
arg = $('#edit_action_arg').val();
|
||||
|
||||
rule.find('tr.action').replaceWith(
|
||||
action({cmd: cmd, arg: arg}));
|
||||
$(this).dialog('close');
|
||||
rawrefresh(rule);
|
||||
update_rulehooks(rule);
|
||||
update_buttons(1);
|
||||
},
|
||||
"Close": function() {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
changed.last = c;
|
||||
}
|
||||
|
||||
var setters = {
|
||||
|
@ -386,6 +198,9 @@ function addrule(id, data)
|
|||
|
||||
$('#ruleset').append(rule);
|
||||
|
||||
rule.find('button.addcriterion')
|
||||
.button({icons: { primary: "ui-icon-plus"}});
|
||||
|
||||
return rule;
|
||||
}
|
||||
|
||||
|
@ -502,7 +317,7 @@ function edit_clause(obj)
|
|||
edit_text(target, title, val, function(obj, text) {
|
||||
$(obj).text(text);
|
||||
rawrefresh($(obj).closest('div.rule'));
|
||||
update_buttons(1);
|
||||
changed(1);
|
||||
});
|
||||
break;
|
||||
case 'int':
|
||||
|
@ -515,7 +330,7 @@ function edit_clause(obj)
|
|||
edit_int(target, title, b[0], b[1], function(obj, op, val) {
|
||||
$(obj).text(op + ' ' + val);
|
||||
rawrefresh($(obj).closest('div.rule'));
|
||||
update_buttons(1);
|
||||
changed(1);
|
||||
});
|
||||
break;
|
||||
case 'select':
|
||||
|
@ -523,7 +338,7 @@ function edit_clause(obj)
|
|||
getters.select(cmd, val), function(obj, val) {
|
||||
$(obj).text(setters.select(cmd, val));
|
||||
rawrefresh($(obj).closest('div.rule'));
|
||||
update_buttons(1);
|
||||
changed(1);
|
||||
});
|
||||
break;
|
||||
|
||||
|
@ -547,17 +362,14 @@ function loadrules(dir)
|
|||
$.each(data, function(key, val) {
|
||||
addrule(key, val);
|
||||
});
|
||||
updateupdown();
|
||||
fixupdown();
|
||||
if (!showraw)
|
||||
$('#ruleset div.raw').hide();
|
||||
|
||||
update_rulehooks();
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
|
||||
loadrules($('span.dir').text());
|
||||
$('#b_add').button({icons: {primary: "ui-icon-plus"}})
|
||||
.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
@ -583,8 +395,7 @@ $('#b_add').button({icons: {primary: "ui-icon-plus"}})
|
|||
arg: ''
|
||||
}
|
||||
});
|
||||
update_rulehooks(rule);
|
||||
update_buttons(1);
|
||||
changed(1);
|
||||
$(this).dialog('close');
|
||||
},
|
||||
"Close": function() {
|
||||
|
@ -595,8 +406,41 @@ $('#b_add').button({icons: {primary: "ui-icon-plus"}})
|
|||
$('#newrule_type_file').prop('checked', true);
|
||||
$('#newrule_comment').focus().val('').val('Unnamed rule');
|
||||
});
|
||||
$('#b_save').button({icons: {primary: "ui-icon-disk"}});
|
||||
$('#b_revert').button({icons: {primary: "ui-icon-arrowrefresh-1-w"}});
|
||||
|
||||
$('#b_save').button({icons: {primary: "ui-icon-disk"}})
|
||||
.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).dojConfirmAction({
|
||||
question: 'Save changes?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
$.post('save.jim', {
|
||||
dir: $('span.dir').text(),
|
||||
data: conffile()
|
||||
}, function(data) {
|
||||
$('#output').html(data)
|
||||
.delay(5000).fadeOut('slow');
|
||||
changed(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#b_revert').button({icons: {primary: "ui-icon-arrowrefresh-1-w"}})
|
||||
.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).dojConfirmAction({
|
||||
question: 'Discard changes?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
loadrules($('span.dir').text());
|
||||
changed(0);
|
||||
});
|
||||
});
|
||||
|
||||
$('#b_show').button({icons: {primary: "ui-icon-clipboard"}})
|
||||
.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
@ -614,11 +458,169 @@ $('#b_show').button({icons: {primary: "ui-icon-clipboard"}})
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#b_raw').button({icons: {primary: "ui-icon-gear"}})
|
||||
.on('click', function(e) {
|
||||
$('div.raw').toggle('slow');
|
||||
});
|
||||
update_buttons(0);
|
||||
|
||||
$('#ruleset div.raw').toggle('slow');
|
||||
});
|
||||
|
||||
changed(0);
|
||||
|
||||
$('#ruleset')
|
||||
.on('click', 'a.editclause', function(e) {
|
||||
e.preventDefault();
|
||||
edit_clause($(this).closest('tr.clause'));
|
||||
})
|
||||
.on('click', 'button.addcriterion', function(e) {
|
||||
e.preventDefault();
|
||||
var rule = $(this).closest('div.rule');
|
||||
edit_select(rule, 'Select new criterion',
|
||||
select_criteria, '', function(rule, val) {
|
||||
var id = rule.attr('id');
|
||||
rule.find('table.criteria tbody')
|
||||
.append(criterion({
|
||||
cmd: val,
|
||||
arg: schema.criterion[val].def
|
||||
}));
|
||||
changed(1);
|
||||
});
|
||||
})
|
||||
.on('click', 'a.editcomment', function(e) {
|
||||
e.preventDefault();
|
||||
edit_text($(this), 'Edit rule name',
|
||||
$(this).siblings('span.comment').text(),
|
||||
function(obj, text) {
|
||||
$(obj).siblings('span.comment').text(text);
|
||||
changed(1);
|
||||
});
|
||||
})
|
||||
.on('click', 'a.uprule', function(e) {
|
||||
e.preventDefault();
|
||||
if ($(this).hasClass('ui-state-disabled'))
|
||||
return false;
|
||||
var rule = $(this).closest('div.rule');
|
||||
var target = $(rule).prev('div.rule');
|
||||
if (!target || !target.length)
|
||||
return false;
|
||||
$(rule).addClass('hl').slideUp('slow', function() {
|
||||
$(this).insertBefore($(target))
|
||||
.slideDown('slow', function() {
|
||||
$(this).removeClass('hl');
|
||||
fixupdown();
|
||||
changed(1);
|
||||
});
|
||||
});
|
||||
})
|
||||
.on('click', 'a.downrule', function(e) {
|
||||
e.preventDefault();
|
||||
if ($(this).hasClass('ui-state-disabled'))
|
||||
return false;
|
||||
var rule = $(this).closest('div.rule');
|
||||
var target = $(rule).next('div.rule');
|
||||
if (!target || !target.length)
|
||||
return false;
|
||||
$(rule).addClass('hl').slideUp('slow', function() {
|
||||
$(this).insertAfter($(target))
|
||||
.slideDown('slow', function() {
|
||||
$(this).removeClass('hl');
|
||||
fixupdown();
|
||||
changed(1);
|
||||
});
|
||||
});
|
||||
})
|
||||
.on('click', 'a.editaction', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var rule = $(this).closest('div.rule');
|
||||
var type = rule.attr('type');
|
||||
|
||||
if (type == 'folder')
|
||||
options = select_folder_actions;
|
||||
else
|
||||
options = select_file_actions;
|
||||
|
||||
$('#edit_action_act').empty();
|
||||
$.each(options, function(k, v) {
|
||||
$('#edit_action_act').append(
|
||||
$('<option></option>').attr('value', k).text(v)
|
||||
);
|
||||
});
|
||||
|
||||
var cmd = rule.find('tr.action th').attr('cmd');
|
||||
var arg = rule.find('tr.action td.val').html();
|
||||
|
||||
if (schema.action[cmd].argtype == 'none')
|
||||
arg = '';
|
||||
|
||||
if (schema.action[cmd].argtype == 'folder' &&
|
||||
arg == 'Media Root')
|
||||
arg = '';
|
||||
|
||||
$('#edit_action_act').val(cmd);
|
||||
$('#edit_action_arg').val(arg);
|
||||
|
||||
$('#edit_action').dialog({
|
||||
height: 'auto', width: 'auto',
|
||||
draggable: false, resizable: false,
|
||||
autoOpen: true,
|
||||
position: {
|
||||
my: 'bottom left',
|
||||
at: 'top right',
|
||||
of: rule
|
||||
},
|
||||
buttons: {
|
||||
"Save": function() {
|
||||
cmd = $('#edit_action_act').val();
|
||||
arg = $('#edit_action_arg').val();
|
||||
|
||||
rule.find('tr.action').replaceWith(
|
||||
action({cmd: cmd, arg: arg}));
|
||||
$(this).dialog('close');
|
||||
rawrefresh(rule);
|
||||
changed(1);
|
||||
},
|
||||
"Close": function() {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.on('click', 'a.delclause', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).dojConfirmAction({
|
||||
question: 'Delete criterion?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
var rule = $(el).closest('div.rule');
|
||||
$(el).closest('tr.clause').fadeOut('slow', function() {
|
||||
$(this).remove();
|
||||
rawrefresh(rule);
|
||||
changed(1);
|
||||
});
|
||||
});
|
||||
})
|
||||
.on('click', 'a.delrule', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).dojConfirmAction({
|
||||
question: 'Delete entire rule?',
|
||||
yesAnswer: 'Yes',
|
||||
cancelAnswer: 'No'
|
||||
}, function(el) {
|
||||
$('.jcaquestion').fadeOut(300);
|
||||
$(el).closest('div.rule').slideUp('slow', function() {
|
||||
$(this).remove();
|
||||
changed(1);
|
||||
fixupdown();
|
||||
if ($('div.rule').length < 1)
|
||||
$('#ruleset').attr('empty', true)
|
||||
.html('<i>No rules defined for this ' +
|
||||
'folder.</i>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
loadrules($('span.dir').text());
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue