From 35c220eefdf5f99e459f0a10999de5a7758dcc57 Mon Sep 17 00:00:00 2001 From: Chris Nehren Date: Sat, 12 Jul 2008 02:59:01 +0000 Subject: [PATCH] Alphebetize the widget methods. --- lib/WebGUI/Asset.pm | 350 ++++++++++++++++++++++---------------------- 1 file changed, 176 insertions(+), 174 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index ccfed90fe..3689b246d 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1403,6 +1403,23 @@ sub getUrl { return $url; } +#------------------------------------------------------------------- + +=head2 getContentLastModified + +Returns the overall modification time of the object and its content in Unix +epoch format, for the purpose of the Last-Modified HTTP header. Override this +for subclasses that contain content that is not solely dependent on the +revisionDate of the asset. + +=cut + +sub getContentLastModified { + my $self = shift; + return $self->get("revisionDate"); +} + + #------------------------------------------------------------------- =head2 getValue ( key ) @@ -1454,6 +1471,19 @@ sub indexContent { #------------------------------------------------------------------- +=head2 isValidRssItem ( ) + +Returns true iff this asset should be included in RSS feeds from the +RSS From Parent asset. If false, this asset will be ignored when +generating feeds, even if it appears in the item list. Defaults to +true. + +=cut + +sub isValidRssItem { 1 } + +#------------------------------------------------------------------- + =head2 loadModule ( $session, $className ) Loads an asset module if it's not already in memory. This is a class method. Returns undef on failure to load, otherwise returns the classname. @@ -1732,6 +1762,130 @@ sub newPending { #------------------------------------------------------------------- +=head2 outputWidgetMarkup ( width, height, templateId ) + +Output the markup required for the widget view. Includes markup to handle the +widget macro in the iframe holding the widgetized asset. This does the following: + +=over 4 + +=item * + +retrieves the content for this asset using its L method + +=item * + +processes macros in that content + +=item * + +serializes the processed content in JSON + +=item * + +writes the JSON to a storage location + +=item * + +refers the user to download this JSON + +=item * + +references the appropriate JS files for the templating engine and the widget macro + +=item * + +invokes the templating engine on this JSON + +=back + +=head3 width + +The width of the iframe. Required for making widget-in-widget function properly. + +=head3 height + +The height of the iframe. Required for making widget-in-widget function properly. + +=head3 templateId + +The templateId for this widgetized asset to use. Required for making +widget-in-widget function properly. + +=cut + +sub outputWidgetMarkup { + # get our parameters. + my $self = shift; + my $width = shift; + my $height = shift; + my $templateId = shift; + + # construct / retrieve the values we'll use later. + my $assetId = $self->getId; + my $session = $self->session; + my $conf = $session->config; + my $extras = $conf->get('extrasURL'); + + # the widgetized version of content that has the widget macro in it is + # executing in an iframe. this iframe doesn't have a style object. + # therefore, the macro won't be able to output the stylesheet and JS + # information it needs to do its work. because of this, we need to output + # that content manually. construct the filesystem paths for those files. + my $containerCss = $extras . '/yui/build/container/assets/container.css'; + my $containerJs = $extras . '/yui/build/container/container-min.js'; + my $yahooDomJs = $extras . '/yui/build/yahoo-dom-event/yahoo-dom-event.js'; + my $wgWidgetJs = $extras . '/wgwidget.js'; + my $ttJs = $extras . '/tt.js'; + + # the templating engine requires its source data to be in json format. + # write this out to disk and then serve the URL to the user. in this case, + # we'll be serializing the content of the asset which is being widgetized. + my $storage = WebGUI::Storage->get($session, $assetId); + my $content = $self->view; + WebGUI::Macro::process($session, \$content); + my $jsonContent = to_json( { "asset$assetId" => { content => $content } } ); + $storage->addFileFromScalar("$assetId.js", "data = $jsonContent"); + my $jsonUrl = $storage->getUrl("$assetId.js"); + + # WebGUI.widgetBox.initButton() needs the full URL of the asset being + # widgetized, and also the full URL of the JS file that does most of the + # work. + my $fullUrl = "http://" . $conf->get("sitename")->[0] . $self->getUrl; + my $wgWidgetPath = 'http://' . $conf->get('sitename')->[0] . $extras . '/wgwidget.js'; + + # finally, given all of the above, construct our output. WebGUI outputs + # fully valid XHTML 1.0 Strict, and there's no reason this should be any + # different. + my $output = < + + + + + + + + + + + + + \${asset$assetId.content} + + +OUTPUT + return $output; +} + +#------------------------------------------------------------------- + =head2 prepareView ( ) Executes what is necessary to make the view() method work with content chunking. This includes things like processing template head tags. @@ -1754,6 +1908,28 @@ sub prepareView { #------------------------------------------------------------------- +=head2 prepareWidgetView ( ) + +Prepares the widget view for this asset. Specifically, sets up some JS to +ensure that links selected / forms submitted in the widgetized form of the +asset open in a new window. + +=cut + +sub prepareWidgetView { + my $self = shift; + my $templateId = shift; + my $template = WebGUI::Asset::Template->new($self->session, $templateId); + my $session = $self->session; + my $extras = $session->config->get('extrasURL'); + + $template->prepare; + + $self->{_viewTemplate} = $template; +} + +#------------------------------------------------------------------- + =head2 processPropertiesFromFormPost ( ) Updates current Asset with data from Form. You can feed back errors by returning an @@ -2387,19 +2563,6 @@ sub www_manageAssets { #------------------------------------------------------------------- -=head2 getContentLastModified - -Returns the overall modification time of the object and its content in Unix epoch format, for the purpose of the Last-Modified HTTP header. Override this for subclasses that contain content that is not solely dependent on the revisionDate of the asset. - -=cut - -sub getContentLastModified { - my $self = shift; - return $self->get("revisionDate"); -} - -#------------------------------------------------------------------- - =head2 www_view ( ) Returns the view() method of the asset object if the requestor canView. @@ -2427,19 +2590,6 @@ sub www_view { #------------------------------------------------------------------- -=head2 isValidRssItem ( ) - -Returns true iff this asset should be included in RSS feeds from the -RSS From Parent asset. If false, this asset will be ignored when -generating feeds, even if it appears in the item list. Defaults to -true. - -=cut - -sub isValidRssItem { 1 } - -#------------------------------------------------------------------- - =head2 www_widgetView ( ) Returns the view() method of the asset object suitable for widgetizing. @@ -2466,152 +2616,4 @@ sub www_widgetView { return $self->outputWidgetMarkup($width, $height, $templateId); } -#------------------------------------------------------------------- - -=head2 prepareWidgetView ( ) - -Prepares the widget view for this asset. Specifically, sets up some JS to -ensure that links selected / forms submitted in the widgetized form of the -asset open in a new window. - -=cut - -sub prepareWidgetView { - my $self = shift; - my $templateId = shift; - my $template = WebGUI::Asset::Template->new($self->session, $templateId); - my $session = $self->session; - my $extras = $session->config->get('extrasURL'); - - $template->prepare; - - $self->{_viewTemplate} = $template; -} - - -#------------------------------------------------------------------- - -=head2 outputWidgetMarkup ( width, height, templateId ) - -Output the markup required for the widget view. Includes markup to handle the -widget macro in the iframe holding the widgetized asset. This does the following: - -=over 4 - -=item * - -retrieves the content for this asset using its L method - -=item * - -processes macros in that content - -=item * - -serializes the processed content in JSON - -=item * - -writes the JSON to a storage location - -=item * - -refers the user to download this JSON - -=item * - -references the appropriate JS files for the templating engine and the widget macro - -=item * - -invokes the templating engine on this JSON - -=back - -=head3 width - -The width of the iframe. Required for making widget-in-widget function properly. - -=head3 height - -The height of the iframe. Required for making widget-in-widget function properly. - -=head3 templateId - -The templateId for this widgetized asset to use. Required for making -widget-in-widget function properly. - -=cut - -sub outputWidgetMarkup { - # get our parameters. - my $self = shift; - my $width = shift; - my $height = shift; - my $templateId = shift; - - # construct / retrieve the values we'll use later. - my $assetId = $self->getId; - my $session = $self->session; - my $conf = $session->config; - my $extras = $conf->get('extrasURL'); - - # the widgetized version of content that has the widget macro in it is - # executing in an iframe. this iframe doesn't have a style object. - # therefore, the macro won't be able to output the stylesheet and JS - # information it needs to do its work. because of this, we need to output - # that content manually. construct the filesystem paths for those files. - my $containerCss = $extras . '/yui/build/container/assets/container.css'; - my $containerJs = $extras . '/yui/build/container/container-min.js'; - my $yahooDomJs = $extras . '/yui/build/yahoo-dom-event/yahoo-dom-event.js'; - my $wgWidgetJs = $extras . '/wgwidget.js'; - my $ttJs = $extras . '/tt.js'; - - # the templating engine requires its source data to be in json format. - # write this out to disk and then serve the URL to the user. in this case, - # we'll be serializing the content of the asset which is being widgetized. - my $storage = WebGUI::Storage->get($session, $assetId); - my $content = $self->view; - WebGUI::Macro::process($session, \$content); - my $jsonContent = to_json( { "asset$assetId" => { content => $content } } ); - $storage->addFileFromScalar("$assetId.js", "data = $jsonContent"); - my $jsonUrl = $storage->getUrl("$assetId.js"); - - # WebGUI.widgetBox.initButton() needs the full URL of the asset being - # widgetized, and also the full URL of the JS file that does most of the - # work. - my $fullUrl = "http://" . $conf->get("sitename")->[0] . $self->getUrl; - my $wgWidgetPath = 'http://' . $conf->get('sitename')->[0] . $extras . '/wgwidget.js'; - - # finally, given all of the above, construct our output. WebGUI outputs - # fully valid XHTML 1.0 Strict, and there's no reason this should be any - # different. - my $output = < - - - - - - - - - - - - - \${asset$assetId.content} - - -OUTPUT - return $output; -} - 1; -