From cfbd471f7a638466f738fe1d46cc18fa8df0dc62 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Mon, 15 Jun 2015 17:23:59 +0000 Subject: [PATCH] search/replace + dialogue position problems --- CONTROL/control | 2 +- webif/plugin/sweeper/auto.hook | 46 ++++++++++++++++++++++++++++++++++ webif/plugin/sweeper/script.js | 28 +++++++++++++-------- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/CONTROL/control b/CONTROL/control index 1ca0cd3..ebe212e 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: sweeper Priority: optional Section: misc -Version: 2.0.7-7 +Version: 2.0.8 Architecture: mipsel Maintainer: af123@hummypkg.org.uk Depends: webif(>=1.2.2-6) diff --git a/webif/plugin/sweeper/auto.hook b/webif/plugin/sweeper/auto.hook index aab765f..054becd 100644 --- a/webif/plugin/sweeper/auto.hook +++ b/webif/plugin/sweeper/auto.hook @@ -33,6 +33,14 @@ proc ::sweeper::strcontains {ref val} { >= 0] } +set ::sweeper::expand_fns { + replace {2} +} + +proc ::sweeper::expand_replace {ts &ret search replace} { + set ret [string map [list $search $replace] $ret] +} + # Expand a string containing tokens proc ::sweeper::expand {ts str {orig ""}} { if {[string first "%" $str] == -1} { @@ -97,6 +105,44 @@ proc ::sweeper::expand {ts str {orig ""}} { set ret [string map $map $str] log " Expanded \[$str] -> \[$ret]" 2 + + foreach {fn params} $::sweeper::expand_fns { + log " Looking for %$fn" 2 + + lassign $params numargs + + set li -1 + while {[set i [string first "%$fn" $ret]] >= 0} { + if {$i <= $li} break + set li $i + + # Fetch the delimiter + set chpos $($i + [string length $fn] + 1) + set ch [string index $ret $chpos] + + log " - found at $i (delim\[$ch])" 2 + + # Extract the arguments + set pos $chpos + set fnargs {} + while {[llength $fnargs] < $numargs} { + incr pos + set e [string first $ch $ret $pos] + if {$e == -1} { + log "Error. %$fn - $i/$numargs parameters found." + break + } + lappend fnargs [string range $ret \ + $pos $($e - 1)] + set pos $e + } + + set ret [string replace $ret $i $pos] + log " - Calling expand_$fn\($fnargs)" 2 + ::sweeper::expand_$fn $ts ret {*}$fnargs + } + } + return $ret } diff --git a/webif/plugin/sweeper/script.js b/webif/plugin/sweeper/script.js index 14cf212..a6ad912 100644 --- a/webif/plugin/sweeper/script.js +++ b/webif/plugin/sweeper/script.js @@ -361,12 +361,13 @@ function edit_text(obj, title, text, callback, typ) $('#edit_text').dialog({ title: title, height: 'auto', width: 'auto', - draggable: false, resizable: false, + draggable: true, resizable: false, autoOpen: true, position: { my: 'bottom left', at: 'top right', - of: obj + of: obj, + collision: 'fit' }, buttons: { "Save": function() { @@ -398,12 +399,13 @@ function edit_int(obj, title, op, val, callback) $('#edit_int').dialog({ title: title, height: 'auto', width: 'auto', - draggable: false, resizable: false, + draggable: true, resizable: false, autoOpen: true, position: { my: 'bottom left', at: 'top right', - of: obj + of: obj, + collision: 'fit' }, buttons: { "Save": function() { @@ -437,12 +439,13 @@ function edit_select(obj, title, options, val, callback) $('#edit_select').dialog({ title: title, height: 'auto', width: 'auto', - draggable: false, resizable: false, + draggable: true, resizable: false, autoOpen: true, position: { my: 'bottom left', at: 'top right', - of: obj + of: obj, + collision: 'fit' }, buttons: { "Save": function() { @@ -536,12 +539,13 @@ $('#b_add').button({icons: {primary: "ui-icon-plus"}}) e.preventDefault(); $('#newrule').dialog({ height: 'auto', width: 'auto', - draggable: false, resizable: false, + draggable: true, resizable: false, autoOpen: true, position: { my: 'bottom left', at: 'top right', - of: $(this) + of: $(this), + collision: 'fit' }, buttons: { "Create Rule": function() { @@ -738,12 +742,13 @@ function addcriterion(rule, target) $('#newcondition').dialog({ height: 'auto', width: 'auto', - draggable: false, resizable: false, + draggable: true, resizable: false, autoOpen: true, position: { my: 'bottom left', at: 'top right', - of: target + of: target, + collision: 'fit' }, buttons: { "Add Condition": function() { @@ -896,7 +901,8 @@ $('#ruleset') position: { my: 'bottom left', at: 'top right', - of: rule + of: rule, + collision: 'fit' }, buttons: { "Save": function() {