diff --git a/source/lib/RippingCluster/Main.class.php b/source/lib/RippingCluster/Main.class.php index 88a25a0..b2b4389 100644 --- a/source/lib/RippingCluster/Main.class.php +++ b/source/lib/RippingCluster/Main.class.php @@ -17,6 +17,7 @@ class RippingCluster_Main extends SihnonFramework_Main { $this->request = new RippingCluster_RequestParser($request_string); switch (HBC_File) { + case 'ajax': case 'index': { $smarty_tmp = '/tmp/ripping-cluster'; $this->smarty = new Smarty(); @@ -28,10 +29,12 @@ class RippingCluster_Main extends SihnonFramework_Main { $this->smarty->registerPlugin('modifier', 'formatDuration', array('RippingCluster_Main', 'formatDuration')); $this->smarty->registerPlugin('modifier', 'formatFilesize', array('RippingCluster_Main', 'formatFilesize')); - $this->smarty->assign('version', '0.1'); + $this->smarty->assign('version', '0.2'); $this->smarty->assign('messages', array()); $this->smarty->assign('base_uri', $this->base_uri); + $this->smarty->assign('base_url', static::absoluteUrl('')); + } break; } diff --git a/webui/_inc.php b/webui/_inc.php index d80eca9..0994fd2 100644 --- a/webui/_inc.php +++ b/webui/_inc.php @@ -1,6 +1,13 @@ smarty(); + + $page = new RippingCluster_Page($smarty, $main->request()); + if ($page->evaluate()) { + //header('Content-Type: text/json'); + $smarty->display('ajax.tpl'); + } + +} catch (RippingCluster_Exception $e) { + die("Uncaught Exception: " . $e->getMessage()); +} + +?> diff --git a/webui/scripts/main.js b/webui/scripts/main.js new file mode 100644 index 0000000..660f16c --- /dev/null +++ b/webui/scripts/main.js @@ -0,0 +1,141 @@ +var rc = { + + init: function() { + rc.ajax.init(); + rc.dialog.init(); + rc.page.init(); + }, + + ajax: { + + init: function() { + + }, + + get: function(url) { + $.ajax({ + url: url, + type: "GET", + dataType: "json", + success: rc.ajax.success, + error: rc.ajax.failure + }); + }, + + post: function(url, data) { + $.ajax(url, { + type: "POST", + dataType: "json", + data: data, + success: rc.ajax.success, + error: rc.ajax.failure + }); + }, + + success: function(d, s, x) { + rc.page.update(d); + rc.dialog.prepare(d); + }, + + failure: function(x, s, e) { + console.log("Ajax Failure: " + s, e); + console.log(x.responseText); + } + }, + + dialog: { + + init: function() { + $("#dialogheaderclose").click(rc.dialog.close); + }, + + prepare: function(d) { + if (d.dialog && d.dialog.show) { + + if (d.dialog.buttons) { + switch (d.dialog.buttons.type) { + case 'yesno': + $("#dialogfooteryes").click( + function() { + rc.trigger(d.dialog.buttons.actions.yes, d.dialog.buttons.params); + } + ); + $("#dialogfooterno").click( + function() { + rc.trigger(d.dialog.buttons.actions.no, d.dialog.buttons.params); + } + ); + $("#dialogfooteryesno").show(); + break; + } + } + + $("#dialog").show(); + } + }, + + close: function() { + $("#dialog").hide(); + $(".dialogfooterbuttonset").hide(); + $("#dialogcontent").html(); + } + + }, + + page: { + + init: function() { + + }, + + update: function(d) { + for ( var f in d.page_replacements) { + $("#" + f).html(d.page_replacements[f].content); + } + } + }, + + sources: { + + remove: function(plugin, source) { + rc.ajax.get(base_url + "ajax/delete-source/plugin/" + plugin + "/id/" + source); + }, + + remove_confirmed: function(plugin, source) { + rc.ajax.get(base_url + "ajax/delete-source/plugin/" + plugin + "/id/" + source + "/confirm/"); + } + + }, + + actions: { + + 'close-dialog': function(params) { + rc.dialog.close(); + }, + + 'delete-source-confirm': function(params) { + rc.sources.remove_confirmed(params['plugin'], params['id']); + } + + }, + + trigger: function(action, params) { + // Handle a list of actions by repeated calling self for each argument + if (action instanceof Array) { + for(i in action) { + rc.trigger(action[i], params); + } + return; + } + + // Check if action is supported, and execute it + if (rc.actions[action]) { + rc.actions[action](params); + } else { + console.log("Action not supported: " +action); + } + } + +}; + +$(document).ready(rc.init); diff --git a/webui/source/pages/ajax/delete-source.php b/webui/source/pages/ajax/delete-source.php new file mode 100644 index 0000000..c43e37f --- /dev/null +++ b/webui/source/pages/ajax/delete-source.php @@ -0,0 +1,35 @@ +request(); +$config = $main->config(); + +// Grab the name of this source +$encoded_filename = null; +if ($req->exists('confirm')) { + $this->smarty->assign('confirmed', true); + + $plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters'); + $encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters'); + + $source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false); + $source->delete(); + + // Generate a new list of sources to update the page with + $all_sources = RippingCluster_Source_PluginFactory::enumerateAll(); + $this->smarty->assign('all_sources', $all_sources); + +} else { + $this->smarty->assign('confirmed', false); + + $plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters'); + $encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters'); + + $source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false); + + $this->smarty->assign('source', $source); + $this->smarty->assign('source_plugin', $plugin); + $this->smarty->assign('source_id', $encoded_filename); +} + +?> \ No newline at end of file diff --git a/webui/source/pages/ajax/source-list.php b/webui/source/pages/ajax/source-list.php new file mode 100644 index 0000000..483dceb --- /dev/null +++ b/webui/source/pages/ajax/source-list.php @@ -0,0 +1,9 @@ +config(); + +$all_sources = RippingCluster_Source_PluginFactory::enumerateAll(); +$this->smarty->assign('all_sources', $all_sources); + +?> \ No newline at end of file diff --git a/webui/source/pages/rips/setup-rip.php b/webui/source/pages/rips/setup.php similarity index 95% rename from webui/source/pages/rips/setup-rip.php rename to webui/source/pages/rips/setup.php index 08ca181..34c04db 100644 --- a/webui/source/pages/rips/setup-rip.php +++ b/webui/source/pages/rips/setup.php @@ -15,7 +15,7 @@ if ($req->exists('submit')) { // Spawn the background client process to run all the jobs RippingCluster_Job::runAllJobs(); - RippingCluster_Page::redirect('rips/setup-rip/queued'); + RippingCluster_Page::redirect('rips/setup/queued'); } elseif ($req->exists('queued')) { $this->smarty->assign('rips_submitted', true); diff --git a/webui/source/pages/rips/source-details.php b/webui/source/pages/sources/details.php similarity index 100% rename from webui/source/pages/rips/source-details.php rename to webui/source/pages/sources/details.php diff --git a/webui/source/pages/rips/sources.php b/webui/source/pages/sources/list.php similarity index 100% rename from webui/source/pages/rips/sources.php rename to webui/source/pages/sources/list.php diff --git a/webui/source/templates/ajax.tpl b/webui/source/templates/ajax.tpl new file mode 100644 index 0000000..99362e6 --- /dev/null +++ b/webui/source/templates/ajax.tpl @@ -0,0 +1,11 @@ +{ + {if $messages} + messages: [ + {foreach from=$messages item=message} + '{$message}', + {/foreach} + ], + {/if} + + {$page_content} +} \ No newline at end of file diff --git a/webui/source/templates/ajax/delete-source.tpl b/webui/source/templates/ajax/delete-source.tpl new file mode 100644 index 0000000..1177770 --- /dev/null +++ b/webui/source/templates/ajax/delete-source.tpl @@ -0,0 +1,37 @@ + +"page_replacements": { + {if $confirmed} + "source-list": { + {include file="fragments/source-list.tpl" assign="sources_html"} + "content": {$sources_html|json_encode} + } + {else} + "dialogcontent": { + {include file="fragments/delete-source.tpl" assign="delete_source_html"} + "content": {$delete_source_html|json_encode} + } + {/if} + +{if ! $confirmed} +}, + +"dialog": { + "show": true, + "buttons": { + "type": "yesno", + "actions": { + "yes": [ + "delete-source-confirm", + "close-dialog" + ], + "no": "close-dialog" + }, + "params": { + "plugin": {$source_plugin|json_encode}, + "id": {$source_id|json_encode} + } + } +} +{else} +} +{/if} diff --git a/webui/source/templates/ajax/source-list.tpl b/webui/source/templates/ajax/source-list.tpl new file mode 100644 index 0000000..082f2ce --- /dev/null +++ b/webui/source/templates/ajax/source-list.tpl @@ -0,0 +1,6 @@ +"page_replacements": { + "source-list": { + {include file="fragments/source-list.tpl" assign="sources_html"} + "content": {$sources_html|json_encode} + } +} \ No newline at end of file diff --git a/webui/source/templates/fragments/delete-source.tpl b/webui/source/templates/fragments/delete-source.tpl new file mode 100644 index 0000000..60f383f --- /dev/null +++ b/webui/source/templates/fragments/delete-source.tpl @@ -0,0 +1,3 @@ +
+ Are you sure you want to delete {$source->plugin()|escape:"html"}:{$source->filename()|escape:"html"}? +
diff --git a/webui/source/templates/fragments/source-list.tpl b/webui/source/templates/fragments/source-list.tpl new file mode 100644 index 0000000..69491e1 --- /dev/null +++ b/webui/source/templates/fragments/source-list.tpl @@ -0,0 +1,25 @@ +{foreach from=$all_sources key=type item=sources} ++ There are no {$type} sources available to rip. +
+ {/if} +