Added the wobject superclass and the first wobject "Item".
This commit is contained in:
parent
98960353c4
commit
842a0eb9db
11 changed files with 585 additions and 222 deletions
148
lib/WebGUI/Wobject/Item.pm
Normal file
148
lib/WebGUI/Wobject/Item.pm
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
package WebGUI::Wobject::Item;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2002 Plain Black Software.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::Attachment;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Wobject;
|
||||
|
||||
our @ISA = qw(WebGUI::Wobject);
|
||||
our $namespace = "Item";
|
||||
our $name = WebGUI::International::get(4,$namespace);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my ($w, $f);
|
||||
$w = $_[0]->SUPER::duplicate($_[1]);
|
||||
$w = WebGUI::Wobject::Item->new({wobjectId=>$w,namespace=>$namespace});
|
||||
$w->set({
|
||||
linkURL=>$_[0]->get("linkURL"),
|
||||
attachment=>$_[0]->get("attachment"),
|
||||
});
|
||||
$f = WebGUI::Attachment->new($_[0]->get("attachment"),$_[0]->get("wobjectId"));
|
||||
$f->copy($w->get("wobjectId"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub new {
|
||||
my ($self, $class, $property);
|
||||
$class = shift;
|
||||
$property = shift;
|
||||
$self = WebGUI::Wobject->new($property);
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub set {
|
||||
my ($key, $sql, @update, $i);
|
||||
$_[0]->SUPER::set($_[1]);
|
||||
foreach $key (keys %{$_[1]}) {
|
||||
if (isIn($key, qw(linkURL attachment))) {
|
||||
$update[$i] .= " ".$key."=".quote($_[1]->{$key});
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
WebGUI::SQL->write("update Item set".join(",",@update)." where wobjectId=".$_[0]->get("wobjectId")) if (@update);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copy {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$_[0]->duplicate;
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteAttachment {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$_[0]->set({attachment=>''});
|
||||
return $_[0]->www_edit();
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my ($output, $f);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = helpIcon(1,$_[0]->get("namespace"));
|
||||
$output .= '<h1>'.WebGUI::International::get(4,$namespace).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->url("linkURL",WebGUI::International::get(1,$_[0]->get("namespace")),$_[0]->get("linkURL"));
|
||||
if ($_[0]->get("attachment") eq "") {
|
||||
$f->file("attachment",WebGUI::International::get(2,$_[0]->get("namespace")))
|
||||
} else {
|
||||
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteAttachment&wid='.$session{form}{wid}).'">'
|
||||
.WebGUI::International::get(3,$namespace).'</a>',WebGUI::International::get(2,$_[0]->get("namespace")))
|
||||
}
|
||||
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
my ($attachment);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$_[0]->SUPER::www_editSave();
|
||||
$attachment = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
|
||||
$attachment->save("attachment");
|
||||
$_[0]->set({
|
||||
linkURL=>$session{form}{linkURL},
|
||||
attachment=>$attachment->getFilename
|
||||
});
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my (@test, $output, $file);
|
||||
if ($_[0]->get("displayTitle")) {
|
||||
$output = '<span class="itemTitle">'.$_[0]->get("title").'</span>';
|
||||
if ($_[0]->get("linkURL")) {
|
||||
$output = '<a href="'.$_[0]->get("linkURL").'">'.$output.'</span></a>';
|
||||
}
|
||||
}
|
||||
if ($_[0]->get("attachment") ne "") {
|
||||
$file = WebGUI::Attachment->new($_[0]->get("attachment"),$_[0]->get("wobjectId"));
|
||||
if ($_[0]->get("displayTitle")) {
|
||||
$output .= ' - ';
|
||||
}
|
||||
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getIcon.'" border=0 alt="'.
|
||||
$_[0]->get("attachment").'" width=16 height=16 border=0 align="middle"></a>';
|
||||
}
|
||||
if ($_[0]->get("description") ne "") {
|
||||
$output .= ' - '.$_[0]->get("description");
|
||||
}
|
||||
return $_[0]->processMacros($output);
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue