Merge branch 'master' of git://github.com/Glooper/gallery3-contrib
Conflicts: modules/basket/helpers/basket.php modules/basket/helpers/basket_installer.php modules/basket/helpers/product.php modules/basket/views/admin_product_lines.html.php modules/basket/views/confirm_order.html.php modules/basket/views/view_basket.html.php
This commit is contained in:
commit
a660cf3183
154
modules/basket/controllers/admin_postage_bands.php
Normal file
154
modules/basket/controllers/admin_postage_bands.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class Admin_Postage_Bands_Controller extends Controller
|
||||
{
|
||||
/**
|
||||
* the index page of the user homes admin
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->content = new View("admin_postage_bands.html");
|
||||
$view->content->postage_bands = ORM::factory("postage_band")->orderby("name")->find_all();
|
||||
|
||||
print $view;
|
||||
}
|
||||
|
||||
public function add_postage_band_form() {
|
||||
print postage_band::get_add_form_admin();
|
||||
}
|
||||
|
||||
|
||||
public function add_postage_band() {
|
||||
access::verify_csrf();
|
||||
|
||||
$form = postage_band::get_add_form_admin();
|
||||
$valid = $form->validate();
|
||||
$name = $form->add_postage->inputs["name"]->value;
|
||||
$postage = ORM::factory("postage_band")->where("name", $name)->find();
|
||||
if ($postage->loaded) {
|
||||
$form->add_postage->inputs["name"]->add_error("in_use", 1);
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$postage = postage_band::create(
|
||||
$name,
|
||||
$form->add_postage->flat_rate->value,
|
||||
$form->add_postage->per_item->value
|
||||
);
|
||||
|
||||
$postage->save();
|
||||
message::success(t("Created postage band %postage_name", array(
|
||||
"postage_name" => html::clean($postage->name))));
|
||||
print json_encode(array("result" => "success"));
|
||||
} else {
|
||||
print json_encode(array("result" => "error",
|
||||
"form" => $form->__toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_postage_band_form($id) {
|
||||
$postage = ORM::factory("postage_band", $id);
|
||||
if (!$postage->loaded) {
|
||||
kohana::show_404();
|
||||
}
|
||||
print postage_band::get_delete_form_admin($postage);
|
||||
}
|
||||
|
||||
public function delete_postage_band($id) {
|
||||
access::verify_csrf();
|
||||
|
||||
if ($id == user::active()->id || $id == user::guest()->id) {
|
||||
access::forbidden();
|
||||
}
|
||||
|
||||
$postage = ORM::factory("postage_band", $id);
|
||||
if (!$postage->loaded) {
|
||||
kohana::show_404();
|
||||
}
|
||||
|
||||
$form = postage_band::get_delete_form_admin($postage);
|
||||
if($form->validate()) {
|
||||
$name = $postage->name;
|
||||
$postage->delete();
|
||||
} else {
|
||||
print json_encode(array("result" => "error",
|
||||
"form" => $form->__toString()));
|
||||
}
|
||||
|
||||
$message = t("Deleted user %postage_band", array("postage_band" => html::clean($name)));
|
||||
log::success("user", $message);
|
||||
message::success($message);
|
||||
print json_encode(array("result" => "success"));
|
||||
}
|
||||
|
||||
public function edit_postage_band($id) {
|
||||
access::verify_csrf();
|
||||
|
||||
$postage = ORM::factory("postage_band", $id);
|
||||
if (!$postage->loaded) {
|
||||
kohana::show_404();
|
||||
}
|
||||
|
||||
$form = postage_band::get_edit_form_admin($postage);
|
||||
$valid = $form->validate();
|
||||
if ($valid) {
|
||||
$new_name = $form->edit_postage->inputs["name"]->value;
|
||||
if ($new_name != $postage->name &&
|
||||
ORM::factory("postage_band")
|
||||
->where("name", $new_name)
|
||||
->where("id !=", $postage->id)
|
||||
->find()
|
||||
->loaded) {
|
||||
$form->edit_postage->inputs["name"]->add_error("in_use", 1);
|
||||
$valid = false;
|
||||
} else {
|
||||
$postage->name = $new_name;
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$postage->flat_rate = $form->edit_postage->flat_rate->value;
|
||||
$postage->per_item = $form->edit_postage->per_item->value;
|
||||
$postage->save();
|
||||
|
||||
message::success(t("Changed postage band %postage_name",
|
||||
array("postage_name" => html::clean($postage->name))));
|
||||
print json_encode(array("result" => "success"));
|
||||
} else {
|
||||
print json_encode(array("result" => "error",
|
||||
"form" => $form->__toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_postage_band_form($id) {
|
||||
$postage = ORM::factory("postage_band", $id);
|
||||
if (!$postage->loaded) {
|
||||
kohana::show_404();
|
||||
}
|
||||
|
||||
$form = postage_band::get_edit_form_admin($postage);
|
||||
|
||||
print $form;
|
||||
}
|
||||
|
||||
}
|
@ -51,7 +51,11 @@ class Admin_Product_Lines_Controller extends Controller
|
||||
|
||||
if ($valid) {
|
||||
$product = product::create(
|
||||
$name, $form->add_product->cost->value, $form->add_product->description->value);
|
||||
$name,
|
||||
$form->add_product->cost->value,
|
||||
$form->add_product->description->value,
|
||||
$form->add_product->postage_band->value
|
||||
);
|
||||
|
||||
$product->save();
|
||||
message::success(t("Created product %product_name", array(
|
||||
@ -83,7 +87,7 @@ class Admin_Product_Lines_Controller extends Controller
|
||||
kohana::show_404();
|
||||
}
|
||||
|
||||
$form = user::get_delete_form_admin($product);
|
||||
$form = product::get_delete_form_admin($product);
|
||||
if($form->validate()) {
|
||||
$name = $product->name;
|
||||
$product->delete();
|
||||
@ -126,6 +130,7 @@ class Admin_Product_Lines_Controller extends Controller
|
||||
if ($valid) {
|
||||
$product->cost = $form->edit_product->cost->value;
|
||||
$product->description = $form->edit_product->description->value;
|
||||
$product->postage_band_id = $form->edit_product->postage_band->value;
|
||||
$product->save();
|
||||
|
||||
message::success(t("Changed product %product_name",
|
||||
|
@ -31,7 +31,7 @@ class Basket_Controller extends Controller {
|
||||
print $template;
|
||||
}
|
||||
|
||||
private function getCheckoutForm(){
|
||||
private function getCheckoutForm(){
|
||||
$form = new Forge("basket/confirm", "", "post", array("id" => "checkout", "name" =>"checkout"));
|
||||
$group = $form->group("contact")->label(t("Contact Details"));
|
||||
$group->input("fullname")->label(t("Name"))->id("fullname");
|
||||
@ -110,6 +110,8 @@ class Basket_Controller extends Controller {
|
||||
$basket = Session_Basket::get();
|
||||
|
||||
//$admin_address = basket::getEmailAddress();
|
||||
$postage = $basket->postage_cost();
|
||||
$product_cost = $basket->cost();
|
||||
|
||||
$admin_email = "Order for :
|
||||
".$basket->name."
|
||||
@ -121,7 +123,9 @@ class Basket_Controller extends Controller {
|
||||
".$basket->email."
|
||||
".$basket->phone."
|
||||
Placed at ".date("d F Y - H:i" ,time())."
|
||||
Total Owed ".$basket->cost()." in ".basket::getCurrency()."
|
||||
Cost of Ordered Products = ".$product_cost."
|
||||
Postage and Packaging Costs + ".$postage."
|
||||
Total Owed ".($product_cost+$postage)." Total in ".basket::getCurrency()."
|
||||
|
||||
Items Ordered:
|
||||
|
||||
|
@ -42,9 +42,9 @@ class basket_Core {
|
||||
static $format= array(
|
||||
"AUD" => "$",
|
||||
"CAD" => "$",
|
||||
"EUR" => "<EFBFBD>",
|
||||
"GBP" => "<EFBFBD>",
|
||||
"JPY" => "<EFBFBD>",
|
||||
"EUR" => "€",
|
||||
"GBP" => "£",
|
||||
"JPY" => "¥",
|
||||
"USD" => "$",
|
||||
"NZD" => "$",
|
||||
"CHF" => "",
|
||||
@ -114,7 +114,7 @@ class basket_Core {
|
||||
}
|
||||
|
||||
static function formatMoney($money){
|
||||
return self::$format[self::getCurrency()].number_format($money);
|
||||
return self::$format[self::getCurrency()].number_format($money,2);
|
||||
}
|
||||
|
||||
static function setEmailAddress($email){
|
||||
@ -141,6 +141,12 @@ class basket_Core {
|
||||
<input type=\"hidden\" name=\"currency_code\" value=\"".self::getCurrency()."\">
|
||||
<input type=\"hidden\" name=\"business\" value=\"".self::getPaypalAccount()."\"/>";
|
||||
|
||||
$postage = $session_basket->postage_cost();
|
||||
if ($postage > 0) {
|
||||
$form = $form."
|
||||
<input type=\"hidden\" name=\"shipping_1\" value=\"".$postage."\">";
|
||||
}
|
||||
|
||||
$id = 1;
|
||||
foreach ($session_basket->contents as $key => $basket_item){
|
||||
$form = $form."
|
||||
@ -149,6 +155,7 @@ class basket_Core {
|
||||
<input type=\"hidden\" name=\"quantity_$id\" value=\"$basket_item->quantity\"/>";
|
||||
$id++;
|
||||
}
|
||||
|
||||
$form = $form."</form>";
|
||||
|
||||
return $form;
|
||||
|
@ -38,6 +38,11 @@ class basket_event_Core{
|
||||
->id("product_line")
|
||||
->label(t("Product Lines"))
|
||||
->url(url::site("admin/product_lines")));
|
||||
$basket_menu->append(
|
||||
Menu::factory("link")
|
||||
->id("postage_bands")
|
||||
->label(t("Postage Bands"))
|
||||
->url(url::site("admin/postage_bands")));
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,18 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class basket_installer {
|
||||
static function install() {
|
||||
|
||||
class basket_installer
|
||||
{
|
||||
static function install(){
|
||||
|
||||
$db = Database::instance();
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {products} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`name` TEXT NOT NULL,
|
||||
`cost` INTEGER(9) default 0,
|
||||
`cost` DECIMAL(10,2) default 0,
|
||||
`description` varchar(1024),
|
||||
`postage_band_id` int(9) default 1,
|
||||
PRIMARY KEY (`id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
|
||||
@ -40,21 +44,57 @@ class basket_installer {
|
||||
`product_override_id` int(9) NOT NULL,
|
||||
`product_id` int(9) NOT NULL,
|
||||
`include` BOOLEAN default false,
|
||||
`cost` INTEGER(9) default -1,
|
||||
`cost` DECIMAL(10,2) default -1,
|
||||
PRIMARY KEY (`id`))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {postage_bands} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`name` TEXT NOT NULL,
|
||||
`flat_rate` DECIMAL(10,2) default 0,
|
||||
`per_item` DECIMAL(10,2) default 0,
|
||||
PRIMARY KEY (`id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
|
||||
product::create("4x6",5,"4\"x6\" print");
|
||||
product::create("8x10",25,"8\"x10\" print");
|
||||
product::create("8x12",30,"8\"x12\" print");
|
||||
postage_band::create("No Postage",0,0);
|
||||
|
||||
product::create("4x6",5,"4\"x6\" print",1);
|
||||
product::create("8x10",25,"8\"x10\" print",1);
|
||||
product::create("8x12",30,"8\"x12\" print",1);
|
||||
|
||||
|
||||
module::set_version("basket", 2);
|
||||
|
||||
module::set_version("basket", 1);
|
||||
}
|
||||
|
||||
static function uninstall() {
|
||||
static function upgrade($version) {
|
||||
$db = Database::instance();
|
||||
if ($version == 1) {
|
||||
|
||||
// fix for allowing decimel place in money
|
||||
$db->query("ALTER TABLE {products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default 0;");
|
||||
$db->query("ALTER TABLE {item_products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default -1;");
|
||||
|
||||
// postage bands
|
||||
$db->query("ALTER TABLE {products} ADD COLUMN `postage_band_id` int(9) default 1");
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {postage_bands} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`name` TEXT NOT NULL,
|
||||
`flat_rate` DECIMAL(10,2) default 0,
|
||||
`per_item` DECIMAL(10,2) default 0,
|
||||
PRIMARY KEY (`id`))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
postage_band::create("No Postage",0,0);
|
||||
|
||||
module::set_version("basket", $version = 2);
|
||||
}
|
||||
}
|
||||
|
||||
static function uninstall(){
|
||||
$db = Database::instance();
|
||||
$db->query("DROP TABLE IF EXISTS {products}");
|
||||
$db->query("DROP TABLE IF EXISTS {product_overrides}");
|
||||
$db->query("DROP TABLE IF EXISTS {item_products}");
|
||||
$db->query("DROP TABLE IF EXISTS {postage_bands}");
|
||||
}
|
||||
}
|
||||
|
99
modules/basket/helpers/postage_band.php
Normal file
99
modules/basket/helpers/postage_band.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class postage_band_Core {
|
||||
|
||||
static function get_add_form_admin() {
|
||||
$form = new Forge("admin/postage_bands/add_postage_band", "", "post", array("id" => "gAddPostageForm"));
|
||||
$group = $form->group("add_postage")->label(t("Add Postage Band"));
|
||||
$group->input("name")->label(t("Name"))->id("gPostageName")
|
||||
->error_messages("in_use", t("There is already a postage band with that name"));
|
||||
$group->input("flat_rate")->label(t("Flat Rate"))->id("gFlatRate");
|
||||
$group->input("per_item")->label(t("Per Item"))->id("gPetItem");
|
||||
$group->submit("")->value(t("Add Postage Band"));
|
||||
$postage = ORM::factory("postage_band");
|
||||
$form->add_rules_from($postage);
|
||||
return $form;
|
||||
}
|
||||
|
||||
static function get_edit_form_admin($postage) {
|
||||
$form = new Forge("admin/postage_bands/edit_postage_band/$postage->id", "", "post",
|
||||
array("id" => "gEditPostageForm"));
|
||||
$group = $form->group("edit_postage")->label(t("Edit Postage Band"));
|
||||
$group->input("name")->label(t("Name"))->id("gPostageName")->value($postage->name);
|
||||
$group->inputs["name"]->error_messages(
|
||||
"in_use", t("There is already a postage band with that name"));
|
||||
$group->input("flat_rate")->label(t("Flat Rate"))->id("gFlatRate")->value($postage->flat_rate);
|
||||
$group->input("per_item")->label(t("Per Item"))->id("gPetItem")->
|
||||
value($postage->per_item);
|
||||
|
||||
$group->submit("")->value(t("Modify Postage Band"));
|
||||
$form->add_rules_from($postage);
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
static function get_delete_form_admin($postage) {
|
||||
$form = new Forge("admin/postage_bands/delete_postage_band/$postage->id", "", "post",
|
||||
array("id" => "gDeletePostageForm"));
|
||||
$group = $form->group("delete_postage")->label(
|
||||
t("Are you sure you want to delete postage band %name?", array("name" => $postage->name)));
|
||||
$group->submit("")->value(t("Delete postage band %name", array("name" => $postage->name)));
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new postage band
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $full_name
|
||||
* @param string $password
|
||||
* @return User_Model
|
||||
*/
|
||||
static function create($name, $flatrate, $peritemcost) {
|
||||
$postage = ORM::factory("postage_band")->where("name", $name)->find();
|
||||
if ($postage->loaded) {
|
||||
throw new Exception("@todo postage already EXISTS $name");
|
||||
}
|
||||
|
||||
$postage->name = $name;
|
||||
$postage->flat_rate = $flatrate;
|
||||
$postage->per_item = $peritemcost;
|
||||
|
||||
$postage->save();
|
||||
return $postage;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the array of postage bands
|
||||
* @return an array of postage bands
|
||||
*/
|
||||
static function getPostageArray(){
|
||||
$postagea = array();
|
||||
|
||||
$postages = ORM::factory("postage_band")->find_all();
|
||||
foreach ($postages as $postage){
|
||||
$show = true;
|
||||
$postagea[$postage->id] = $postage->name;
|
||||
}
|
||||
|
||||
return $postagea;
|
||||
}
|
||||
|
||||
}
|
@ -24,8 +24,11 @@ class product_Core {
|
||||
$group = $form->group("add_product")->label(t("Add Product"));
|
||||
$group->input("name")->label(t("Name"))->id("g-product-name")
|
||||
->error_messages("in_use", t("There is already a product with that name"));
|
||||
$group->input("cost")->label(t("Cost"))->id("g-cost");
|
||||
$group->input("cost")->label(t("Cost"))->id("gCost");
|
||||
$group->input("description")->label(t("Description"))->id("g-description");
|
||||
$group->dropdown("postage_band")
|
||||
->label(t("Postage Band"))
|
||||
->options(postage_band::getPostageArray());
|
||||
$group->submit("")->value(t("Add Product"));
|
||||
$product = ORM::factory("product");
|
||||
$form->add_rules_from($product);
|
||||
@ -42,6 +45,10 @@ class product_Core {
|
||||
$group->input("cost")->label(t("Cost"))->id("g-cost")->value($product->cost);
|
||||
$group->input("description")->label(t("Description"))->id("g-description")->
|
||||
value($product->description);
|
||||
$group->dropdown("postage_band")
|
||||
->label(t("Postage Band"))
|
||||
->options(postage_band::getPostageArray())
|
||||
->selected($product->postage_band_id);
|
||||
|
||||
$group->submit("")->value(t("Modify Product"));
|
||||
$form->add_rules_from($product);
|
||||
@ -66,7 +73,7 @@ class product_Core {
|
||||
* @param string $password
|
||||
* @return User_Model
|
||||
*/
|
||||
static function create($name, $cost, $description) {
|
||||
static function create($name, $cost, $description, $postage_band) {
|
||||
$product = ORM::factory("product")->where("name", $name)->find();
|
||||
if ($product->loaded) {
|
||||
throw new Exception("@todo USER_ALREADY_EXISTS $name");
|
||||
@ -75,7 +82,7 @@ class product_Core {
|
||||
$product->name = $name;
|
||||
$product->cost = $cost;
|
||||
$product->description = $description;
|
||||
|
||||
$product->postage_band_id = $postage_band;
|
||||
$product->save();
|
||||
return $product;
|
||||
}
|
||||
|
@ -64,6 +64,11 @@ class basket_item
|
||||
return $prod->description;
|
||||
}
|
||||
|
||||
public function getProduct(){
|
||||
$prod = ORM::factory("product", $this->product);
|
||||
return $prod;
|
||||
}
|
||||
|
||||
public function getCode(){
|
||||
$photo = ORM::factory("item", $this->item);
|
||||
$prod = ORM::factory("product", $this->product);
|
||||
@ -122,6 +127,32 @@ class Session_Basket_Core {
|
||||
unset($this->contents[$key]);
|
||||
}
|
||||
|
||||
public function postage_cost(){
|
||||
$postage_cost = 0;
|
||||
$postage_bands = array();
|
||||
$postage_quantities = array();
|
||||
if (isset($this->contents)){
|
||||
// create array of postage bands
|
||||
foreach ($this->contents as $product => $basket_item){
|
||||
$postage_band = $basket_item->getProduct()->postage_band;
|
||||
if (isset($postage_bands[$postage_band->id]))
|
||||
{
|
||||
$postage_quantities[$postage_band->id] += $basket_item->quantity;
|
||||
}
|
||||
else
|
||||
{
|
||||
$postage_quantities[$postage_band->id] = $basket_item->quantity;
|
||||
$postage_bands[$postage_band->id] = $postage_band;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($postage_bands as $id => $postage_band){
|
||||
$postage_cost += $postage_band->flat_rate + ($postage_band->per_item * $postage_quantities[$id]);
|
||||
}
|
||||
}
|
||||
return $postage_cost;
|
||||
}
|
||||
|
||||
public function cost(){
|
||||
$cost = 0;
|
||||
if (isset($this->contents)){
|
||||
|
26
modules/basket/models/postage_band.php
Normal file
26
modules/basket/models/postage_band.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class Postage_Band_Model extends ORM {
|
||||
var $rules = array(
|
||||
"name" => "length[1,32]");
|
||||
|
||||
protected $has_many=array('products');
|
||||
|
||||
}
|
@ -21,4 +21,6 @@ class Product_Model extends ORM {
|
||||
var $rules = array(
|
||||
"name" => "length[1,32]",
|
||||
"description" => "length[0,255]");
|
||||
protected $belongs_to=array('postage_band');
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
name = "Shopping Basket"
|
||||
description = "Provides a simple shopping basket and checkout with paypal integration"
|
||||
version = 1
|
||||
version = 2
|
||||
|
70
modules/basket/views/admin_postage_bands.html.php
Normal file
70
modules/basket/views/admin_postage_bands.html.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.")
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
?>
|
||||
<div class="gBlock">
|
||||
|
||||
<a href="<?= url::site("admin/postage_bands/add_postage_band_form") ?>"
|
||||
class="gDialogLink gButtonLink right ui-icon-left ui-state-default ui-corner-all"
|
||||
title="<?= t("Create a new Postage Band") ?>">
|
||||
<span class="ui-icon ui-icon-circle-plus"></span>
|
||||
<?= t("Add a new Postage Band") ?>
|
||||
</a>
|
||||
|
||||
<h2>
|
||||
<?= t("Postage Bands") ?>
|
||||
</h2>
|
||||
|
||||
<div class="gBlockContent">
|
||||
<table id="gPostageAdminList">
|
||||
<tr>
|
||||
<th><?= t("Name") ?></th>
|
||||
<th><?= t("Flat Rate") ?></th>
|
||||
<th><?= t("Per Item") ?></th>
|
||||
<th><?= t("Actions") ?></th>
|
||||
|
||||
</tr>
|
||||
<? foreach ($postage_bands as $i => $postage_band): ?>
|
||||
<tr id="gProduct-<?= $postage_band->id ?>" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||
<td id="product-<?= $postage_band->id ?>" class="core-info ">
|
||||
<?= html::clean($postage_band->name) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= basket::formatMoney($postage_band->flat_rate) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= basket::formatMoney($postage_band->per_item) ?>
|
||||
</td>
|
||||
<td class="gActions">
|
||||
<a href="<?= url::site("admin/postage_bands/edit_postage_band_form/$postage_band->id") ?>"
|
||||
open_text="<?= t("close") ?>"
|
||||
class="gPanelLink gButtonLink ui-state-default ui-corner-all ui-icon-left">
|
||||
<span class="ui-icon ui-icon-pencil"></span><span class="gButtonText"><?= t("edit") ?></span></a>
|
||||
|
||||
<a href="<?= url::site("admin/postage_bands/delete_postage_band_form/$postage_band->id") ?>"
|
||||
class="gDialogLink gButtonLink ui-state-default ui-corner-all ui-icon-left">
|
||||
<span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<? endforeach ?>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
@ -37,6 +37,7 @@
|
||||
<th><?= t("Name") ?></th>
|
||||
<th><?= t("Cost") ?></th>
|
||||
<th><?= t("Description") ?></th>
|
||||
<th><?= t("Postage Band") ?></th>
|
||||
<th><?= t("Actions") ?></th>
|
||||
|
||||
</tr>
|
||||
@ -51,6 +52,11 @@
|
||||
<td>
|
||||
<?= html::clean($product->description) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= html::clean($product->postage_band->name) ?>
|
||||
</td>
|
||||
|
||||
|
||||
<td class="g-actions">
|
||||
<a href="<?= url::site("admin/product_lines/edit_product_form/$product->id") ?>"
|
||||
open_text="<?= t("close") ?>"
|
||||
|
@ -51,8 +51,14 @@ function so(){document.confirm.submit();}
|
||||
</td>
|
||||
</tr>
|
||||
<? endforeach ?>
|
||||
<? $postage = $basket->postage_cost();?>
|
||||
<? if ($postage > 0):?>
|
||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean($basket->cost())?></td>
|
||||
<td></td><td></td><td>Postage and Packaging</td><td><?= html::clean(basket::formatMoney($postage))?></td><td></td>
|
||||
</tr>
|
||||
<? endif;?>
|
||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($basket->cost() + $postage))?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -88,8 +88,14 @@
|
||||
</td>
|
||||
</tr>
|
||||
<? endforeach ?>
|
||||
<? $postage = $basket->postage_cost();?>
|
||||
<? if ($postage > 0):?>
|
||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($total))?></td><td></td>
|
||||
<td></td><td></td><td>Postage and Packaging</td><td><?= html::clean(basket::formatMoney($postage))?></td><td></td>
|
||||
</tr>
|
||||
<? endif;?>
|
||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($total + $postage))?></td><td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
11
modules/gwtorganise/.classpath
Normal file
11
modules/gwtorganise/.classpath
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="C:/Users/User/code/gwt-dnd/gwt-dnd-2.6.5.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/User/code/gwt-dnd/gwt-dnd-2.6.5-javadoc.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/User/code/gwt-gears/gwt-gears.jar"/>
|
||||
<classpathentry kind="output" path="war/WEB-INF/classes"/>
|
||||
</classpath>
|
40
modules/gwtorganise/.project
Normal file
40
modules/gwtorganise/.project
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>gwtorganise</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.appengine.eclipse.core.enhancerbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.appengine.eclipse.core.projectValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>com.google.appengine.eclipse.core.gaeNature</nature>
|
||||
<nature>com.google.gwt.eclipse.core.gwtNature</nature>
|
||||
<nature>com.google.gdt.eclipse.core.webAppNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,3 @@
|
||||
#Sun Aug 30 20:30:24 NZST 2009
|
||||
eclipse.preferences.version=1
|
||||
filesCopiedToWebInfLib=appengine-api-1.0-sdk-1.2.2.jar|datanucleus-appengine-1.0.2.final.jar|datanucleus-core-1.1.4-gae.jar|datanucleus-jpa-1.1.4.jar|geronimo-jpa_3.0_spec-1.1.1.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-ea.jar
|
@ -0,0 +1,4 @@
|
||||
#Thu Sep 24 11:47:04 NZST 2009
|
||||
eclipse.preferences.version=1
|
||||
filesCopiedToWebInfLib=gwt-servlet.jar
|
||||
gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBW11dPjwvZXh0cmEtYXJncz48dm0tYXJncz48IVtDREFUQVstWG14NTEybV1dPjwvdm0tYXJncz48L2d3dC1jb21waWxlLXNldHRpbmdzPg\=\=
|
26
modules/gwtorganise/controllers/admin_gwtorganise.php
Normal file
26
modules/gwtorganise/controllers/admin_gwtorganise.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class Admin_GWTOrganise_Controller extends Controller {
|
||||
public function index() {
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->content = new View("gwtorganise_view.html");
|
||||
print $view;
|
||||
}
|
||||
}
|
257
modules/gwtorganise/controllers/json_album.php
Normal file
257
modules/gwtorganise/controllers/json_album.php
Normal file
@ -0,0 +1,257 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class Json_Album_Controller extends Controller {
|
||||
|
||||
|
||||
private function child_json_encode($child){
|
||||
return array(
|
||||
'id' => $child->id,
|
||||
'title' => $child->title,
|
||||
'type' => $child->type,
|
||||
'thumb' => $child->thumb_url(),
|
||||
'resize' => $child->resize_url(),
|
||||
'sort' => $child->sort_column);
|
||||
}
|
||||
|
||||
private function child_elements($item_id, $where = array()) {
|
||||
$item = ORM::factory("item", $item_id);
|
||||
access::required("view", $item);
|
||||
|
||||
$children = $item->children(null, 0, $where);
|
||||
$encoded = array();
|
||||
foreach ($children as $id => $child){
|
||||
$encoded[$id] = self::child_json_encode($child);
|
||||
}
|
||||
|
||||
return json_encode($encoded);
|
||||
}
|
||||
|
||||
function is_admin() {
|
||||
if (user::active()->admin) {
|
||||
print json_encode(array("result" => "success", "csrf" => access::csrf_token()));
|
||||
return;
|
||||
}
|
||||
print json_encode(array("result" => "failure"));
|
||||
|
||||
}
|
||||
|
||||
function albums($item_id) {
|
||||
|
||||
print $this->child_elements($item_id,array("type" => "album"));
|
||||
}
|
||||
|
||||
function children($item_id){
|
||||
|
||||
print $this->child_elements($item_id);
|
||||
}
|
||||
|
||||
function item($item_id){
|
||||
|
||||
$item = ORM::factory("item", $item_id);
|
||||
access::required("view", $item);
|
||||
print json_encode(self::child_json_encode($item));
|
||||
}
|
||||
|
||||
|
||||
function move_to($target_album_id) {
|
||||
access::verify_csrf();
|
||||
|
||||
$target_album = ORM::factory("item", $target_album_id);
|
||||
|
||||
$js = json_decode($_REQUEST["sourceids"]);
|
||||
|
||||
$i = 0;
|
||||
foreach ($js as $source_id) {
|
||||
$source = ORM::factory("item", $source_id);
|
||||
if (!$source->contains($target_album)) {
|
||||
item::move($source, $target_album);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
print json_encode(array("result" => "success"));
|
||||
}
|
||||
|
||||
function rearrange($target_id, $before_or_after) {
|
||||
access::verify_csrf();
|
||||
$target = ORM::factory("item", $target_id);
|
||||
$album = $target->parent();
|
||||
access::required("view", $album);
|
||||
access::required("edit", $album);
|
||||
|
||||
$source_ids = json_decode($_REQUEST["sourceids"]);
|
||||
|
||||
if ($album->sort_column != "weight") {
|
||||
$i = 0;
|
||||
foreach ($album->children() as $child) {
|
||||
// Do this directly in the database to avoid sending notifications
|
||||
Database::Instance()->update("items", array("weight" => ++$i), array("id" => $child->id));
|
||||
}
|
||||
$album->sort_column = "weight";
|
||||
$album->sort_order = "ASC";
|
||||
$album->save();
|
||||
$target->reload();
|
||||
}
|
||||
|
||||
// Find the insertion point
|
||||
$target_weight = $target->weight;
|
||||
if ($before_or_after == "after") {
|
||||
$target_weight++;
|
||||
}
|
||||
|
||||
// Make a hole
|
||||
$count = count($source_ids);
|
||||
Database::Instance()->query(
|
||||
"UPDATE {items} " .
|
||||
"SET `weight` = `weight` + $count " .
|
||||
"WHERE `weight` >= $target_weight AND `parent_id` = {$album->id}");
|
||||
|
||||
// Insert source items into the hole
|
||||
foreach ($source_ids as $source_id) {
|
||||
Database::Instance()->update(
|
||||
"items", array("weight" => $target_weight++), array("id" => $source_id));
|
||||
}
|
||||
|
||||
module::event("album_rearrange", $album);
|
||||
|
||||
print json_encode(array("result" => "success"));
|
||||
|
||||
}
|
||||
|
||||
public function start() {
|
||||
batch::start();
|
||||
}
|
||||
|
||||
public function add_photo($id) {
|
||||
access::verify_csrf();
|
||||
$album = ORM::factory("item", $id);
|
||||
access::required("view", $album);
|
||||
access::required("add", $album);
|
||||
|
||||
|
||||
try {
|
||||
$name = $_REQUEST["filename"];
|
||||
$body = @file_get_contents('php://input');
|
||||
//$stream = http_get_request_body();
|
||||
|
||||
$directory = Kohana::config('upload.directory', TRUE);
|
||||
|
||||
// Make sure the directory ends with a slash
|
||||
$directory = str_replace('\\','/',$directory);
|
||||
$directory = rtrim($directory, '/').'/';
|
||||
|
||||
if ( ! is_dir($directory) AND Kohana::config('upload.create_directories') === TRUE)
|
||||
{
|
||||
// Create the upload directory
|
||||
mkdir($directory, 0777, TRUE);
|
||||
}
|
||||
|
||||
if ( ! is_writable($directory))
|
||||
throw new Kohana_Exception('upload.not_writable', $directory);
|
||||
|
||||
$temp_filename = $directory.$name;
|
||||
$file = fopen($temp_filename,'w');
|
||||
|
||||
fwrite($file,$body);
|
||||
|
||||
fclose($file);
|
||||
|
||||
|
||||
|
||||
$title = item::convert_filename_to_title($name);
|
||||
$path_info = @pathinfo($temp_filename);
|
||||
if (array_key_exists("extension", $path_info) &&
|
||||
in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
|
||||
$item = movie::create($album, $temp_filename, $name, $title);
|
||||
log::success("content", t("Added a movie"),
|
||||
html::anchor("movies/$item->id", t("view movie")));
|
||||
} else {
|
||||
$item = photo::create($album, $temp_filename, $name, $title);
|
||||
log::success("content", t("Added a photo"),
|
||||
html::anchor("photos/$item->id", t("view photo")));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Kohana::log("alert", $e->__toString());
|
||||
if (file_exists($temp_filename)) {
|
||||
unlink($temp_filename);
|
||||
}
|
||||
header("HTTP/1.1 500 Internal Server Error");
|
||||
print "ERROR: " . $e->getMessage();
|
||||
return;
|
||||
}
|
||||
unlink($temp_filename);
|
||||
|
||||
print json_encode(self::child_json_encode($item));
|
||||
}
|
||||
|
||||
public function make_album_cover($id) {
|
||||
access::verify_csrf();
|
||||
|
||||
$item = model_cache::get("item", $id);
|
||||
access::required("view", $item);
|
||||
access::required("view", $item->parent());
|
||||
access::required("edit", $item->parent());
|
||||
|
||||
item::make_album_cover($item);
|
||||
|
||||
print json_encode(array("result" => "success"));
|
||||
}
|
||||
|
||||
public function rotate($id, $dir) {
|
||||
access::verify_csrf();
|
||||
$item = model_cache::get("item", $id);
|
||||
access::required("view", $item);
|
||||
access::required("edit", $item);
|
||||
|
||||
$degrees = 0;
|
||||
switch($dir) {
|
||||
case "ccw":
|
||||
$degrees = -90;
|
||||
break;
|
||||
|
||||
case "cw":
|
||||
$degrees = 90;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($degrees) {
|
||||
graphics::rotate($item->file_path(), $item->file_path(), array("degrees" => $degrees));
|
||||
|
||||
list($item->width, $item->height) = getimagesize($item->file_path());
|
||||
$item->resize_dirty= 1;
|
||||
$item->thumb_dirty= 1;
|
||||
$item->save();
|
||||
|
||||
graphics::generate($item);
|
||||
|
||||
$parent = $item->parent();
|
||||
if ($parent->album_cover_item_id == $item->id) {
|
||||
copy($item->thumb_path(), $parent->thumb_path());
|
||||
$parent->thumb_width = $item->thumb_width;
|
||||
$parent->thumb_height = $item->thumb_height;
|
||||
$parent->save();
|
||||
}
|
||||
}
|
||||
|
||||
print json_encode(self::child_json_encode($item));
|
||||
}
|
||||
|
||||
|
||||
}
|
34
modules/gwtorganise/helpers/gwtorganise_event.php
Normal file
34
modules/gwtorganise/helpers/gwtorganise_event.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class gwtorganise_event_Core{
|
||||
/**
|
||||
* adds the shopping basket administration controls to the admin menu
|
||||
*/
|
||||
static function admin_menu($menu, $theme){
|
||||
|
||||
|
||||
$menu->add_after("users_groups",
|
||||
Menu::factory("link")
|
||||
->id("gwtorganise")
|
||||
->label(t("GWT Organise"))
|
||||
->url(url::site("admin/gwtorganise")));
|
||||
}
|
||||
}
|
31
modules/gwtorganise/helpers/gwtorganise_installer.php
Normal file
31
modules/gwtorganise/helpers/gwtorganise_installer.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class gwtorganise_installer
|
||||
{
|
||||
static function install(){
|
||||
module::set_version("gwtorganise", 1);
|
||||
}
|
||||
static function activate() {
|
||||
}
|
||||
|
||||
static function deactivate(){
|
||||
}
|
||||
}
|
3
modules/gwtorganise/module.info
Normal file
3
modules/gwtorganise/module.info
Normal file
@ -0,0 +1,3 @@
|
||||
name = "GWT Organise"
|
||||
description = "An alternative to organise and simple uploader making use of funky google technology."
|
||||
version = 1
|
15
modules/gwtorganise/src/META-INF/jdoconfig.xml
Normal file
15
modules/gwtorganise/src/META-INF/jdoconfig.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
|
||||
|
||||
<persistence-manager-factory name="transactions-optional">
|
||||
<property name="javax.jdo.PersistenceManagerFactoryClass"
|
||||
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
|
||||
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
|
||||
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
|
||||
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
|
||||
<property name="javax.jdo.option.RetainValues" value="true"/>
|
||||
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
|
||||
</persistence-manager-factory>
|
||||
</jdoconfig>
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
|
||||
<module rename-to='g3viewer'>
|
||||
<!-- Inherit the core Web Toolkit stuff. -->
|
||||
<inherits name='com.google.gwt.user.User'/><inherits name="com.google.gwt.http.HTTP" /><inherits
|
||||
name="com.google.gwt.json.JSON" /><inherits name="com.google.gwt.user.theme.standard.Standard" />
|
||||
<entry-point class='com.gloopics.g3viewer.client.G3Viewer'/><inherits
|
||||
name="com.allen_sauer.gwt.dnd.gwt-dnd" /><inherits name="com.google.gwt.gears.Gears" />
|
||||
|
||||
<replace-with class="com.gloopics.g3viewer.client.NoGears">
|
||||
<when-type-is class="com.gloopics.g3viewer.client.G3Viewer"/>
|
||||
<when-property-is name="gears.installed" value="false"/>
|
||||
</replace-with>
|
||||
</module>
|
481
modules/gwtorganise/src/com/gloopics/g3viewer/client/Album.java
Normal file
481
modules/gwtorganise/src/com/gloopics/g3viewer/client/Album.java
Normal file
@ -0,0 +1,481 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gwt.event.logical.shared.CloseEvent;
|
||||
import com.google.gwt.event.logical.shared.CloseHandler;
|
||||
import com.google.gwt.gears.client.Factory;
|
||||
import com.google.gwt.gears.client.desktop.Desktop;
|
||||
import com.google.gwt.gears.client.desktop.File;
|
||||
import com.google.gwt.gears.client.desktop.OpenFilesHandler;
|
||||
import com.google.gwt.json.client.JSONArray;
|
||||
import com.google.gwt.json.client.JSONNumber;
|
||||
import com.google.gwt.json.client.JSONObject;
|
||||
import com.google.gwt.json.client.JSONString;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
import com.google.gwt.user.client.Command;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.MenuBar;
|
||||
import com.google.gwt.user.client.ui.MenuItem;
|
||||
import com.google.gwt.user.client.ui.PopupPanel;
|
||||
import com.google.gwt.user.client.ui.TreeItem;
|
||||
|
||||
/**
|
||||
* encapsulates an album
|
||||
* @author User
|
||||
*
|
||||
*/
|
||||
public class Album extends TreeItem {
|
||||
|
||||
private final int m_ID;
|
||||
|
||||
private String m_Title;
|
||||
|
||||
|
||||
private final G3Viewer m_Container;
|
||||
|
||||
private final View m_View;
|
||||
|
||||
private final Label m_Label;
|
||||
|
||||
private String m_Sort;
|
||||
|
||||
private final List<Item> m_Items = new ArrayList<Item>();
|
||||
|
||||
private final Map<Integer, Item> m_IDtoItem = new HashMap<Integer, Item>();
|
||||
|
||||
private final Map<Integer, Album> m_IDtoAlbum = new HashMap<Integer, Album>();
|
||||
|
||||
private final LinkedList<UploadFile> m_UploadQueue = new LinkedList<UploadFile>();
|
||||
|
||||
private boolean m_Running = false;
|
||||
|
||||
private final AlbumTreeDropController m_DropController;
|
||||
|
||||
public Album(JSONObject jsonObject, G3Viewer a_Container)
|
||||
{
|
||||
m_ID = (int)((JSONNumber)jsonObject.get("id")).doubleValue();
|
||||
m_Title = ((JSONString)jsonObject.get("title")).stringValue();
|
||||
m_Sort = ((JSONString)jsonObject.get("sort")).stringValue();
|
||||
|
||||
m_Container = a_Container;
|
||||
m_View = a_Container.getView();
|
||||
m_DropController = new AlbumTreeDropController(this);
|
||||
m_Label = initComponents();
|
||||
|
||||
}
|
||||
|
||||
public Album(G3Viewer a_Container)
|
||||
{
|
||||
m_ID = 1;
|
||||
m_Title = "Root";
|
||||
m_Container = a_Container;
|
||||
m_View = a_Container.getView();
|
||||
m_Sort = "Unknown";
|
||||
m_DropController = new AlbumTreeDropController(this);
|
||||
m_Label = initComponents();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void updateValues(JSONValue a_Jso){
|
||||
JSONObject jso = a_Jso.isObject();
|
||||
if (jso != null){
|
||||
m_Title = ((JSONString)jso.get("title")).stringValue();
|
||||
String oldSort = m_Sort;
|
||||
m_Sort = ((JSONString)jso.get("sort")).stringValue();
|
||||
if (!oldSort.equals(m_Sort)){
|
||||
if (m_View.getCurrentAlbum() == this)
|
||||
{
|
||||
select();
|
||||
}
|
||||
}
|
||||
m_Label.setText(m_Title);
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh(){
|
||||
m_Container.doJSONRequest(G3Viewer.VIEW_ITEM_URL + getId(),
|
||||
new HttpSuccessHandler() {
|
||||
|
||||
@Override
|
||||
public void success(JSONValue aValue) {
|
||||
updateValues(aValue);
|
||||
}
|
||||
},false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void showPopupMenu(Event event){
|
||||
m_Label.addStyleName("popped");
|
||||
final PopupPanel popupPanel = new PopupPanel(true);
|
||||
popupPanel.setAnimationEnabled(true);
|
||||
MenuBar popupMenuBar = new MenuBar(true);
|
||||
|
||||
MenuItem editItem = new MenuItem("Edit Album", true, new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
m_Container.doDialog("index.php/form/edit/albums/" + m_ID, new HttpDialogHandler() {
|
||||
@Override
|
||||
public void success(String aResult) {
|
||||
refresh();
|
||||
|
||||
}
|
||||
});
|
||||
popupPanel.hide();
|
||||
|
||||
}
|
||||
});
|
||||
MenuItem uploadPhotos = new MenuItem("Upload Photos", true, new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
uploadFiles();
|
||||
popupPanel.hide();
|
||||
|
||||
}
|
||||
});
|
||||
MenuItem addAlbum = new MenuItem("Add Album", true, new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
m_Container.doDialog("index.php/form/add/albums/" + m_ID + "?type=album", new HttpDialogHandler() {
|
||||
@Override
|
||||
public void success(String aResult) {
|
||||
expand();
|
||||
m_View.getCurrentAlbum().select();
|
||||
}
|
||||
});
|
||||
|
||||
popupPanel.hide();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
MenuItem userPermissions = new MenuItem("User Permissions", true, new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
m_Container.doDialog("index.php/permissions/browse/" + m_ID , new HttpDialogHandler() {
|
||||
@Override
|
||||
public void success(String aResult) {
|
||||
}
|
||||
});
|
||||
|
||||
popupPanel.hide();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
popupPanel.setStyleName("popup");
|
||||
editItem.addStyleName("popup-item");
|
||||
addAlbum.addStyleName("popup-item");
|
||||
uploadPhotos.addStyleName("popup-item");
|
||||
userPermissions.addStyleName("popup-item");
|
||||
|
||||
|
||||
popupMenuBar.addItem(uploadPhotos);
|
||||
popupMenuBar.addItem(editItem);
|
||||
popupMenuBar.addItem(addAlbum);
|
||||
popupMenuBar.addItem(userPermissions);
|
||||
|
||||
|
||||
popupMenuBar.setVisible(true);
|
||||
popupPanel.add(popupMenuBar);
|
||||
|
||||
int x = DOM.eventGetClientX(event);
|
||||
int y = DOM.eventGetClientY(event);
|
||||
popupPanel.setPopupPosition(x, y);
|
||||
popupPanel.addCloseHandler(new CloseHandler<PopupPanel>() {
|
||||
|
||||
@Override
|
||||
public void onClose(CloseEvent<PopupPanel> event) {
|
||||
|
||||
m_Label.removeStyleName("popped");
|
||||
}
|
||||
});
|
||||
|
||||
popupPanel.show();
|
||||
}
|
||||
|
||||
private Label initComponents()
|
||||
{
|
||||
Label toReturn = new Label(m_Title);
|
||||
toReturn.addStyleName("Tree-Album");
|
||||
setWidget(toReturn);
|
||||
m_Container.getDragController().registerDropController(m_DropController);
|
||||
expand();
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds the albums in the json response
|
||||
* TreeItem.
|
||||
*/
|
||||
private void addAlbums(JSONValue jsonValue)
|
||||
{
|
||||
JSONArray jsonArray = (JSONArray)jsonValue;
|
||||
Set<Integer> allAlbums = new HashSet<Integer>(m_IDtoAlbum.keySet());
|
||||
for (int i = 0; i < jsonArray.size(); ++i)
|
||||
{
|
||||
JSONObject jso = (JSONObject)jsonArray.get(i);
|
||||
int id = (int)((JSONNumber)jso.get("id")).doubleValue();
|
||||
|
||||
if (m_IDtoAlbum.containsKey(id))
|
||||
{
|
||||
m_IDtoAlbum.get(id).updateValues(jso);
|
||||
}
|
||||
else
|
||||
{
|
||||
Album album = new Album(jso, m_Container);
|
||||
m_IDtoAlbum.put(id, album);
|
||||
addItem(album);
|
||||
}
|
||||
allAlbums.remove(id);
|
||||
}
|
||||
for (Integer id : allAlbums){
|
||||
Album a = m_IDtoAlbum.remove(id);
|
||||
a.cleanup();
|
||||
|
||||
|
||||
removeItem(a);
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanup()
|
||||
{
|
||||
m_Container.getDragController().unregisterDropController(m_DropController);
|
||||
for (int i = 0; i < getChildCount(); i++){
|
||||
((Album) getChild(i)).cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* moves the given array of ids to this album
|
||||
*/
|
||||
public void moveTo(JSONArray a_Ids){
|
||||
Loading.getInstance().loading();
|
||||
|
||||
m_Container.doJSONRequest(G3Viewer.MOVE_TO_ALBUM_URL + getId() + "?sourceids=" + a_Ids.toString(),
|
||||
new HttpSuccessHandler() {
|
||||
|
||||
@Override
|
||||
public void success(JSONValue aValue) {
|
||||
expand();
|
||||
m_View.getCurrentAlbum().expand();
|
||||
m_View.getCurrentAlbum().select();
|
||||
}
|
||||
},true);
|
||||
}
|
||||
|
||||
/**
|
||||
* rearranges the albums
|
||||
*/
|
||||
|
||||
public void rearrangeTo(JSONArray a_Ids, Item m_CompareTo, boolean m_Before){
|
||||
Loading.getInstance().loading();
|
||||
String bora = m_Before?"before":"after";
|
||||
|
||||
m_Container.doJSONRequest(G3Viewer.REARRANGE_URL + m_CompareTo.getID() + "/" + bora
|
||||
+ "?sourceids=" + a_Ids.toString(),
|
||||
new HttpSuccessHandler() {
|
||||
|
||||
@Override
|
||||
public void success(JSONValue aValue) {
|
||||
m_View.getCurrentAlbum().select();
|
||||
}
|
||||
},true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the album with the given id
|
||||
*/
|
||||
public void selectSubAlbum(int a_Id){
|
||||
for (int i = 0; i < getChildCount(); i++)
|
||||
{
|
||||
Album ab = ((Album) getChild(i));
|
||||
if (ab.m_ID == a_Id)
|
||||
{
|
||||
ab.select();
|
||||
m_Container.getTree().ensureSelected(ab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the requested URL.
|
||||
*/
|
||||
public void expand() {
|
||||
|
||||
m_Container.doJSONRequest(G3Viewer.VIEW_ALBUM_URL + getId(),
|
||||
new HttpSuccessHandler() {
|
||||
|
||||
@Override
|
||||
public void success(JSONValue aValue) {
|
||||
addAlbums(aValue);
|
||||
}
|
||||
},false);
|
||||
}
|
||||
|
||||
|
||||
public void select() {
|
||||
Loading.getInstance().loading();
|
||||
m_Container.doJSONRequest(G3Viewer.VIEW_CHILDREN_URL + getId(),
|
||||
new HttpSuccessHandler() {
|
||||
|
||||
@Override
|
||||
public void success(JSONValue aValue) {
|
||||
viewAlbum(aValue);
|
||||
}
|
||||
},false);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* view Album contents
|
||||
*/
|
||||
private void viewAlbum(JSONValue a_Value){
|
||||
|
||||
JSONArray jsonArray = (JSONArray)a_Value;
|
||||
|
||||
Item item = null;
|
||||
int id;
|
||||
JSONObject jso;
|
||||
|
||||
m_Items.clear();
|
||||
|
||||
for (int i = 0; i < jsonArray.size(); ++i)
|
||||
{
|
||||
jso = (JSONObject)jsonArray.get(i);
|
||||
id = (int)((JSONNumber)jso.get("id")).doubleValue();
|
||||
|
||||
if (m_IDtoItem.containsKey(id)){
|
||||
item = m_IDtoItem.get(id);
|
||||
item.updateValues(jso);
|
||||
}
|
||||
else
|
||||
{
|
||||
item =new Item(this, jso, m_Container);
|
||||
m_IDtoItem.put(id, item);
|
||||
|
||||
if (item.isAlbum()){
|
||||
linkAlbum(item);
|
||||
}
|
||||
}
|
||||
m_Items.add(item);
|
||||
|
||||
}
|
||||
|
||||
m_View.setAlbum(this);
|
||||
addPendingDownloads();
|
||||
}
|
||||
|
||||
public List<Item> getItems()
|
||||
{
|
||||
return m_Items;
|
||||
}
|
||||
|
||||
public void linkAlbum(Item a_Item){
|
||||
// link album
|
||||
int id = a_Item.getID();
|
||||
Album child;
|
||||
for (int j = 0 ; j < getChildCount(); j++){
|
||||
child = (Album) getChild(j);
|
||||
if (child.m_ID == id){
|
||||
a_Item.setLinkedAlbum(child);
|
||||
j = getChildCount();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isManualSort(){
|
||||
return m_Sort.equalsIgnoreCase("weight");
|
||||
}
|
||||
|
||||
public void uploadFiles() {
|
||||
Desktop desktop = Factory.getInstance().createDesktop();
|
||||
|
||||
desktop.openFiles(new OpenFilesHandler() {
|
||||
|
||||
public void onOpenFiles(OpenFilesEvent event) {
|
||||
File[] files = event.getFiles();
|
||||
UploadFile uf;
|
||||
for (File file : files){
|
||||
uf = new UploadFile(Album.this, file);
|
||||
m_View.addToView(uf);
|
||||
m_UploadQueue.addLast(uf);
|
||||
}
|
||||
|
||||
if (!m_Running){
|
||||
m_Running = true;
|
||||
next();
|
||||
}
|
||||
|
||||
}
|
||||
}, false);
|
||||
|
||||
}
|
||||
|
||||
public void addPendingDownloads()
|
||||
{
|
||||
for (UploadFile uf: m_UploadQueue)
|
||||
{
|
||||
m_View.addToView(uf);
|
||||
}
|
||||
}
|
||||
|
||||
public void finishedUpload(UploadFile uf, JSONValue a_Return)
|
||||
{
|
||||
m_UploadQueue.remove(uf);
|
||||
next();
|
||||
|
||||
JSONObject jo = a_Return.isObject();
|
||||
|
||||
if (jo != null){
|
||||
Item item = new Item(this,jo,m_Container);
|
||||
m_IDtoItem.put(item.getID(), item);
|
||||
m_Items.add(item);
|
||||
|
||||
if (m_View.getCurrentAlbum() == this){
|
||||
m_View.replaceInView(uf, item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_View.getCurrentAlbum() == this){
|
||||
m_View.removeFromView(uf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void next()
|
||||
{
|
||||
if (m_UploadQueue.size() > 0)
|
||||
{
|
||||
UploadFile uf = m_UploadQueue.getFirst();
|
||||
uf.startUpload();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Running = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.allen_sauer.gwt.dnd.client.DragContext;
|
||||
import com.allen_sauer.gwt.dnd.client.VetoDragException;
|
||||
import com.allen_sauer.gwt.dnd.client.drop.DropController;
|
||||
import com.google.gwt.json.client.JSONArray;
|
||||
import com.google.gwt.json.client.JSONNumber;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class AlbumItemDropContainer implements DropController{
|
||||
/**
|
||||
* the tree
|
||||
*/
|
||||
private final Album m_Album;
|
||||
|
||||
private final Item m_Item;
|
||||
|
||||
public AlbumItemDropContainer(Item a_Item, Album a_Album){
|
||||
m_Album = a_Album;
|
||||
m_Item = a_Item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Widget getDropTarget() {
|
||||
// TODO Auto-generated method stub
|
||||
return m_Item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrop(DragContext context) {
|
||||
JSONArray jsa = new JSONArray();
|
||||
|
||||
int i = 0;
|
||||
for (Widget widget : context.selectedWidgets){
|
||||
if (widget instanceof Item){
|
||||
jsa.set(i, new JSONNumber(((Item)widget).getID()));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
m_Album.moveTo(jsa);
|
||||
// context.
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnter(DragContext context) {
|
||||
m_Item.addStyleName("drop-target");
|
||||
//m_Album.g
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeave(DragContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
m_Item.removeStyleName("drop-target");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(DragContext context) {
|
||||
// m_Album.
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreviewDrop(DragContext context) throws VetoDragException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.event.logical.shared.SelectionEvent;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.Tree;
|
||||
import com.google.gwt.user.client.ui.TreeItem;
|
||||
|
||||
public class AlbumTree extends Tree{
|
||||
|
||||
private final G3Viewer m_Container;
|
||||
|
||||
|
||||
public AlbumTree(G3Viewer a_Container){
|
||||
super();
|
||||
|
||||
sinkEvents(Event.ONMOUSEUP | Event.ONMOUSEDOWN | Event.ONCONTEXTMENU);
|
||||
|
||||
m_Container = a_Container;
|
||||
|
||||
addSelectionHandler(new SelectionHandler<TreeItem>() {
|
||||
|
||||
@Override
|
||||
public void onSelection(SelectionEvent<TreeItem> event) {
|
||||
((Album) event.getSelectedItem()).select();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void fetchTree()
|
||||
{
|
||||
// fetch top album
|
||||
Album tree = new Album(m_Container);
|
||||
addItem(tree);
|
||||
setSelectedItem(tree);
|
||||
}
|
||||
|
||||
public void onBrowserEvent(Event event) {
|
||||
|
||||
|
||||
switch (DOM.eventGetType(event)) {
|
||||
|
||||
case Event.ONMOUSEUP:
|
||||
if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event.ONMOUSEDOWN:
|
||||
if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event.ONCONTEXTMENU:
|
||||
event.preventDefault();
|
||||
|
||||
popupMenu(event);
|
||||
//GWT.log("Event.ONCONTEXTMENU", null);
|
||||
break;
|
||||
|
||||
default:
|
||||
super.onBrowserEvent(event);
|
||||
}//end switch
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
((Album)getSelectedItem()).select();
|
||||
}
|
||||
|
||||
public void ensureSelected(Album album)
|
||||
{
|
||||
setSelectedItem(album);
|
||||
ensureSelectedItemVisible();
|
||||
}
|
||||
|
||||
|
||||
/* do popup
|
||||
*/
|
||||
public void popupMenu(Event event){
|
||||
((Album)getSelectedItem()).showPopupMenu(event);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.allen_sauer.gwt.dnd.client.DragContext;
|
||||
import com.allen_sauer.gwt.dnd.client.VetoDragException;
|
||||
import com.allen_sauer.gwt.dnd.client.drop.DropController;
|
||||
import com.google.gwt.json.client.JSONArray;
|
||||
import com.google.gwt.json.client.JSONNumber;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class AlbumTreeDropController implements DropController{
|
||||
|
||||
/**
|
||||
* the tree
|
||||
*/
|
||||
private final Album m_Album;
|
||||
|
||||
public AlbumTreeDropController(Album a_Album){
|
||||
m_Album = a_Album;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Widget getDropTarget() {
|
||||
// TODO Auto-generated method stub
|
||||
return m_Album.getWidget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrop(DragContext context) {
|
||||
JSONArray jsa = new JSONArray();
|
||||
|
||||
int i = 0;
|
||||
for (Widget widget : context.selectedWidgets){
|
||||
if (widget instanceof Item){
|
||||
jsa.set(i, new JSONNumber(((Item)widget).getID()));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
m_Album.moveTo(jsa);
|
||||
// context.
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnter(DragContext context) {
|
||||
m_Album.getWidget().addStyleName("drop-target");
|
||||
//m_Album.g
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeave(DragContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
m_Album.getWidget().removeStyleName("drop-target");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(DragContext context) {
|
||||
// m_Album.
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreviewDrop(DragContext context) throws VetoDragException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.allen_sauer.gwt.dnd.client.DragContext;
|
||||
import com.allen_sauer.gwt.dnd.client.VetoDragException;
|
||||
import com.allen_sauer.gwt.dnd.client.drop.DropController;
|
||||
import com.google.gwt.json.client.JSONArray;
|
||||
import com.google.gwt.json.client.JSONNumber;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class DropZoneController implements DropController{
|
||||
|
||||
/**
|
||||
* the album
|
||||
*/
|
||||
private final Album m_Album;
|
||||
|
||||
/**
|
||||
* the album
|
||||
*/
|
||||
private final HTML m_DropZone;
|
||||
|
||||
/**
|
||||
* compare to
|
||||
*/
|
||||
private final Item m_CompareTo;
|
||||
|
||||
/**
|
||||
* before
|
||||
*/
|
||||
private final boolean m_Before;
|
||||
|
||||
public DropZoneController(Album a_Album, HTML a_DropZone, Item a_CompareTo, boolean a_Before){
|
||||
m_Album = a_Album;
|
||||
m_DropZone = a_DropZone;
|
||||
m_CompareTo = a_CompareTo;
|
||||
m_Before = a_Before;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Widget getDropTarget() {
|
||||
// TODO Auto-generated method stub
|
||||
return m_DropZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrop(DragContext context) {
|
||||
|
||||
JSONArray jsa = new JSONArray();
|
||||
|
||||
int i = 0;
|
||||
for (Widget widget : context.selectedWidgets){
|
||||
if (widget instanceof Item){
|
||||
jsa.set(i, new JSONNumber(((Item)widget).getID()));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
m_Album.rearrangeTo(jsa, m_CompareTo, m_Before);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnter(DragContext context) {
|
||||
m_DropZone.addStyleName("drop-target");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeave(DragContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
m_DropZone.removeStyleName("drop-target");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(DragContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreviewDrop(DragContext context) throws VetoDragException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,363 @@
|
||||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
|
||||
import com.allen_sauer.gwt.dnd.client.PickupDragController;
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.InputElement;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.http.client.RequestBuilder;
|
||||
import com.google.gwt.http.client.RequestException;
|
||||
import com.google.gwt.json.client.JSONObject;
|
||||
import com.google.gwt.json.client.JSONString;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.DialogBox;
|
||||
import com.google.gwt.user.client.ui.DockPanel;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.SimplePanel;
|
||||
|
||||
/**
|
||||
* Class that acts as a client to a JSON service. Currently, this client just
|
||||
* requests a text which contains a JSON encoding of a search result set from
|
||||
* yahoo. We use a text file to demonstrate how the pieces work without tripping
|
||||
* on cross-site scripting issues.
|
||||
*
|
||||
* If you would like to make this a more dynamic example, you can associate a
|
||||
* servlet with this example and simply have it hit the yahoo service and return
|
||||
* the results.
|
||||
*/
|
||||
public class G3Viewer {
|
||||
|
||||
private static String m_CSRF = null;
|
||||
|
||||
private static class ErrorDialog extends DialogBox
|
||||
{
|
||||
|
||||
public ErrorDialog(String error) {
|
||||
// Set the dialog box's caption.
|
||||
setText("Error");
|
||||
|
||||
DockPanel dp = new DockPanel();
|
||||
dp.addStyleName("error");
|
||||
dp.add(new HTML(error), DockPanel.CENTER);
|
||||
|
||||
|
||||
// DialogBox is a SimplePanel, so you have to set its widget property to
|
||||
// whatever you want its contents to be.
|
||||
Button ok = new Button("OK");
|
||||
ok.addClickHandler(new ClickHandler() {
|
||||
public void onClick(ClickEvent event) {
|
||||
ErrorDialog.this.hide();
|
||||
}
|
||||
});
|
||||
|
||||
dp.add(ok, DockPanel.NORTH);
|
||||
|
||||
setWidget(dp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* BASE url
|
||||
*/
|
||||
private static String BASE_URL =
|
||||
((InputElement)Document.get().getElementById
|
||||
("baseurl")).getValue();
|
||||
|
||||
/*
|
||||
* url to view album
|
||||
*/
|
||||
public static final String VIEW_ALBUM_URL = BASE_URL + "index.php/json_album/albums/";
|
||||
|
||||
/*
|
||||
* url to view album
|
||||
*/
|
||||
public static final String MOVE_TO_ALBUM_URL = BASE_URL + "index.php/json_album/move_to/";
|
||||
|
||||
/*
|
||||
* url to view album
|
||||
*/
|
||||
public static final String VIEW_CHILDREN_URL = BASE_URL + "index.php/json_album/children/";
|
||||
|
||||
/*
|
||||
* Load Item
|
||||
*/
|
||||
public static final String VIEW_ITEM_URL = BASE_URL + "index.php/json_album/item/";
|
||||
|
||||
/**
|
||||
* upload url
|
||||
*/
|
||||
public static final String UPLOAD_URL = BASE_URL + "index.php/json_album/add_photo/";
|
||||
|
||||
/**
|
||||
* upload url
|
||||
*/
|
||||
public static final String REARRANGE_URL = BASE_URL + "index.php/json_album/rearrange/";
|
||||
|
||||
/**
|
||||
* upload url
|
||||
*/
|
||||
public static final String IS_ADMIN_URL = BASE_URL + "index.php/json_album/is_admin/";
|
||||
|
||||
/**
|
||||
* upload url
|
||||
*/
|
||||
public static final String MAKE_ALBUM_COVER_URL = BASE_URL + "index.php/json_album/make_album_cover/";
|
||||
|
||||
/**
|
||||
* rotate url
|
||||
*/
|
||||
public static final String ROTATE_URL = BASE_URL + "index.php/json_album/rotate/";
|
||||
|
||||
/*
|
||||
* tree
|
||||
*/
|
||||
private final AlbumTree m_Tree;
|
||||
|
||||
/**
|
||||
* the only image dialog box
|
||||
*/
|
||||
private final ImageDialogBox m_ImageDialogBox = new ImageDialogBox();
|
||||
|
||||
/**
|
||||
* the only dialog box
|
||||
*/
|
||||
private final HttpDialogBox m_HttpDialogBox= new HttpDialogBox();
|
||||
|
||||
private class SimplePanelEx extends SimplePanel
|
||||
{
|
||||
public SimplePanelEx()
|
||||
{
|
||||
super();
|
||||
sinkEvents(Event.ONMOUSEUP | Event.ONMOUSEDOWN | Event.ONCONTEXTMENU);
|
||||
|
||||
}
|
||||
|
||||
public void onBrowserEvent(Event event) {
|
||||
|
||||
|
||||
switch (DOM.eventGetType(event)) {
|
||||
|
||||
case Event.ONMOUSEUP:
|
||||
if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event.ONMOUSEDOWN:
|
||||
if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event.ONCONTEXTMENU:
|
||||
event.preventDefault();
|
||||
m_Tree.popupMenu(event);
|
||||
//GWT.log("Event.ONCONTEXTMENU", null);
|
||||
break;
|
||||
|
||||
default:
|
||||
super.onBrowserEvent(event);
|
||||
}//end switch
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* central split panel
|
||||
*/
|
||||
private final HorizontalSplitPanel m_SplitPanel = new HorizontalSplitPanel();
|
||||
|
||||
|
||||
/**
|
||||
* Grid View
|
||||
*/
|
||||
private final View m_View = new View(this);
|
||||
|
||||
/**
|
||||
* the drag controller
|
||||
*/
|
||||
private final PickupDragController m_DragController;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
|
||||
public G3Viewer(){
|
||||
m_DragController = new PickupDragController(RootPanel.get(),false);
|
||||
m_DragController.setBehaviorMultipleSelection(true);
|
||||
m_DragController.setBehaviorDragStartSensitivity(5);
|
||||
m_DragController.setBehaviorDragProxy(true);
|
||||
|
||||
m_Tree = new AlbumTree(this);
|
||||
|
||||
checkAdmin();
|
||||
}
|
||||
|
||||
public static String getCSRF()
|
||||
{
|
||||
return m_CSRF;
|
||||
}
|
||||
|
||||
private void checkAdmin(){
|
||||
|
||||
doJSONRequest(IS_ADMIN_URL, new HttpSuccessHandler() {
|
||||
|
||||
@Override
|
||||
public void success(JSONValue aValue) {
|
||||
JSONObject jso = aValue.isObject();
|
||||
if (jso != null){
|
||||
JSONString jss = jso.get("result").isString();
|
||||
if (jss != null){
|
||||
if (jss.stringValue().equals("success"))
|
||||
{
|
||||
|
||||
m_CSRF = (jso.get("csrf").isString()).stringValue();
|
||||
m_Tree.fetchTree();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doDialog("index.php/login/ajax", new HttpDialogHandler() {
|
||||
|
||||
@Override
|
||||
public void success(String aResult) {
|
||||
// recheck admin
|
||||
checkAdmin();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
},false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Entry point for this simple application. Currently, we build the
|
||||
* application's form and wait for events.
|
||||
*/
|
||||
public void onModuleLoad() {
|
||||
initializeMainForm();
|
||||
}
|
||||
|
||||
public static void displayError(String errorType, String errorMessage) {
|
||||
new ErrorDialog(errorType + "\n" + errorMessage).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the drag controller
|
||||
*/
|
||||
public PickupDragController getDragController(){
|
||||
return m_DragController;
|
||||
}
|
||||
|
||||
public AlbumTree getTree(){
|
||||
return m_Tree;
|
||||
}
|
||||
|
||||
public View getView(){
|
||||
return m_View;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void doDialog(String a_Url, HttpDialogHandler a_Handler)
|
||||
{
|
||||
m_HttpDialogBox.doDialog(BASE_URL + a_Url, a_Handler);
|
||||
}
|
||||
|
||||
public void showImage(String a_Url)
|
||||
{
|
||||
m_ImageDialogBox.doDialog( a_Url);
|
||||
}
|
||||
|
||||
public void doJSONRequest(final String a_URL, final HttpSuccessHandler a_Handler, final boolean a_hasParams){
|
||||
try {
|
||||
String url;
|
||||
if (m_CSRF != null)
|
||||
{
|
||||
url = a_URL + (a_hasParams?"&csrf=":"?csrf=") + m_CSRF;
|
||||
}
|
||||
else
|
||||
{
|
||||
url = a_URL;
|
||||
}
|
||||
RequestBuilder requestBuilder = new RequestBuilder(
|
||||
RequestBuilder.GET, url);
|
||||
requestBuilder.setCallback(new JSONResponseTextHandler(
|
||||
new JSONResponseCallback() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONValue aValue) {
|
||||
a_Handler.success(aValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable aThrowable) {
|
||||
displayError("Unexpected Error",
|
||||
aThrowable.toString() + " - " + a_URL);
|
||||
}}
|
||||
));
|
||||
|
||||
requestBuilder.send();
|
||||
} catch (RequestException ex) {
|
||||
displayError("Request Exception", ex.toString() + " - " + a_URL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the main form's layout and content.
|
||||
*/
|
||||
private void initializeMainForm() {
|
||||
|
||||
m_View.addStyleName("view");
|
||||
|
||||
m_Tree.setVisible(true);
|
||||
|
||||
m_SplitPanel.setSplitPosition("20%");
|
||||
|
||||
m_SplitPanel.setLeftWidget(m_Tree);
|
||||
|
||||
m_SplitPanel.setRightWidget(m_View);
|
||||
|
||||
SimplePanel sp = new SimplePanelEx();
|
||||
sp.add(m_SplitPanel);
|
||||
|
||||
RootPanel.get("main").add(sp);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.NodeList;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.http.client.Request;
|
||||
import com.google.gwt.http.client.RequestBuilder;
|
||||
import com.google.gwt.http.client.RequestCallback;
|
||||
import com.google.gwt.http.client.RequestException;
|
||||
import com.google.gwt.http.client.RequestTimeoutException;
|
||||
import com.google.gwt.http.client.Response;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.DialogBox;
|
||||
import com.google.gwt.user.client.ui.DockPanel;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.FormPanel;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
|
||||
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
|
||||
|
||||
public class HttpDialogBox extends DialogBox{
|
||||
|
||||
private FormPanel m_FormPanel = null;
|
||||
|
||||
private HttpDialogHandler m_Callback;
|
||||
|
||||
private final HTML m_Dialog;
|
||||
|
||||
public HttpDialogBox(){
|
||||
m_Dialog = new HTML("Empty");
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void initComponents(){
|
||||
setModal(true);
|
||||
addStyleName("dialog");
|
||||
setAnimationEnabled(true);
|
||||
setText("Dialog");
|
||||
|
||||
Button close = new Button("Cancel", new ClickHandler() {
|
||||
|
||||
public void onClick(ClickEvent event) {
|
||||
HttpDialogBox.this.hide();
|
||||
Loading.getInstance().endLoading();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Button ok = new Button("ok", new ClickHandler() {
|
||||
|
||||
public void onClick(ClickEvent event) {
|
||||
if (m_FormPanel!=null)
|
||||
{
|
||||
m_FormPanel.submit();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
HttpDialogBox.this.hide();
|
||||
Loading.getInstance().loading();
|
||||
}
|
||||
});
|
||||
|
||||
FlowPanel fp = new FlowPanel();
|
||||
fp.add(ok);
|
||||
fp.add(close);
|
||||
fp.addStyleName("dButtons");
|
||||
DockPanel dp = new DockPanel();
|
||||
dp.add(m_Dialog , DockPanel.CENTER);
|
||||
dp.add(fp, DockPanel.SOUTH);
|
||||
dp.addStyleName("dContents");
|
||||
add(dp);
|
||||
|
||||
}
|
||||
|
||||
private class RequestCallbackImpl implements RequestCallback {
|
||||
|
||||
private static final int STATUS_CODE_OK = 200;
|
||||
|
||||
private final String m_URL;
|
||||
|
||||
public RequestCallbackImpl(String a_URL){
|
||||
m_URL = a_URL;
|
||||
}
|
||||
|
||||
public void onError(Request request, Throwable exception) {
|
||||
if (exception instanceof RequestTimeoutException) {
|
||||
// handle a request timeout
|
||||
} else {
|
||||
// handle other request errors
|
||||
}
|
||||
showDialog("Could not get " + m_URL + " Exception thrown " + exception.toString());
|
||||
}
|
||||
|
||||
public void onResponseReceived(Request request, Response response) {
|
||||
if (STATUS_CODE_OK == response.getStatusCode()) {
|
||||
showDialog(response.getText());
|
||||
} else {
|
||||
showDialog(m_URL + response.getText());
|
||||
// handle non-OK response from the server
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showDialog(String a_Text){
|
||||
|
||||
m_Dialog.setHTML(a_Text);
|
||||
|
||||
// hide all submits
|
||||
NodeList<Element> inputs = this.getElement().getElementsByTagName("input");
|
||||
Element input;
|
||||
for (int i = 0; i < inputs.getLength(); i++){
|
||||
input = inputs.getItem(i);
|
||||
|
||||
if (input.getAttribute("type").equals("submit"))
|
||||
{
|
||||
input.setAttribute("style", "display:none");
|
||||
}
|
||||
}
|
||||
|
||||
Loading.getInstance().hideAnimation();
|
||||
show();
|
||||
|
||||
// find forms if it exists
|
||||
NodeList<Element> forms = this.getElement().getElementsByTagName("form");
|
||||
if (forms.getLength() > 0)
|
||||
{
|
||||
Element element = this.getElement().getElementsByTagName("form").getItem(0);
|
||||
setText(element.getElementsByTagName("legend").getItem(0).getInnerText());
|
||||
|
||||
|
||||
m_FormPanel = FormPanel.wrap(element, true);
|
||||
m_FormPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {
|
||||
|
||||
@Override
|
||||
public void onSubmitComplete(SubmitCompleteEvent event) {
|
||||
m_Callback.success(event.getResults());
|
||||
Loading.getInstance().endLoading();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
setText(this.getElement().getElementsByTagName("legend").getItem(0).getInnerText());
|
||||
}
|
||||
|
||||
setPopupPosition(Window.getClientWidth() / 2 - this.getOffsetWidth() / 2,
|
||||
Window.getClientHeight() / 2 - this.getOffsetHeight() / 2);
|
||||
}
|
||||
|
||||
public void doDialog(String url, HttpDialogHandler a_Callback){
|
||||
m_Callback = a_Callback;
|
||||
Loading.getInstance().loading();
|
||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
|
||||
|
||||
try {
|
||||
builder.sendRequest(null, new RequestCallbackImpl(url));
|
||||
} catch (RequestException e) {
|
||||
showDialog("Could not call " + url + " Exception thrown " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
|
||||
public interface HttpDialogHandler {
|
||||
|
||||
public void success(String a_Result);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
|
||||
public interface HttpSuccessHandler {
|
||||
public void success(JSONValue a_Value);
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.ErrorEvent;
|
||||
import com.google.gwt.event.dom.client.ErrorHandler;
|
||||
import com.google.gwt.event.dom.client.LoadEvent;
|
||||
import com.google.gwt.event.dom.client.LoadHandler;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.PopupPanel;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.SimplePanel;
|
||||
|
||||
public class ImageDialogBox extends PopupPanel{
|
||||
|
||||
private Image m_Image = null;
|
||||
|
||||
public ImageDialogBox(){
|
||||
initComponents();
|
||||
}
|
||||
|
||||
|
||||
private void initComponents()
|
||||
{
|
||||
setModal(true);
|
||||
addStyleName("dialog");
|
||||
setAnimationEnabled(true);
|
||||
|
||||
addDomHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
ImageDialogBox.this.hide();
|
||||
|
||||
Loading.getInstance().endLoading();
|
||||
}
|
||||
|
||||
} ,ClickEvent.getType());
|
||||
|
||||
}
|
||||
|
||||
public void doDialog(String a_Image){
|
||||
|
||||
Loading.getInstance().loading();
|
||||
|
||||
if (m_Image != null){
|
||||
m_Image.removeFromParent();
|
||||
}
|
||||
|
||||
m_Image = new Image();
|
||||
final SimplePanel sp = new SimplePanel();
|
||||
m_Image.addLoadHandler(new LoadHandler() {
|
||||
|
||||
@Override
|
||||
public void onLoad(LoadEvent event) {
|
||||
sp.removeFromParent();
|
||||
|
||||
Loading.getInstance().hideAnimation();
|
||||
|
||||
add(m_Image);
|
||||
show();
|
||||
|
||||
setPopupPosition(Window.getClientWidth() / 2 - getOffsetWidth() / 2,
|
||||
Window.getClientHeight() / 2 - getOffsetHeight() / 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
m_Image.addErrorHandler(new ErrorHandler() {
|
||||
|
||||
@Override
|
||||
public void onError(ErrorEvent event) {
|
||||
sp.removeFromParent();
|
||||
G3Viewer.displayError("Error Loading Image", "It could be that the resized version of the image has not been built correctly.");
|
||||
Loading.getInstance().endLoading();
|
||||
}
|
||||
});
|
||||
|
||||
sp.setSize("0px", "0px");
|
||||
sp.setStylePrimaryName("hideme");
|
||||
sp.setWidget(m_Image);
|
||||
RootPanel.get().add(sp);
|
||||
|
||||
m_Image.setUrl(a_Image);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
338
modules/gwtorganise/src/com/gloopics/g3viewer/client/Item.java
Normal file
338
modules/gwtorganise/src/com/gloopics/g3viewer/client/Item.java
Normal file
@ -0,0 +1,338 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.event.dom.client.ContextMenuEvent;
|
||||
import com.google.gwt.event.dom.client.ContextMenuHandler;
|
||||
import com.google.gwt.event.dom.client.DoubleClickEvent;
|
||||
import com.google.gwt.event.dom.client.DoubleClickHandler;
|
||||
import com.google.gwt.event.dom.client.HasAllMouseHandlers;
|
||||
import com.google.gwt.event.dom.client.MouseDownEvent;
|
||||
import com.google.gwt.event.dom.client.MouseDownHandler;
|
||||
import com.google.gwt.event.dom.client.MouseMoveEvent;
|
||||
import com.google.gwt.event.dom.client.MouseMoveHandler;
|
||||
import com.google.gwt.event.dom.client.MouseOutEvent;
|
||||
import com.google.gwt.event.dom.client.MouseOutHandler;
|
||||
import com.google.gwt.event.dom.client.MouseOverEvent;
|
||||
import com.google.gwt.event.dom.client.MouseOverHandler;
|
||||
import com.google.gwt.event.dom.client.MouseUpEvent;
|
||||
import com.google.gwt.event.dom.client.MouseUpHandler;
|
||||
import com.google.gwt.event.dom.client.MouseWheelEvent;
|
||||
import com.google.gwt.event.dom.client.MouseWheelHandler;
|
||||
import com.google.gwt.event.logical.shared.CloseEvent;
|
||||
import com.google.gwt.event.logical.shared.CloseHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.json.client.JSONNumber;
|
||||
import com.google.gwt.json.client.JSONObject;
|
||||
import com.google.gwt.json.client.JSONString;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
import com.google.gwt.user.client.Command;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.MenuBar;
|
||||
import com.google.gwt.user.client.ui.MenuItem;
|
||||
import com.google.gwt.user.client.ui.PopupPanel;
|
||||
|
||||
|
||||
public class Item extends Composite implements HasAllMouseHandlers{
|
||||
|
||||
private final int m_ID;
|
||||
|
||||
private String m_Title;
|
||||
|
||||
private String m_Thumb;
|
||||
|
||||
private String m_Resized;
|
||||
|
||||
private final String m_Type;
|
||||
|
||||
private final Album m_Parent;
|
||||
|
||||
private Album m_LinkedAlbum = null;
|
||||
|
||||
private final G3Viewer m_Container;
|
||||
|
||||
private final boolean m_IsAlbum;
|
||||
|
||||
private final boolean m_IsPhoto;
|
||||
|
||||
private final View m_View;
|
||||
|
||||
private AlbumItemDropContainer m_DropContainer = null;
|
||||
|
||||
private final Image m_ThumbImage;
|
||||
private final Label m_TitleLabel;
|
||||
|
||||
public Item(Album a_Parent, JSONObject a_Value, G3Viewer a_Container){
|
||||
m_Container = a_Container;
|
||||
m_View = a_Container.getView();
|
||||
m_Parent = a_Parent;
|
||||
m_ID = (int)((JSONNumber)a_Value.get("id")).doubleValue();
|
||||
m_Title = ((JSONString)a_Value.get("title")).stringValue();
|
||||
m_Thumb = ((JSONString)a_Value.get("thumb")).stringValue();
|
||||
m_Type = ((JSONString)a_Value.get("type")).stringValue();
|
||||
m_Resized = ((JSONString)a_Value.get("resize")).stringValue();
|
||||
m_IsAlbum = m_Type.equals("album");
|
||||
m_IsPhoto = m_Type.equals("photo");
|
||||
FlowPanel dp = new FlowPanel();
|
||||
|
||||
m_ThumbImage = new Image(m_Thumb);
|
||||
dp.add(m_ThumbImage);
|
||||
|
||||
m_TitleLabel = new Label(m_Title);
|
||||
dp.add(m_TitleLabel);
|
||||
|
||||
initWidget(dp);
|
||||
|
||||
this.setStylePrimaryName("item");
|
||||
this.addStyleName("i" + m_Type);
|
||||
|
||||
addDomHandler(new ContextMenuHandler() {
|
||||
|
||||
@Override
|
||||
public void onContextMenu(ContextMenuEvent event) {
|
||||
showPopupMenu(event);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
}, ContextMenuEvent.getType());
|
||||
|
||||
addDomHandler(new DoubleClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onDoubleClick(DoubleClickEvent event) {
|
||||
if (isAlbum()){
|
||||
m_Parent.selectSubAlbum(m_ID);
|
||||
}
|
||||
else if (isPhoto()){
|
||||
m_Container.showImage(m_Resized);
|
||||
}
|
||||
|
||||
}
|
||||
},DoubleClickEvent.getType());
|
||||
|
||||
a_Container.getDragController().makeDraggable(this);
|
||||
|
||||
}
|
||||
|
||||
public void showing(){
|
||||
if (isAlbum() && m_LinkedAlbum != null){
|
||||
m_DropContainer = new AlbumItemDropContainer(this, m_LinkedAlbum);
|
||||
m_Container.getDragController().registerDropController(
|
||||
m_DropContainer);
|
||||
}
|
||||
}
|
||||
|
||||
public void hidding(){
|
||||
if (m_DropContainer != null){
|
||||
m_Container.getDragController().unregisterDropController(m_DropContainer);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateValues(JSONValue aValue){
|
||||
JSONObject jso = aValue.isObject();
|
||||
|
||||
if (jso != null) {
|
||||
m_Title = ((JSONString)jso.get("title")).stringValue();
|
||||
m_Thumb = ((JSONString)jso.get("thumb")).stringValue();
|
||||
m_Resized = ((JSONString)jso.get("resize")).stringValue();
|
||||
if (m_LinkedAlbum != null){
|
||||
m_LinkedAlbum.updateValues(jso);
|
||||
}
|
||||
|
||||
m_TitleLabel.setText(m_Title);
|
||||
m_ThumbImage.setUrl(m_Thumb);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateImages(JSONValue a_Value){
|
||||
JSONObject jso = a_Value.isObject();
|
||||
|
||||
if (jso != null) {
|
||||
m_Thumb = ((JSONString)jso.get("thumb")).stringValue();
|
||||
m_ThumbImage.setUrl(m_Thumb);
|
||||
m_Resized = ((JSONString)jso.get("resize")).stringValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void refresh(){
|
||||
|
||||
m_Container.doJSONRequest(G3Viewer.VIEW_ITEM_URL + getID(),
|
||||
new HttpSuccessHandler() {
|
||||
|
||||
@Override
|
||||
public void success(JSONValue aValue) {
|
||||
updateValues(aValue);
|
||||
}
|
||||
},false);
|
||||
|
||||
}
|
||||
|
||||
public void setLinkedAlbum(Album a_Album){
|
||||
m_LinkedAlbum = a_Album;
|
||||
}
|
||||
|
||||
public void showPopupMenu(ContextMenuEvent event){
|
||||
this.addStyleName("popped");
|
||||
final PopupPanel popupPanel = new PopupPanel(true);
|
||||
popupPanel.setAnimationEnabled(true);
|
||||
popupPanel.setStyleName("popup");
|
||||
MenuBar popupMenuBar = new MenuBar(true);
|
||||
|
||||
MenuItem deleteItem = new MenuItem("Delete " + m_Type, true, new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
m_Container.doDialog("index.php/quick/form_delete/" + m_ID, new HttpDialogHandler() {
|
||||
public void success(String aResult) {
|
||||
m_View.removeFromView(Item.this);
|
||||
if (m_LinkedAlbum != null){
|
||||
m_LinkedAlbum.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
popupPanel.hide();
|
||||
|
||||
}
|
||||
});
|
||||
deleteItem.addStyleName("popup-item");
|
||||
popupMenuBar.addItem(deleteItem);
|
||||
|
||||
MenuItem editItem = new MenuItem("Edit " + m_Type, true, new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
m_Container.doDialog("index.php/form/edit/" + m_Type + "s/" + m_ID,
|
||||
new HttpDialogHandler() {
|
||||
public void success(String aResult) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
popupPanel.hide();
|
||||
|
||||
}
|
||||
});
|
||||
editItem.addStyleName("popup-item");
|
||||
popupMenuBar.addItem(editItem);
|
||||
|
||||
MenuItem albumCover = new MenuItem("Make Album Cover", true, new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
m_Container.doJSONRequest(G3Viewer.MAKE_ALBUM_COVER_URL + m_ID, new HttpSuccessHandler() {
|
||||
|
||||
public void success(JSONValue aValue) {
|
||||
// nothing to do
|
||||
}
|
||||
},false);
|
||||
popupPanel.hide();
|
||||
}
|
||||
});
|
||||
albumCover.addStyleName("popup-item");
|
||||
popupMenuBar.addItem(albumCover);
|
||||
|
||||
if (isPhoto())
|
||||
{
|
||||
MenuItem rotateCW = new MenuItem("Rotate Clockwise", true, new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
m_ThumbImage.setUrl(Loading.URL);
|
||||
m_Container.doJSONRequest(G3Viewer.ROTATE_URL + m_ID + "/cw", new HttpSuccessHandler() {
|
||||
|
||||
public void success(JSONValue aValue) {
|
||||
updateImages(aValue);
|
||||
}
|
||||
},false);
|
||||
popupPanel.hide();
|
||||
}
|
||||
});
|
||||
rotateCW.addStyleName("popup-item");
|
||||
popupMenuBar.addItem(rotateCW);
|
||||
|
||||
MenuItem rotateCCW = new MenuItem("Rotate Couter-Clockwise", true, new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
m_ThumbImage.setUrl(Loading.URL);
|
||||
m_Container.doJSONRequest(G3Viewer.ROTATE_URL + m_ID + "/ccw", new HttpSuccessHandler() {
|
||||
|
||||
public void success(JSONValue aValue) {
|
||||
updateImages(aValue);
|
||||
}
|
||||
},false);
|
||||
popupPanel.hide();
|
||||
}
|
||||
});
|
||||
rotateCCW.addStyleName("popup-item");
|
||||
popupMenuBar.addItem(rotateCCW);
|
||||
}
|
||||
|
||||
|
||||
|
||||
popupMenuBar.setVisible(true);
|
||||
popupPanel.add(popupMenuBar);
|
||||
|
||||
int x = DOM.eventGetClientX((Event)event.getNativeEvent());
|
||||
int y = DOM.eventGetClientY((Event)event.getNativeEvent());
|
||||
popupPanel.setPopupPosition(x, y);
|
||||
popupPanel.addCloseHandler(new CloseHandler<PopupPanel>() {
|
||||
|
||||
@Override
|
||||
public void onClose(CloseEvent<PopupPanel> event) {
|
||||
|
||||
Item.this.removeStyleName("popped");
|
||||
}
|
||||
});
|
||||
|
||||
popupPanel.show();
|
||||
}
|
||||
|
||||
|
||||
public boolean isAlbum(){
|
||||
return m_IsAlbum;
|
||||
}
|
||||
|
||||
public boolean isPhoto(){
|
||||
return m_IsPhoto;
|
||||
}
|
||||
|
||||
public int getID()
|
||||
{
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
|
||||
return addDomHandler(handler, MouseDownEvent.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
|
||||
return addDomHandler(handler, MouseUpEvent.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
|
||||
return addDomHandler(handler, MouseOutEvent.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
|
||||
return addDomHandler(handler, MouseOverEvent.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
|
||||
return addDomHandler(handler, MouseMoveEvent.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) {
|
||||
return addDomHandler(handler, MouseWheelEvent.getType());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
|
||||
public interface JSONResponseCallback {
|
||||
void onError(Throwable a_Throwable);
|
||||
|
||||
void onResponse(JSONValue a_Value);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.http.client.Request;
|
||||
import com.google.gwt.http.client.RequestCallback;
|
||||
import com.google.gwt.http.client.Response;
|
||||
import com.google.gwt.json.client.JSONException;
|
||||
import com.google.gwt.json.client.JSONParser;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
|
||||
public class JSONResponseTextHandler implements RequestCallback
|
||||
{
|
||||
private final JSONResponseCallback m_Callback;
|
||||
|
||||
public JSONResponseTextHandler(JSONResponseCallback a_Callback){
|
||||
m_Callback = a_Callback;
|
||||
}
|
||||
|
||||
public void onError(Request request, Throwable exception) {
|
||||
m_Callback.onError(exception);
|
||||
}
|
||||
|
||||
public void onResponseReceived(Request request, Response response) {
|
||||
//response.
|
||||
String responseText = response.getText();
|
||||
try {
|
||||
JSONValue jsonValue = JSONParser.parse(responseText);
|
||||
m_Callback.onResponse(jsonValue);
|
||||
} catch (JSONException e) {
|
||||
m_Callback.onError(new Throwable(response.getText(), e));
|
||||
}catch (Exception e) {
|
||||
m_Callback.onError(new Throwable(response.getText() + e.toString(), e));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.AbsolutePanel;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
|
||||
public class Loading extends AbsolutePanel{
|
||||
|
||||
private static final Loading INSTANCE = new Loading();
|
||||
|
||||
public static final String URL = "images/loading.gif";
|
||||
|
||||
/**
|
||||
* the image widget
|
||||
*/
|
||||
private Image m_Image = new Image("images/loading.gif");
|
||||
|
||||
private Loading(){
|
||||
HTML back = new HTML();
|
||||
back.addStyleName("loading");
|
||||
add(back, 0, 0);
|
||||
Image.prefetch(URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* get instance
|
||||
*/
|
||||
public static Loading getInstance(){
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void loading(){
|
||||
int width = RootPanel.get().getOffsetWidth();
|
||||
int height = RootPanel.get().getOffsetHeight();
|
||||
height = height / 2 - 25;
|
||||
width = width / 2 - 25;
|
||||
add(m_Image);
|
||||
this.setWidgetPosition(m_Image, width, height);
|
||||
RootPanel.get().add(this);
|
||||
}
|
||||
|
||||
public void endLoading(){
|
||||
if (m_Image.isAttached()){
|
||||
remove(m_Image);
|
||||
}
|
||||
RootPanel.get().remove(this);
|
||||
}
|
||||
|
||||
public void hideAnimation(){
|
||||
remove(m_Image);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
|
||||
public class NoGears implements EntryPoint {
|
||||
public void onModuleLoad() {
|
||||
RootPanel rootPanel = RootPanel.get("main");
|
||||
rootPanel.add(new HTML(
|
||||
"<font color=\"red\">This application requires Google Gears. To install please visit <a href=\"http://gears.google.com/\">gears.google.com</a> and follow the installation instructions.</font>"));
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import com.google.gwt.user.client.ui.AbsolutePanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.SimplePanel;
|
||||
import com.google.gwt.gears.client.Factory;
|
||||
import com.google.gwt.gears.client.desktop.File;
|
||||
import com.google.gwt.gears.client.httprequest.HttpRequest;
|
||||
import com.google.gwt.gears.client.httprequest.ProgressEvent;
|
||||
import com.google.gwt.gears.client.httprequest.ProgressHandler;
|
||||
import com.google.gwt.gears.client.httprequest.RequestCallback;
|
||||
import com.google.gwt.json.client.JSONParser;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
|
||||
public class UploadFile extends AbsolutePanel{
|
||||
|
||||
private class ProgressBar extends SimplePanel{
|
||||
private final SimplePanel m_ProgressInner;
|
||||
public ProgressBar(){
|
||||
addStyleName("progressBar");
|
||||
m_ProgressInner = new SimplePanel();
|
||||
m_ProgressInner.addStyleName("progessInner");
|
||||
add(m_ProgressInner);
|
||||
}
|
||||
|
||||
public void setProgress(int a_Percent){
|
||||
m_ProgressInner.setWidth( a_Percent + "%");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private final File m_LocalFile;
|
||||
|
||||
private final String m_Name;
|
||||
|
||||
private final Album m_Parent;
|
||||
|
||||
//private final Label m_PendingLabel = new Label("Upload Pending");
|
||||
private final ProgressBar m_ProgressBar = new ProgressBar();
|
||||
|
||||
public UploadFile(Album a_Parent, File a_File){
|
||||
m_Parent = a_Parent;
|
||||
m_LocalFile = a_File;
|
||||
m_Name = a_File.getName();
|
||||
Label name = new Label(m_Name);
|
||||
name.addStyleName("label");
|
||||
add(name,5,20);
|
||||
|
||||
add(m_ProgressBar,0,80);
|
||||
setStylePrimaryName("item");
|
||||
addStyleName("iUpload");
|
||||
|
||||
}
|
||||
|
||||
public void startUpload(){
|
||||
HttpRequest request = Factory.getInstance().createHttpRequest();
|
||||
request.open("POST", G3Viewer.UPLOAD_URL + m_Parent.getId() + "?filename="
|
||||
+ m_Name + "&csrf=" + G3Viewer.getCSRF());
|
||||
//request.setRequestHeader("Content-Type", "image/jpg");
|
||||
//request.setRequestHeader("Content-Type", "image/jpg");
|
||||
|
||||
request.getUpload().setProgressHandler(new ProgressHandler() {
|
||||
|
||||
@Override
|
||||
public void onProgress(ProgressEvent event) {
|
||||
double pcnt = ((double) event.getLoaded() / event.getTotal());
|
||||
m_ProgressBar.setProgress((int) Math.floor(pcnt * 100));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
request.setCallback(new RequestCallback() {
|
||||
|
||||
@Override
|
||||
public void onResponseReceived(HttpRequest request) {
|
||||
|
||||
if (request.getStatus() != 200)
|
||||
{
|
||||
G3Viewer.displayError("Upload Error", request.getResponseText() + request.getStatus() + request.getStatusText());
|
||||
}
|
||||
try{
|
||||
JSONValue jv = JSONParser.parse(request.getResponseText());
|
||||
m_Parent.finishedUpload(UploadFile.this, jv);
|
||||
} catch (Exception e)
|
||||
{
|
||||
G3Viewer.displayError("Exception on Upload", e.toString() + " " + request.getResponseText());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
request.send(m_LocalFile.getBlob());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.gloopics.g3viewer.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class View extends FlowPanel{
|
||||
|
||||
/**
|
||||
* the current album being viewed
|
||||
*/
|
||||
private Album m_Album;
|
||||
|
||||
/**
|
||||
* the list of drop zones
|
||||
*/
|
||||
private final List<DropZoneController> m_DropZones
|
||||
= new ArrayList<DropZoneController>();
|
||||
|
||||
private final G3Viewer m_Container;
|
||||
|
||||
public View(G3Viewer a_Container){
|
||||
m_Container = a_Container;
|
||||
}
|
||||
|
||||
private void clearView(){
|
||||
if (m_DropZones.size() > 0){
|
||||
for (DropZoneController dropController : m_DropZones){
|
||||
m_Container.getDragController().unregisterDropController(dropController);
|
||||
}
|
||||
m_DropZones.clear();
|
||||
}
|
||||
|
||||
for (Widget widget : getChildren()){
|
||||
if (widget instanceof Item){
|
||||
((Item)widget).hidding();
|
||||
}
|
||||
}
|
||||
clear();
|
||||
}
|
||||
|
||||
public void setAlbum(Album a_Album){
|
||||
|
||||
clearView();
|
||||
m_Album = a_Album;
|
||||
Item last = null;
|
||||
for (Item item : a_Album.getItems())
|
||||
{
|
||||
if (a_Album.isManualSort()){
|
||||
addDropZone(a_Album, item, true);
|
||||
}
|
||||
|
||||
addToView(item);
|
||||
|
||||
item.showing();
|
||||
|
||||
last = item;
|
||||
}
|
||||
if (a_Album.isManualSort() && (last != null)){
|
||||
addDropZone(a_Album, last, false);
|
||||
}
|
||||
|
||||
Loading.getInstance().endLoading();
|
||||
|
||||
}
|
||||
|
||||
private void addDropZone(Album a_Parent,Item a_CompareTo, boolean a_Before){
|
||||
HTML drop = new HTML();
|
||||
drop.addStyleName("DropZone");
|
||||
DropZoneController dzp = new DropZoneController(a_Parent, drop, a_CompareTo, a_Before);
|
||||
m_Container.getDragController().registerDropController(dzp);
|
||||
m_DropZones.add(dzp);
|
||||
addToView(drop);
|
||||
}
|
||||
|
||||
public void addToView(Widget a_Widget){
|
||||
add(a_Widget);
|
||||
}
|
||||
|
||||
public void replaceInView(UploadFile a_Remove, Item a_Insert){
|
||||
int index = getWidgetIndex(a_Remove);
|
||||
insert(a_Insert, index);
|
||||
remove(a_Remove);
|
||||
}
|
||||
|
||||
public void removeFromView(Widget a_Widget){
|
||||
remove(a_Widget);
|
||||
}
|
||||
|
||||
public Album getCurrentAlbum(){
|
||||
return m_Album;
|
||||
}
|
||||
|
||||
|
||||
}
|
24
modules/gwtorganise/src/log4j.properties
Normal file
24
modules/gwtorganise/src/log4j.properties
Normal file
@ -0,0 +1,24 @@
|
||||
# A default log4j configuration for log4j users.
|
||||
#
|
||||
# To use this configuration, deploy it into your application's WEB-INF/classes
|
||||
# directory. You are also encouraged to edit it as you like.
|
||||
|
||||
# Configure the console as our one appender
|
||||
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n
|
||||
|
||||
# tighten logging on the DataNucleus Categories
|
||||
log4j.category.DataNucleus.JDO=WARN, A1
|
||||
log4j.category.DataNucleus.Persistence=WARN, A1
|
||||
log4j.category.DataNucleus.Cache=WARN, A1
|
||||
log4j.category.DataNucleus.MetaData=WARN, A1
|
||||
log4j.category.DataNucleus.General=WARN, A1
|
||||
log4j.category.DataNucleus.Utility=WARN, A1
|
||||
log4j.category.DataNucleus.Transaction=WARN, A1
|
||||
log4j.category.DataNucleus.Datastore=WARN, A1
|
||||
log4j.category.DataNucleus.ClassLoading=WARN, A1
|
||||
log4j.category.DataNucleus.Plugin=WARN, A1
|
||||
log4j.category.DataNucleus.ValueGeneration=WARN, A1
|
||||
log4j.category.DataNucleus.Enhancer=WARN, A1
|
||||
log4j.category.DataNucleus.SchemaTool=WARN, A1
|
6
modules/gwtorganise/views/gwtorganise_view.html.php
Normal file
6
modules/gwtorganise/views/gwtorganise_view.html.php
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
<? $base = url::base(false, "http");
|
||||
$url = "$base/modules/gwtorganise/war/index.php?url=$base";
|
||||
?>
|
||||
<iframe src="<?=$url?>" style="width:100%; height:500px; border:8px solid #d2e1f6; margin:0; padding:0;">
|
||||
</iframe>
|
40
modules/gwtorganise/war/G3viewer.css
Normal file
40
modules/gwtorganise/war/G3viewer.css
Normal file
@ -0,0 +1,40 @@
|
||||
* {padding:0; margin:0;}
|
||||
|
||||
#main {position:relative; width:100%; height:100%}
|
||||
|
||||
.error {width:300px; height:200px;}
|
||||
|
||||
.item {width:100px; height: 100px; padding:3px; border: 2px solid #FFF; overflow: hidden; float:left; text-align:center; position:relative;margin:3px;}
|
||||
.item img{max-width:96px; max-height:76px; *width:96px; *height:76px; border:2px solid #AAA;}
|
||||
.item h3{font-size:10px; font-weight:normal; position:absolute; bottom:5px; left:0px; width:100%; text-align:center; padding:0; margin:0;}
|
||||
.ialbum {background-color: #e3effb; border: 2px solid #91c0ef; }
|
||||
.popped {background-color: #e3effb;}
|
||||
.view {padding:3px;}
|
||||
.DropZone {height: 100px; width:6px; margin: 0 -3px 0 -3px; padding: 0; float:left; text-align:center; position:relative;}
|
||||
|
||||
.loading{position:absolute; top:0px; left:0px; width:100%; height: 100%; background-color:#888; opacity: 0.3; filter: alpha(opacity = 30);}
|
||||
|
||||
.gwt-TreeItem-selected .Tree-Album {background-color: #333; color: #FFF;}
|
||||
.Tree-Album {padding: 1px;}
|
||||
.Tree-Album:hover{text-decoration:underline;}
|
||||
.drop-target{background-color: #91c0ef; color: #000;}
|
||||
|
||||
.popup {padding: 2px; border: 1px solid #91c0ef;background-color:#FFF}
|
||||
|
||||
.dialog fieldset{ border: none; padding: 0px; margin: 0px;}
|
||||
.dialog legend{ display: none;}
|
||||
.dialog ul {padding:0; margin:0;}
|
||||
.dialog ul ul li {float:left;}
|
||||
.dialog li {list-style: none; padding:0;margin:0;}
|
||||
.dialog form input[type="password"], .dialog form input[type="text"], .dialog form textarea .dialog form select {border: 1px solid #000; padding: 0.2em; display:block; clear: both;}
|
||||
.dialog form input[type="password"], .dialog form input[type="text"], .dialog form textarea {width: 100%}
|
||||
.dialog form textarea {height: 12em;}
|
||||
|
||||
.label {width:90px; text-align:center;}
|
||||
.progressBar {border: 1px solid #cccccc; width: 100px; height: 10px;}
|
||||
.progessInner {background: #34628c;width: 0px;height: 10px;}
|
||||
|
||||
.dContents {padding: 2px 5px 2px 5px;}
|
||||
.dButtons {text-align: right}
|
||||
|
||||
.hideme {overflow:hidden; width:0; height:0; margin:0; padding:0;}
|
11
modules/gwtorganise/war/WEB-INF/appengine-web.xml
Normal file
11
modules/gwtorganise/war/WEB-INF/appengine-web.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
|
||||
<application></application>
|
||||
<version>1</version>
|
||||
|
||||
<!-- Configure java.util.logging -->
|
||||
<system-properties>
|
||||
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
|
||||
</system-properties>
|
||||
|
||||
</appengine-web-app>
|
28
modules/gwtorganise/war/WEB-INF/logging.properties
Normal file
28
modules/gwtorganise/war/WEB-INF/logging.properties
Normal file
@ -0,0 +1,28 @@
|
||||
# A default java.util.logging configuration.
|
||||
# (All App Engine logging is through java.util.logging by default).
|
||||
#
|
||||
# To use this configuration, copy it into your application's WEB-INF
|
||||
# folder and add the following to your appengine-web.xml:
|
||||
#
|
||||
# <system-properties>
|
||||
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
|
||||
# </system-properties>
|
||||
#
|
||||
|
||||
# Set the default logging level for all loggers to WARNING
|
||||
.level = WARNING
|
||||
|
||||
# Set the default logging level for ORM, specifically, to WARNING
|
||||
DataNucleus.JDO.level=WARNING
|
||||
DataNucleus.Persistence.level=WARNING
|
||||
DataNucleus.Cache.level=WARNING
|
||||
DataNucleus.MetaData.level=WARNING
|
||||
DataNucleus.General.level=WARNING
|
||||
DataNucleus.Utility.level=WARNING
|
||||
DataNucleus.Transaction.level=WARNING
|
||||
DataNucleus.Datastore.level=WARNING
|
||||
DataNucleus.ClassLoading.level=WARNING
|
||||
DataNucleus.Plugin.level=WARNING
|
||||
DataNucleus.ValueGeneration.level=WARNING
|
||||
DataNucleus.Enhancer.level=WARNING
|
||||
DataNucleus.SchemaTool.level=WARNING
|
24
modules/gwtorganise/war/WEB-INF/web.xml
Normal file
24
modules/gwtorganise/war/WEB-INF/web.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE web-app
|
||||
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
|
||||
<web-app>
|
||||
|
||||
<!-- Servlets -->
|
||||
<servlet>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<servlet-class>com.gloopics.g3viewer.server.GreetingServiceImpl</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<url-pattern>/g3viewer/greet</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Default page to serve -->
|
||||
<welcome-file-list>
|
||||
<welcome-file>G3viewer.html</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
</web-app>
|
BIN
modules/gwtorganise/war/images/loading.gif
Normal file
BIN
modules/gwtorganise/war/images/loading.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
3
modules/gwtorganise/war/index.php
Normal file
3
modules/gwtorganise/war/index.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?
|
||||
$url = $_REQUEST['url'];
|
||||
?><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><link type="text/css" rel="stylesheet" href="G3viewer.css"><title>Gallery Administration</title><script type="text/javascript" language="javascript" src="g3viewer/g3viewer.nocache.js"></script></head><body><input type="hidden" id="baseurl" value="<?= $url ?>"/><div id="main"></div></body></html>
|
Reference in New Issue
Block a user