From 7638aa98139b93329beed27c4c7311d2b0840e54 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 18 Dec 2009 12:24:10 -0800 Subject: [PATCH] Add the start of dialog processing to the test client. At this point the dialogs display, but will fail when trying to submit them. --- .../application/controllers/g3_client.php | 66 ++++++++++++++ web_client/application/views/add.html.php | 42 +++++++++ web_client/application/views/delete.html.php | 27 ++++++ web_client/application/views/edit.html.php | 35 ++++++++ web_client/application/views/main.html.php | 13 ++- web_client/css/g3_client.css | 41 ++++++++- web_client/js/g3_client.js | 90 ++++++++++++++++++- 7 files changed, 308 insertions(+), 6 deletions(-) create mode 100644 web_client/application/views/add.html.php create mode 100644 web_client/application/views/delete.html.php create mode 100644 web_client/application/views/edit.html.php diff --git a/web_client/application/controllers/g3_client.php b/web_client/application/controllers/g3_client.php index 0b4e993d..999a048c 100644 --- a/web_client/application/controllers/g3_client.php +++ b/web_client/application/controllers/g3_client.php @@ -76,6 +76,67 @@ class G3_Client_Controller extends Template_Controller { print $this->_get_detail($resource); } + public function __call($function, $args) { + $path = $this->input->get("path"); + $resource = G3Remote::instance()->get_resource("gallery/$path"); + + $this->auto_render = false; + switch ($function) { + case "edit_album": + case "edit_photo": + $readonly = empty($resource->path) ? "readonly" : ""; + $form = array("name" => array("value" => $resource->name, "readonly" => $readonly), + "description" => array("value" => $resource->description, + "readonly" => $readonly), + "slug" => array("value" => $resource->internet_address, + "readonly" => $readonly), + "title" => array("value" => $resource->title, "readonly" => $readonly)); + $errors = array_fill_keys(array_keys($form), ""); + + if ($_POST) { + } else { + $v = new View("edit.html"); + $v->form = $form; + $v->errors = $errors; + $v->path = "g3_client/$function/?path=$path"; + $v->type = $resource->type; + } + break; + case "add_album": + case "add_photo": + $errors = $form = array( + "name" => "", + "description" => "", + "slug" => "", + "image_file" => "", + "title" => ""); + if ($_POST) { + } else { + $v = new View("add.html"); + $v->form = $form; + $v->errors = $errors; + $v->path = "g3_client/$function/?path=$path"; + $v->function = $function; + $function_parts = explode("_", $function); + $v->type = $function_parts[1]; + } + break; + case "delete_album": + case "delete_photo": + if ($_POST) { + } else { + $v = new View("delete.html"); + $v->title = $resource->title; + $v->path = "g3_client/$function/?path=$path"; + } + break; + default: + throw new Kohana_404_Exception(); + } + + print $v; + } + private function _get_album_tree($resource) { $v = new View("tree_part.html"); $v->element = (object)array("title" => $resource->title, "path" => $resource->path); @@ -105,4 +166,9 @@ class G3_Client_Controller extends Template_Controller { } return $v; } + + private function _extract_form_data($resource) { + return $form; + } + } // End G3 Client Controller diff --git a/web_client/application/views/add.html.php b/web_client/application/views/add.html.php new file mode 100644 index 00000000..ce6b3527 --- /dev/null +++ b/web_client/application/views/add.html.php @@ -0,0 +1,42 @@ + +
+ ") ?> +
+ Add Resource +
    +
  • +
    + + {$errors["title"]}" ?> +
  • +
  • +
    + + {$errors["description"]}" ?> +
  • +
  • +
    + + {$errors["name"]}" ?> +
  • +
  • +
    + + {$errors["slug"]}" ?> +
  • + +
  • +
    + + {$errors["image_file"]}" ?> +
  • + +
  • + + 'reset','name'=>'reset'), "Reset") ?> +
  • +
+
+ +
+ diff --git a/web_client/application/views/delete.html.php b/web_client/application/views/delete.html.php new file mode 100644 index 00000000..d44733a9 --- /dev/null +++ b/web_client/application/views/delete.html.php @@ -0,0 +1,27 @@ + + +
+ ") ?> +
+ Confirm Delete +
    +
  • + Do you really want to delete ''.
    + Press Yes to continue, Cancel to quit +
  • +
  • + + +
  • +
+
+ +
+ diff --git a/web_client/application/views/edit.html.php b/web_client/application/views/edit.html.php new file mode 100644 index 00000000..8e56cd3b --- /dev/null +++ b/web_client/application/views/edit.html.php @@ -0,0 +1,35 @@ + +
+ ") ?> +
+ Update Resource +
    +
  • +
    + + {$errors["title"]}" ?> +
  • +
  • +
    + + {$errors["description"]}" ?> +
  • +
  • +
    + + {$errors["name"]}" ?> +
  • +
  • +
    + + {$errors["slug"]}" ?> +
  • +
  • + + 'reset','name'=>'reset'), "Reset") ?> +
  • +
+
+ +
+ diff --git a/web_client/application/views/main.html.php b/web_client/application/views/main.html.php index 1f0f2991..f56f1d81 100644 --- a/web_client/application/views/main.html.php +++ b/web_client/application/views/main.html.php @@ -20,8 +20,17 @@
- Add Album -   + Add Album + + +   + +
+
    +
  • Add Album
  • +
  • Add Photo
  • +
