diff --git a/source/lib/RippingCluster/Main.class.php b/source/lib/RippingCluster/Main.class.php index ea2bb98..e7318c3 100644 --- a/source/lib/RippingCluster/Main.class.php +++ b/source/lib/RippingCluster/Main.class.php @@ -25,11 +25,12 @@ 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')); - $this->smarty->assign('version', '0.2.1'); + $this->smarty->assign('version', '0.3'); $this->smarty->assign('messages', array()); $this->smarty->assign('base_uri', $this->base_uri); diff --git a/webui/scripts/main.js b/webui/scripts/main.js index 660f16c..e45dd74 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, @@ -35,6 +36,7 @@ var rc = { success: function(d, s, x) { rc.page.update(d); rc.dialog.prepare(d); + rc.trigger_all(d); }, failure: function(x, s, e) { @@ -54,6 +56,23 @@ 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 'okcancel': + $("#dialogfooterokcancel_ok").click(function() { + rc.trigger(d.dialog.buttons.actions.ok, d.dialog.buttons.params); + }); + $("#dialogfooterokcancel_cancel").click(function() { + rc.trigger(d.dialog.buttons.actions.cancel, d.dialog.buttons.params); + }); + $("#dialogfooterokcancel").show(); + break; case 'yesno': $("#dialogfooteryes").click( function() { @@ -70,15 +89,56 @@ var rc = { } } + if (d.dialog.title) { + $('#dialogheadertitle').html(d.dialog.title); + } + + if (d.dialog.content) { + $('#dialogcontent').html(d.dialog.content); + } + $("#dialog").show(); } }, close: function() { + // Hide the dialog $("#dialog").hide(); - $(".dialogfooterbuttonset").hide(); + + // Remove the dialog content $("#dialogcontent").html(); - } + + // Hide all buttons + $(".dialogfooterbuttonset").hide(); + // Strip all event handlers + $(".dialogfooterbuttonset input[type='button']").unbind('click'); + }, + + error: function(title, content, messages) { + var formatted_content = $('
').text('content')); + if (messages) { + var formatted_messages = $('
').text('These messages were reported:').append(formatted_messages)); + } + + rc.dialog.prepare({ + dialog: { + show: true, + title: title, + content: formatted_content, + buttons: { + type: 'ok', + actions: { + ok: 'close-dialog' + } + } + } + }); + } }, @@ -115,6 +175,31 @@ var rc = { 'delete-source-confirm': function(params) { rc.sources.remove_confirmed(params['plugin'], params['id']); + }, + + 'add-setting': function(params) { + rc.ajax.post(base_url + 'ajax/admin/add-setting/name/' + $('#'+params.name).val() + '/type/' + $('#'+params.type).val() + '/'); + }, + + 'add_setting_row': function(params) { + $("#settings tbody").append(params.content); + }, + + 'rename_setting': function(params) { + rc.ajax.post(base_url + 'ajax/admin/rename-setting/name/' + params.name + '/new-name/' + $('#'+params.new_name_field).val() + '/confirm/'); + }, + + 'rename_setting_confirm': function(params) { + $('#setting_'+params.old_id+'_row').replaceWith($(params.content)); + }, + + 'remove_setting': function(params) { + rc.ajax.post(base_url + 'ajax/admin/remove-setting/name/' + params.name + '/'); + rc.trigger('remove_setting_row', params); + }, + + 'remove_setting_row': function(params) { + $('#setting_' + params.id + '_row').remove(); } }, @@ -134,6 +219,119 @@ var rc = { } else { console.log("Action not supported: " +action); } + }, + + trigger_all: function(params) { + if (params.actions) { + for (var action in params.actions) { + rc.trigger(action, params.actions[action]); + } + } + }, + + settings: { + + init: function() { + $("#settings_save").click(function() { + rc.settings.save(); + }); + + $("#settings_new").click(function() { + rc.settings.new_setting(); + }); + }, + + new_setting: function() { + rc.ajax.get(base_url + "ajax/admin/new-setting/"); + }, + + rename_setting: function(id, name) { + rc.ajax.get(base_url + "ajax/admin/rename-setting/name/" + name + "/"); + }, + + remove_setting: function(id, name) { + rc.dialog.prepare({ + dialog: { + show: true, + title: 'Remove setting', + content: "Do you really want to remove setting '" + name + "'", + buttons: { + type: 'okcancel', + actions: { + ok: [ + 'remove_setting', + 'close-dialog' + ], + cancel: 'close-dialog' + }, + params: { + id: id, + name: name + } + } + } + }); + }, + + 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..3640b03 100644
--- a/webui/source/templates/admin/settings.tpl
+++ b/webui/source/templates/admin/settings.tpl
@@ -1 +1,29 @@
-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)} + + {include file="fragments/admin-setting-row.tpl"} + {/foreach} + + +
|---|---|
| + + + | +
+ {$name}
+
+
+
| Name | +Type | + + +
|---|---|
| + + | ++ + | +
+ Enter a new name for setting '{$name|escape}' below. +
+ ++ 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..5c8d460 100644 --- a/webui/source/templates/index.tpl +++ b/webui/source/templates/index.tpl @@ -64,6 +64,17 @@