From 72edbfd628983d7f82b6284b4cc1f96dfbc197d7 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 29 Sep 2008 00:14:49 +0000 Subject: [PATCH] various fixes and enhancements for the asset configuration stuff i checked in earlier --- lib/WebGUI/Asset.pm | 9 +- lib/WebGUI/Content/AssetManager.pm | 26 +--- lib/WebGUI/Form/Control.pm | 21 +-- lib/WebGUI/HTMLForm.pm | 3 +- lib/WebGUI/Macro/AdminBar.pm | 230 +---------------------------- lib/WebGUI/TabForm.pm | 8 +- www/extras/accordion/accordion.js | 1 - 7 files changed, 14 insertions(+), 284 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 9b43e6624..97289fc4e 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -791,10 +791,7 @@ sub getEditForm { my $self = shift; my $i18n = WebGUI::International->new($self->session, "Asset"); my $ago = $i18n->get("ago"); - my $rs = $self->session->db->read("select revisionDate from assetData where assetId=? order by revisionDate desc limit 5", [$self->getId]); - my $uiLevelOverride = $self->get("className"); - $uiLevelOverride =~ s/\:\:/_/g; - my $tabform = WebGUI::TabForm->new($self->session,undef,undef,$self->getUrl(),$uiLevelOverride); + my $tabform = WebGUI::TabForm->new($self->session,undef,undef,$self->getUrl()); my $overrides = $self->session->config->get("assets/".$self->get("className")); # Set the appropriate URL @@ -824,8 +821,10 @@ sub getEditForm { }); } else { + # revision history my $ac = $self->getAdminConsole; $ac->addSubmenuItem($self->getUrl("func=manageRevisions"),$i18n->get("revisions").":"); + my $rs = $self->session->db->read("select revisionDate from assetData where assetId=? order by revisionDate desc limit 5", [$self->getId]); while (my ($version) = $rs->array) { my ($interval, $units) = $self->session->datetime->secondsToInterval(time() - $version); $ac->addSubmenuItem($self->getUrl("func=edit;revision=".$version), $interval." ".$units." ".$ago); @@ -2390,7 +2389,7 @@ sub www_add { assetId=>"new", url=>$self->session->form->param("url") ); - $properties{isHidden} = 1 unless (WebGUI::Utility::isIn($class, @{$self->session->config->get("assetContainers")})); + $properties{isHidden} = 1 unless $self->session->config->get("assets/".$class."/isContainer"); my $newAsset = WebGUI::Asset->newByPropertyHashRef($self->session,\%properties); $newAsset->{_parent} = $self; return $newAsset->www_edit(); diff --git a/lib/WebGUI/Content/AssetManager.pm b/lib/WebGUI/Content/AssetManager.pm index c1498c0af..198235469 100644 --- a/lib/WebGUI/Content/AssetManager.pm +++ b/lib/WebGUI/Content/AssetManager.pm @@ -415,7 +415,7 @@ sub www_manage { YAHOO.util.Event.onDOMReady( WebGUI.AssetManager.initManager ); ENDHTML - my $output = '
' . getHeader( $session ); + my $output = WebGUI::Macro::AdminBar::process($session).'
' . getHeader( $session ); ### Crumbtrail my $crumb_markup = '
  • %s >
  • '; @@ -459,30 +459,6 @@ ENDHTML ### Clearing div $output .= q{
     
    }; - ### New Content - $output .= q{
    } . $i18n->get( '1083' ) . ''; - foreach my $link (@{$currentAsset->getAssetAdderLinks("proceed=manageAssets","assetContainers")}) { - $output .= '

    '.$link->{label}.'

    - '.$link->{label}.' '; - $output .= $session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype}); - $output .= '
    '; - } - $output .= '
    '; - foreach my $link (@{$currentAsset->getAssetAdderLinks("proceed=manageAssets")}) { - $output .= '

    '.$link->{label}.'

    - '.$link->{label}.' '; - $output .= $session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype}); - $output .= '
    '; - } - $output .= '
    '; - foreach my $link (@{$currentAsset->getAssetAdderLinks("proceed=manageAssets","utilityAssets")}) { - $output .= '

    '.$link->{label}.'

    - '.$link->{label}.' '; - $output .= $session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype}); - $output .= '
    '; - } - $output .= '
    '; - tie my %options, 'Tie::IxHash'; my $hasClips = 0; foreach my $asset (@{$currentAsset->getAssetsInClipboard(1)}) { diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index edbf896e1..c39c54f50 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -127,12 +127,6 @@ If specified, this will be prepended to the id (whether autogenerated or not) to The UI Level that the user must meet or exceed if this field should be displayed with toHtmlWithWrapper() is called. -=head4 uiLevelOverride - -An identifier that will be grabbed from the config file to determine the uiLevel. If the uiLevelOverride is "Article" and the name is "title" then the entry in the config file would look like: - - Article_uiLevel = title => 5 - =head4 subtext A text string that will be appended after the field when toHtmlWithWrapper() is called. @@ -181,9 +175,6 @@ sub definition { uiLevel=>{ defaultValue=>1 }, - uiLevelOverride=>{ - defaultValue=>undef - }, labelClass=>{ defaultValue=>"formDescription" }, @@ -576,19 +567,11 @@ Renders the form field to HTML as a table row complete with labels, subtext, hov sub passUiLevelCheck { my $self = shift; - my $passUiLevelCheck = 0; - my $override = $self->session->config->get($self->get("uiLevelOverride")."_uiLevel"); - if (defined $override && $override->{$self->get("name")}) { # use override if it exists - $passUiLevelCheck = ($override->{$self->get("name")} <= $self->session->user->profileField("uiLevel")); - } else { # use programmed default - $passUiLevelCheck = ($self->get("uiLevel") <= $self->session->user->profileField("uiLevel")); - } - $passUiLevelCheck = $self->session->user->isAdmin unless ($passUiLevelCheck); # override if in admins group - return $passUiLevelCheck; + my $user = $self->session->user; + return $self->get("uiLevel") <= $user->profileField("uiLevel") || $user->isAdmin; } - #------------------------------------------------------------------- =head2 prepareWrapper ( ) diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 074647fc3..f8acb4af3 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -83,7 +83,6 @@ sub AUTOLOAD { my $self = shift; my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); my %params = @_; - $params{uiLevelOverride} ||= $self->{_uiLevelOverride}; $params{rowClass} ||= $self->{_class}; my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $self->session, %params ]) }; if ($@) { @@ -269,7 +268,7 @@ sub new { $header .= "\n'; $footer = "
    \n" ; $footer .= WebGUI::Form::formFooter($session); - bless {_session=>$session, _tableExtras=>$param{tableExtras}, _uiLevelOverride=>$param{uiLevelOverride}, _header => $header, _footer => $footer, _data => ''}, $class; + bless {_session=>$session, _tableExtras=>$param{tableExtras}, _header => $header, _footer => $footer, _data => ''}, $class; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Macro/AdminBar.pm b/lib/WebGUI/Macro/AdminBar.pm index 955b456c7..49fb7ca4d 100644 --- a/lib/WebGUI/Macro/AdminBar.pm +++ b/lib/WebGUI/Macro/AdminBar.pm @@ -40,11 +40,7 @@ sub process { my ($url, $style, $asset, $user, $config) = $session->quick(qw(url style asset user config)); $style->setScript($url->extras('yui/build/utilities/utilities.js'), {type=>'text/javascript'}); $style->setScript($url->extras('accordion/accordion.js'), {type=>'text/javascript'}); -# $style->setLink($url->extras('accordion/accordion.css'), {type=>'text/css', rel=>'stylesheet'}); - $style->setLink($url->extras('slidePanel/slidePanel.css'), {type=>'text/css', rel=>'stylesheet'}); -# $style->setRawHeadTags(); + $style->setLink($url->extras('macro/AdminBar/slidePanel.css'), {type=>'text/css', rel=>'stylesheet'}); my $out = q{
    }; @@ -181,232 +177,12 @@ sub process { } $out .= q{
    - }; return $out; } -#------------------------------------------------------------------- - -=head2 getAssetAdderLinks ( [addToUrl, type] ) - -Returns an arrayref that contains a label (name of the class of Asset) and url (url link to function to add the class). - -=head3 addToUrl - -Any text to append to the getAssetAdderLinks URL. Usually name/variable pairs to pass in the url. If addToURL is specified, the character ";" and the text in addToUrl is appended to the returned url. - -=head3 type - -A string indicating which type of adders to return. Defaults to "assets". Choose from "assets", "assetContainers", or "utilityAssets". - -=cut - -sub getAssetAdderLinks { - my $self = shift; - my $addToUrl = shift; - my $type = shift || "assets"; - my %links; - my $classesInType = $self->session->config->get($type); - if (ref $classesInType ne "ARRAY") { - $classesInType = []; - } - foreach my $class (@{$classesInType}) { - next unless $class; - my %properties = ( - className=>$class, - dummy=>1 - ); - my $newAsset = WebGUI::Asset->newByPropertyHashRef($self->session,\%properties); - next unless $newAsset; - my $uiLevel = eval{$newAsset->getUiLevel()}; - if ($@) { - $self->session->errorHandler->error("Couldn't get UI level of ".$class.". Root cause: ".$@); - next; - } - next if ($uiLevel > $self->session->user->profileField("uiLevel"));# && !$self->session->user->isAdmin); - my $canAdd = eval{$class->canAdd($self->session)}; - if ($@) { - $self->session->errorHandler->error("Couldn't determine if user can add ".$class." because ".$@); - next; - } - next unless ($canAdd); - my $label = eval{$newAsset->getName()}; - if ($@) { - $self->session->errorHandler->error("Couldn't get the name of ".$class."because ".$@); - next; - } - my $url = $self->getUrl("func=add;class=".$class); - $url = $self->session->url->append($url,$addToUrl) if ($addToUrl); - $links{$label}{url} = $url; - $links{$label}{icon} = $newAsset->getIcon; - $links{$label}{'icon.small'} = $newAsset->getIcon(1); - } - my $constraint; - if ($type eq "assetContainers") { - $constraint = $self->session->db->quoteAndJoin($self->session->config->get("assetContainers")); - } elsif ($type eq "utilityAssets") { - $constraint = $self->session->db->quoteAndJoin($self->session->config->get("utilityAssets")); - } else { - $constraint = $self->session->db->quoteAndJoin($self->session->config->get("assets")); - } - if ($constraint) { - my $sth = $self->session->db->read("select asset.className,asset.assetId,assetData.revisionDate from asset left join assetData on asset.assetId=assetData.assetId where assetData.isPrototype=1 and asset.state='published' and asset.className in ($constraint) and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId) group by assetData.assetId"); - while (my ($class,$id,$date) = $sth->array) { - my $asset = WebGUI::Asset->new($self->session,$id,$class,$date); - next unless ($asset->canView && $asset->canAdd($self->session) && $asset->getUiLevel <= $self->session->user->profileField("uiLevel")); - my $url = $self->getUrl("func=add;class=".$class.";prototype=".$id); - $url = $self->session->url->append($url,$addToUrl) if ($addToUrl); - $links{$asset->getTitle}{url} = $url; - $links{$asset->getTitle}{icon} = $asset->getIcon; - $links{$asset->getTitle}{'icon.small'} = $asset->getIcon(1); - $links{$asset->getTitle}{'isPrototype'} = 1; - $links{$asset->getTitle}{'asset'} = $asset; - } - $sth->finish; - } - my @sortedLinks; - foreach my $label (sort keys %links) { - push(@sortedLinks,{ - label=>$label, - url=>$links{$label}{url}, - icon=>$links{$label}{icon}, - 'icon.small'=>$links{$label}{'icon.small'}, - isPrototype=>$links{$label}{isPrototype}, - asset=>$links{$label}{asset} - }); - } - return \@sortedLinks; -} - - - - -#------------------------------------------------------------------- -sub processOld { - my $session = shift; - return "" unless ($session->var->isAdminOn); - $session->style->setScript($session->url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), {type=>"text/javascript"}); - $session->style->setScript($session->url->extras('yui/build/animation/animation-min.js'), {type=>"text/javascript"}); - my @param = @_; - my $templateId = $param[0] || "PBtmpl0000000000000090"; - my $i18n = WebGUI::International->new($session,'Macro_AdminBar'); - my @adminbar = (); - my $ac = WebGUI::AdminConsole->new($session); - my @adminConsole = (); - foreach my $item (@{$ac->getAdminFunction}) { - push(@adminConsole, { - title=>$item->{title}, - icon=>$item->{'icon.small'}, - url=>$item->{url} - }) if ($item->{canUse}); - } - push(@adminbar, { - label => $i18n->get("admin console","AdminConsole"), - name => "adminConsole", - items => \@adminConsole - }); - if ($session->asset) { - my @clipboard = (); - foreach my $asset (@{$session->asset->getAssetsInClipboard(1)}) { - my $title = $asset->getTitle; - $title =~ s/'//g; # stops it from breaking the javascript menus - push(@clipboard, { - 'title'=>$title, - 'url'=>$session->asset->getUrl("func=paste;assetId=".$asset->getId), - icon=>$asset->getIcon(1), - }); - } - if (scalar(@clipboard)) { - push(@adminbar, { - label => $i18n->get(1082), - name => "clipboard", - items => \@clipboard - }); - } - my @packages = (); - foreach my $package (@{$session->asset->getPackageList}) { - my $title = $package->getTitle; - $title =~ s/'//g; # stops it from breaking the javascript menus - push(@packages,{ - 'url'=>$session->asset->getUrl("func=deployPackage;assetId=".$package->getId), - 'title'=>$title, - icon=>$package->getIcon(1), - }); - } - if ($session->user->profileField("uiLevel") >= 7 && scalar(@packages)) { - push(@adminbar, { - label => $i18n->get(376), - name => "packages", - items => \@packages - }); - } - } - my $working = WebGUI::VersionTag->getWorking($session, 1); - my $workingId = ""; - my @tags = (); - if ($working) { - $workingId = $working->getId; - my $commitUrl = ""; - if ($session->setting->get("skipCommitComments")) { - $session->url->page("op=commitVersionTagConfirm;tagId=".$workingId); - } - else { - $session->url->page("op=commitVersionTag;tagId=".$workingId); - } - push(@tags, { - url=>$session->url->page("op=commitVersionTag;tagId=".$workingId), - title=>$i18n->get("commit my changes"), - icon=>$session->url->extras('adminConsole/small/versionTags.gif') - }); - } - foreach my $tag (@{WebGUI::VersionTag->getOpenTags($session)}) { - next unless $session->user->isInGroup($tag->get("groupToUse")); - push(@tags, { - url=>$session->url->page("op=" . ($tag->getId eq $workingId ? "editVersionTag" : "setWorkingVersionTag") . ";backToSite=1;tagId=".$tag->getId), - title=>($tag->getId eq $workingId) ? '* '.$tag->get("name").'' : $tag->get("name"), - icon=>$session->url->extras('spacer.gif') - }); - } - if (scalar(@tags)) { - push(@adminbar, { - label => $i18n->get("version tags","VersionTag"), - name => "versions", - items => \@tags - }); - } - if ($session->asset) { - my @assets = (); - foreach my $asset (@{$session->asset->getAssetAdderLinks(undef,"assetContainers")}) { - push(@assets, { - title=>$asset->{label}, - icon=>$asset->{'icon.small'}, - url=>$asset->{url} - }); - } - push(@assets, {icon=>$session->url->extras('spacer.gif'),label=>'
    '}); - foreach my $asset (@{$session->asset->getAssetAdderLinks}) { - push(@assets, { - title=>$asset->{label}, - icon=>$asset->{'icon.small'}, - url=>$asset->{url} - }); - } - push(@adminbar, { - label => $i18n->get(1083), - name => "newContent", - items => \@assets - }); - } - return WebGUI::Asset::Template->new($session,$templateId)->process({adminbar_loop=>\@adminbar}); -} - - - - 1; diff --git a/lib/WebGUI/TabForm.pm b/lib/WebGUI/TabForm.pm index 1538eac5b..a0405a18a 100644 --- a/lib/WebGUI/TabForm.pm +++ b/lib/WebGUI/TabForm.pm @@ -96,7 +96,7 @@ sub addTab { my $name = shift; my $label = shift; my $uiLevel = shift || 0; - $self->{_tab}{$name}{form} = WebGUI::HTMLForm->new($self->session,uiLevelOverride=>$self->{_uiLevelOverride}); + $self->{_tab}{$name}{form} = WebGUI::HTMLForm->new($self->session); $self->{_tab}{$name}{label} = $label; $self->{_tab}{$name}{uiLevel} = $uiLevel; return $self->{_tab}{$name}{form}; @@ -198,11 +198,10 @@ sub new { my $startingTabs = shift; my $css = shift || $session->url->extras('tabs/tabs.css'); my $cancelUrl = shift || $session->url->page(); - my $uiLevelOverride = shift; my %tabs; tie %tabs, 'Tie::IxHash'; foreach my $key (keys %{$startingTabs}) { - $tabs{$key}{form} = WebGUI::HTMLForm->new($session,uiLevelOverride=>$uiLevelOverride); + $tabs{$key}{form} = WebGUI::HTMLForm->new($session); $tabs{$key}{label} = $startingTabs->{$key}->{label}; $tabs{$key}{uiLevel} = $startingTabs->{$key}->{uiLevel}; } @@ -211,8 +210,7 @@ sub new { value=>$i18n->get('cancel'), extras=>q|onclick="history.go(-1);" class="backwardButton"| }); - bless { _session=>$session, _uiLevelOverride=>$uiLevelOverride, _cancel=>$cancel, - _submit=>WebGUI::Form::submit($session), + bless { _session=>$session, _cancel=>$cancel, _submit=>WebGUI::Form::submit($session), _form=>WebGUI::Form::formHeader($session), _hidden=>"", _tab=>\%tabs, _css=>$css }, $class; } diff --git a/www/extras/accordion/accordion.js b/www/extras/accordion/accordion.js index 4c9aeeb2c..a15e9790b 100644 --- a/www/extras/accordion/accordion.js +++ b/www/extras/accordion/accordion.js @@ -6,7 +6,6 @@ var AccordionMenu = new function() var oMenuCache = {}; var dLastHoverTitle ; YUD.addClass(document.documentElement,'accordion-menu-js'); - YAHOO.util.Event.on(window, "load", function () { document.body.style.marginLeft = "250px"; }); function getDT(e) {