diff --git a/source/lib/RippingCluster/Main.class.php b/source/lib/RippingCluster/Main.class.php index ea2bb98..e4d1cc5 100644 --- a/source/lib/RippingCluster/Main.class.php +++ b/source/lib/RippingCluster/Main.class.php @@ -25,6 +25,7 @@ class RippingCluster_Main extends SihnonFramework_Main { $this->smarty->compile_dir = static::makeAbsolutePath($smarty_tmp . '/tmp/templates'); $this->smarty->cache_dir = static::makeAbsolutePath($smarty_tmp . '/tmp/cache'); $this->smarty->config_dir = static::makeAbsolutePath($smarty_tmp . '/config'); + $this->smarty->plugins_dir[]= static::makeAbsolutePath('./source/smarty/plugins'); $this->smarty->registerPlugin('modifier', 'formatDuration', array('RippingCluster_Main', 'formatDuration')); $this->smarty->registerPlugin('modifier', 'formatFilesize', array('RippingCluster_Main', 'formatFilesize')); diff --git a/webui/scripts/main.js b/webui/scripts/main.js index 660f16c..718e849 100644 --- a/webui/scripts/main.js +++ b/webui/scripts/main.js @@ -23,7 +23,8 @@ var rc = { }, post: function(url, data) { - $.ajax(url, { + $.ajax({ + url: url, type: "POST", dataType: "json", data: data, @@ -54,6 +55,14 @@ var rc = { if (d.dialog.buttons) { switch (d.dialog.buttons.type) { + case 'ok': + $("#dialogfooterok").click( + function() { + rc.trigger(d.dialog.buttons.actions.ok, d.dialog.buttons.params); + } + ); + $("#dialogfooterok").show(); + break; case 'yesno': $("#dialogfooteryes").click( function() { @@ -134,6 +143,77 @@ var rc = { } else { console.log("Action not supported: " +action); } + }, + + settings: { + + init: function() { + $("#settings_save").click( + function() { + rc.settings.save(); + } + ); + }, + + add_stringlist_field: function(id) { + var container = $('#container_'+id); + var next = $('#settings_'+id+'_next'); + var next_value = next.val(); + + var line = $('
+ * {foreach item=$debugItem from=$debugData}
+ * // Switch on $debugItem.type
+ * {switch $debugItem.type}
+ * {case 1}
+ * {case "invalid_field"}
+ * // Case checks for string and numbers.
+ * {/case}
+ * {case $postError}
+ * {case $getError|cat:"_ajax"|lower}
+ * // Case checks can also use variables and modifiers.
+ * {break}
+ * {default}
+ * // Default case is supported.
+ * {/switch}
+ * {/foreach}
+ *
+ *
+ * Note in the above example that the break statements work exactly as expected. Also the switch and default
+ * tags can take the break attribute. If set they will break automatically before the next case is printed.
+ *
+ * Both blocks produce the same switch logic:
+ *
+ * {case 1 break}
+ * Code 1
+ * {case 2}
+ * Code 2
+ * {default break}
+ * Code 3
+ *
+ *
+ *
+ * {case 1}
+ * Code 1
+ * {break}
+ * {case 2}
+ * Code 2
+ * {default}
+ * Code 3
+ * {break}
+ *
+ *
+ * Finally, there is an alternate long hand style for the switch statments that you may need to use in some cases.
+ *
+ *
+ * {switch var=$type}
+ * {case value="box" break}
+ * {case value="line"}
+ * {break}
+ * {default}
+ * {/switch}
+ *
+ */
+
+//Register the post and pre filters as they are not auto-registered.
+$this->registerFilter('post', 'smarty_postfilter_switch');
+
+class Smarty_Compiler_Switch extends Smarty_Internal_CompileBase {
+ public $required_attributes = array('var');
+ public $optional_attributes = array();
+ public $shorttag_order = array('var');
+
+/**
+ * Start a new switch statement.
+ * A variable must be passed to switch on.
+ * Also, the switch can only directly contain {case} and {default} tags.
+ *
+ * @param string $tag_arg
+ * @param Smarty_Compiler $smarty
+ * @return string
+ */
+ public function compile($args, $compiler){
+ $this->compiler = $compiler;
+ $attr = $this->_get_attributes($args);
+ $_output = '';
+
+ $this->_open_tag('switch',array($compiler->tag_nocache));
+
+ if (is_array($attr['var'])) {
+ $_output .= "tpl_vars[".$attr['var']['var']."])) \$_smarty_tpl->tpl_vars[".$attr['var']['var']."] = new Smarty_Variable;";
+ $_output .= "switch (\$_smarty_tpl->tpl_vars[".$attr['var']['var']."]->value = ".$attr['var']['value']."){?>";
+ } else {
+ $_output .= '';
+ }
+ return $_output;
+ }
+}
+
+class Smarty_Compiler_Case extends Smarty_Internal_CompileBase {
+ public $required_attributes = array('value');
+ public $optional_attributes = array('break');
+ public $shorttag_order = array('value', 'break');
+
+/**
+ * Print out a case line for this switch.
+ * A condition must be passed to match on.
+ * This can only go in {switch} tags.
+ * If break is passed, a {break} will be rendered before the next case.
+ *
+ * @param string $tag_arg
+ * @param Smarty_Compiler $smarty
+ * @return string
+ */
+ public function compile($args, $compiler){
+ $this->compiler = $compiler;
+ $attr = $this->_get_attributes($args);
+ $_output = '';
+
+ list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1];
+
+ if($last_tag == 'case')
+ {
+ list($break, $compiler->tag_nocache) = $this->_close_tag(array('case'));
+ if($last_attr[0])
+ $_output .= '';
+ }
+ $this->_open_tag('case', array(isset($attr['break']) ? $attr['break'] : false, $compiler->tag_nocache));
+
+ if (is_array($attr['value'])) {
+ $_output .= "tpl_vars[".$attr['value']['var']."])) \$_smarty_tpl->tpl_vars[".$attr['value']['var']."] = new Smarty_Variable;";
+ $_output .= "case \$_smarty_tpl->tpl_vars[".$attr['value']['var']."]->value = ".$attr['value']['value'].":?>";
+ } else {
+ $_output .= '';
+ }
+ return $_output;
+ }
+}
+
+class Smarty_Compiler_Default extends Smarty_Internal_CompileBase {
+ public $required_attributes = array();
+ public $optional_attributes = array('break');
+ public $shorttag_order = array('break');
+
+/**
+ * Print out a default line for this switch.
+ * This can only go in {switch} tags.
+ * If break is passed, a {break} will be rendered before the next case.
+ *
+ * @param string $tag_arg
+ * @param Smarty_Compiler $smarty
+ * @return string
+ */
+ public function compile($args, $compiler){
+ $this->compiler = $compiler;
+ $attr = $this->_get_attributes($args);
+ $_output = '';
+
+ list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1];
+ if($last_tag == 'case')
+ {
+ list($break, $compiler->tag_nocache) = $this->_close_tag(array('case'));
+ if($last_attr[0])
+ $_output .= '';
+ }
+ $this->_open_tag('case', array(isset($attr['break']) ? $attr['break'] : false, $compiler->tag_nocache));
+
+ $_output .= '';
+
+ return $_output;
+ }
+}
+
+
+class Smarty_Compiler_Break extends Smarty_Internal_CompileBase {
+ public $required_attributes = array();
+ public $optional_attributes = array();
+ public $shorttag_order = array();
+
+/**
+ * Print out a break command for the switch.
+ * This can only go inside of {case} tags.
+ *
+ * @param string $tag_arg
+ * @param Smarty_Compiler $smarty
+ * @return string
+ */
+
+ public function compile($args, $compiler){
+ $this->compiler = $compiler;
+ $attr = $this->_get_attributes($args);
+
+ list($break, $compiler->tag_nocache) = $this->_close_tag(array('case'));
+
+ return '';
+ }
+}
+
+class Smarty_Compiler_Caseclose extends Smarty_Internal_CompileBase {
+ public $required_attributes = array();
+ public $optional_attributes = array();
+ public $shorttag_order = array();
+
+/**
+ * Print out a break command for the switch.
+ * This can only go inside of {case} tags.
+ *
+ * @param string $tag_arg
+ * @param Smarty_Compiler $smarty
+ * @return string
+ */
+
+ public function compile($args, $compiler){
+ $this->compiler = $compiler;
+ $attr = $this->_get_attributes($args);
+
+ list($break, $compiler->tag_nocache) = $this->_close_tag(array('case'));
+
+ return '';
+ }
+}
+
+class Smarty_Compiler_Switchclose extends Smarty_Internal_CompileBase {
+ public $required_attributes = array();
+ public $optional_attributes = array();
+ public $shorttag_order = array();
+
+/**
+ * End a switch statement.
+ *
+ * @param string $tag_arg
+ * @param Smarty_Compiler $smarty
+ * @return string
+ */
+
+ public function compile($args, $compiler){
+ $this->compiler = $compiler;
+ $attr = $this->_get_attributes($args);
+
+ list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1];
+ if(($last_tag == 'case' || $last_tag == 'default'))
+ list($break, $compiler->tag_nocache) = $this->_close_tag(array('case'));
+ list($compiler->tag_nocache) = $this->_close_tag(array('switch'));
+
+ return '';
+ }
+}
+
+/**
+ * Filter the template after it is generated to fix switch bugs.
+ * Remove any spaces after the 'switch () {' code and before the first case. Any tabs or spaces
+ * for layout would cause php errors witch this reged will fix.
+ *
+ * @param string $compiled
+ * @param Smarty_Compiler $smarty
+ * @return string
+ */
+function smarty_postfilter_switch($compiled, &$smarty) {
+ // Remove the extra spaces after the start of the switch tag and before the first case statement.
+ return preg_replace('/({ ?\?>)\s+(<\?php case)/', "$1\n$2", $compiled);
+}
+?>
\ No newline at end of file
diff --git a/webui/source/templates/admin/settings.tpl b/webui/source/templates/admin/settings.tpl
index f99b905..ea646de 100644
--- a/webui/source/templates/admin/settings.tpl
+++ b/webui/source/templates/admin/settings.tpl
@@ -1 +1,56 @@
-Not yet implemented.
\ No newline at end of file
+| Name | +Value | + + + {foreach from=$settings item=name} + {assign var='value' value=$config->get($name)} + {assign var='type' value=$config->type($name)} + {assign var='id' value=str_replace('.', '-',$name)} +
|---|---|
| {$name} | +
+ {switch $type}
+ {case Sihnon_Config::TYPE_BOOL}
+
+ {/case}
+ {case Sihnon_Config::TYPE_INT}
+
+ {/case}
+ {case Sihnon_Config::TYPE_STRING}
+
+ {/case}
+ {case Sihnon_Config::TYPE_STRING_LIST}
+
+ {foreach from=$value item=line name=settings}
+
+
+
+
+
+ {/foreach}
+
+
+
+
+ {/case}
+ {/switch}
+ |
+
| + + | +|
+ Settings have been saved. +
+ +{if $messages} ++ Some messages were generated during this operation: + {include file="fragments/messages.tpl"} +
+{/if} diff --git a/webui/source/templates/index.tpl b/webui/source/templates/index.tpl index 559f0f9..412f558 100644 --- a/webui/source/templates/index.tpl +++ b/webui/source/templates/index.tpl @@ -64,6 +64,11 @@