+
diff --git a/web_client/css/g3_client.css b/web_client/css/g3_client.css index bc3339c0..761de31c 100644 --- a/web_client/css/g3_client.css +++ b/web_client/css/g3_client.css @@ -30,11 +30,30 @@ height: 100%; } +#g-dialog { + background-color: #666666; + color: #FF9933; +} + form li { padding-top: .4em; + text-align: left; +} + +form li input[type=text], +form li input[type=file], +form li textarea { + width: 100%; +} + +form li input[readonly=readonly], +form li textarea[readonly=readonly] { + background-color: #999999; + color: #FF9933; } form legend { + color: #FF9933; font-size: 1.2em; font-weight: bold; } @@ -201,8 +220,8 @@ a.ui-state-default { /* remove extra button width in IE */ button.wc-button { - width:auto; - overflow:visible; + width: auto; + overflow: visible; } .wc-button-icon-left { @@ -256,3 +275,21 @@ button.wc-button { .wc-toolbar .wc-button { font-size: 1em; } + +#wc-resource-list { + border-style: solid; + border-width: 0px 1px 1px 1px; + background: #FFFFFF; + color: #F6A828; + display: none; + float: left; + position: absolute; + z-index: 200; +} + +#wc-resource-list li { + border-top-style: solid; + border-top-width: 1px; + cursor: pointer; + padding: 3px; +} diff --git a/web_client/js/g3_client.js b/web_client/js/g3_client.js index 6948992c..579a2eee 100644 --- a/web_client/js/g3_client.js +++ b/web_client/js/g3_client.js @@ -66,6 +66,34 @@ return false; }); + $("#wc-choose-resource").live("click", function(event){ + event.preventDefault(); + event.stopPropagation(); + if ($("#wc-resource-list:visible").length) { + $("#wc-resource-list").hide(); + } else { + var parent = $(this).parent("div"); + var width = parent.width(); + var height = parent.height(); + var top = parent.position().top; + var current_path = $("#wc-add-resource").attr("ref"); + $("#wc-resource-list li[ref='" + current_path + "']").addClass("ui-selected"); + $("#wc-resource-list") + .css({"top": (top + height - 5) + "px", "width": width + "px"}) + .show(); + } + return false; + }); + + $("#wc-resource-list").live("click", function(event) { + var ref = $(event.originalTarget).attr("ref"); + var text = $(event.originalTarget).text(); + $("#wc-add-resource span").text(text); + $("#wc-add-resource").attr("ref", ref); + $("#wc-resource-list").hide(); + $("#wc-resource-list li.ui-selected").removeClass("ui-selected"); + }); + $("#center a.wc-child-link").live("click", function(event) { $(".wc-thumb-grid-cell.ui-selected").removeClass("ui-selected"); $(this).parents("li:first").addClass("ui-selected"); @@ -77,7 +105,9 @@ if ($(this).hasClass("ui-state-disabled")) { return false; } - switch ($(this).attr("ref")) { + + var action = $(this).attr("ref"); + switch (action) { case "parent": get_detail($("span", this).attr("ref"), _set_active_album); break; @@ -107,6 +137,13 @@ _set_navigation_buttons(); } break; + case "edit": + case "delete": + case "add_album": + case "add_photo": + var url = /^add_.*/.test(action) ? action : action + "_" + resource_type; + _open_dialog(url, $("span", this).attr("ref")); + break; default: console.group("process toolbar button click: " + $(this).attr("ref")); console.log(($("span", this).attr("ref"))); @@ -141,6 +178,55 @@ } } + function _open_dialog(dialog, resource_path) { + console.group("_open_dialog(" + dialog + ")"); + console.log(resource_path); + console.groupEnd(); + $("body").append('
'); + $("#g-dialog").dialog({ + model: true, + resizable: false, + position: "center", + close: function() { + $("#g-dialog").dialog("destroy").remove(); + } + }); + $.get("/g3_client/index.php/g3_client/" + dialog, {path: resource_path}, function(data) { + $("#g-dialog").html(data); + + $("#g-dialog").dialog("open"); + if ($("#g-dialog fieldset legend").length) { + $("#g-dialog").dialog('option', 'title', $("#g-dialog fieldset legend:eq(0)").html()); + } + + if ($("#g-dialog form").length) { + $("#g-dialog form").ajaxForm({ + dataType: "json", + beforeSubmit: function(formData, form, options) { + form.find(":submit") + .addClass("ui-state-disabled") + .attr("disabled", "disabled"); + return true; + }, + success: function(data) { + if (data.form) { + $("#g-dialog form").replaceWith(data.form); + $("#g-dialog form :submit").removeClass("ui-state-disabled") + .attr("disabled", null); + self._ajaxify_dialog(); + self.form_loaded(null, $("#g-dialog form")); + if (typeof data.reset == 'function') { + eval(data.reset + '()'); + } + } + if (data.result == "success") { + } + } + }); + } + }); + } + function get_detail(path, callback) { $.get("/g3_client/index.php/g3_client/detail", {path: path}, function(data, textStatus) { $("#wc-detail").html(data); @@ -172,7 +258,7 @@ $(".wc-toolbar .ui-icon-eject").attr("ref", parent_path); $(".wc-toolbar .ui-icon-pencil").attr("ref", current_path); $(".wc-toolbar .ui-icon-trash").attr("ref", current_path); - $(".wc-toolbar #add-resource span") + $(".wc-toolbar #wc-add-resource span") .attr("ref", resource_type == "album" ? current_path : parent_path); var paths = _paths[resource_type == "album" ? current_path : parent_path];