Collateral handling code.
This commit is contained in:
parent
08ea05486e
commit
c92c386747
1 changed files with 119 additions and 60 deletions
|
|
@ -1,80 +1,38 @@
|
|||
package FilePump::Bundle;
|
||||
package WebGUI::FilePump::Bundle;
|
||||
|
||||
use base qw/WebGUI::Crud/;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Utility;
|
||||
use URI;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addCssFile ( $uri )
|
||||
=head2 addFile ( $type, $uri )
|
||||
|
||||
Adds a CSS file to the bundle. Returns 1 if the add was successful.
|
||||
Adds a file of the requested type to the bundle. Returns 1 if the add was successful.
|
||||
Otherwise, returns 0 and an error message as to why it was not successful.
|
||||
|
||||
=head3 $type
|
||||
|
||||
If $type is JS, it adds it to the javascript part of the bundle. If it is
|
||||
CSS, it adds it to the CSS part of the bundle. OTHER is used for all other
|
||||
types of files.
|
||||
|
||||
=head3 $uri
|
||||
|
||||
A URI to the new file to add.
|
||||
|
||||
=cut
|
||||
|
||||
sub addCssFile {
|
||||
my ($self, $uri) = @_;
|
||||
sub addFile {
|
||||
my ($self, $type, $uri) = @_;
|
||||
return 0, 'No URI' unless $uri;
|
||||
return 0, 'Illegal type' unless WebGUI::Utility::isIn($type, 'JS', 'CSS', 'OTHER');
|
||||
my $collateralType = $type eq 'JS' ? 'jsFiles'
|
||||
: $type eq 'CSS' ? 'cssFiles'
|
||||
: 'OTHER';
|
||||
$self->setCollateral(
|
||||
'cssFiles',
|
||||
'fileId',
|
||||
'new',
|
||||
{
|
||||
uri => $uri,
|
||||
lastModified => 0,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addJsFile ( $uri )
|
||||
|
||||
Adds a javascript file to the bundle. Returns 1 if the add was successful.
|
||||
Otherwise, returns 0 and an error message as to why it was not successful.
|
||||
|
||||
=head3 $uri
|
||||
|
||||
A URI to the new file to add.
|
||||
|
||||
=cut
|
||||
|
||||
sub addJsFile {
|
||||
my ($self, $uri) = @_;
|
||||
return 0, 'No URI' unless $uri;
|
||||
$self->setCollateral(
|
||||
'jsFiles',
|
||||
'fileId',
|
||||
'new',
|
||||
{
|
||||
uri => $uri,
|
||||
lastModified => 0,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addOtherFile ( $uri )
|
||||
|
||||
Adds an Other file to the bundle. Returns 1 if the add was successful.
|
||||
Otherwise, returns 0 and an error message as to why it was not successful.
|
||||
|
||||
=head3 $uri
|
||||
|
||||
A URI to the new file to add.
|
||||
|
||||
=cut
|
||||
|
||||
sub addOtherFile {
|
||||
my ($self, $uri) = @_;
|
||||
return 0, 'No URI' unless $uri;
|
||||
$self->setCollateral(
|
||||
'otherFiles',
|
||||
$collateralType,
|
||||
'fileId',
|
||||
'new',
|
||||
{
|
||||
|
|
@ -82,6 +40,7 @@ sub addOtherFile {
|
|||
lastModified => 0,
|
||||
},
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -150,6 +109,7 @@ sub crud_definition {
|
|||
defaultValue => 0,
|
||||
serialize => 1,
|
||||
};
|
||||
return $definition;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -187,6 +147,39 @@ sub deleteCollateral {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 deleteFile ( $type, $fileId )
|
||||
|
||||
Deletes a file of the requested type from the bundle.
|
||||
|
||||
=head3 $type
|
||||
|
||||
If $type is JS, it deletes it from the javascript part of the bundle. If it is
|
||||
CSS, it deletes it from the CSS part of the bundle. OTHER is used for all other
|
||||
types of files.
|
||||
|
||||
=head3 $fileId
|
||||
|
||||
The unique collateral GUID to delete from the bundle.
|
||||
|
||||
=cut
|
||||
|
||||
sub deleteFile {
|
||||
my ($self, $type, $fileId) = @_;
|
||||
return 0, 'No fileId' unless $fileId;
|
||||
return 0, 'Illegal type' unless WebGUI::Utility::isIn($type, 'JS', 'CSS', 'OTHER');
|
||||
my $collateralType = $type eq 'JS' ? 'jsFiles'
|
||||
: $type eq 'CSS' ? 'cssFiles'
|
||||
: 'OTHER';
|
||||
$self->deleteCollateral(
|
||||
$collateralType,
|
||||
'fileId',
|
||||
$fileId,
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getAllCollateral ( tableName )
|
||||
|
||||
Returns an array reference to the translated JSON data for the
|
||||
|
|
@ -365,6 +358,72 @@ sub moveCollateralUp {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 moveFileDown ( $type, $fileId )
|
||||
|
||||
Moves the requested file down in the ordered collateral.
|
||||
|
||||
=head3 $type
|
||||
|
||||
If $type is JS, it moves a file in the javascript part of the bundle. If it is
|
||||
CSS, it moves a file in the CSS part of the bundle. OTHER is used for all other
|
||||
types of files.
|
||||
|
||||
=head3 $fileId
|
||||
|
||||
The unique collateral GUID to move in the bundle.
|
||||
|
||||
=cut
|
||||
|
||||
sub moveFileDown {
|
||||
my ($self, $type, $fileId) = @_;
|
||||
return 0, 'No fileId' unless $fileId;
|
||||
return 0, 'Illegal type' unless WebGUI::Utility::isIn($type, 'JS', 'CSS', 'OTHER');
|
||||
my $collateralType = $type eq 'JS' ? 'jsFiles'
|
||||
: $type eq 'CSS' ? 'cssFiles'
|
||||
: 'OTHER';
|
||||
$self->moveCollateralDown(
|
||||
$collateralType,
|
||||
'fileId',
|
||||
$fileId,
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 moveFileUp ( $type, $fileId )
|
||||
|
||||
Moves the requested file up in the ordered collateral.
|
||||
|
||||
=head3 $type
|
||||
|
||||
If $type is JS, it moves a file in the javascript part of the bundle. If it is
|
||||
CSS, it moves a file in the CSS part of the bundle. OTHER is used for all other
|
||||
types of files.
|
||||
|
||||
=head3 $fileId
|
||||
|
||||
The unique collateral GUID to move in the bundle.
|
||||
|
||||
=cut
|
||||
|
||||
sub moveFileUp {
|
||||
my ($self, $type, $fileId) = @_;
|
||||
return 0, 'No fileId' unless $fileId;
|
||||
return 0, 'Illegal type' unless WebGUI::Utility::isIn($type, 'JS', 'CSS', 'OTHER');
|
||||
my $collateralType = $type eq 'JS' ? 'jsFiles'
|
||||
: $type eq 'CSS' ? 'cssFiles'
|
||||
: 'OTHER';
|
||||
$self->moveCollateralUp(
|
||||
$collateralType,
|
||||
'fileId',
|
||||
$fileId,
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 reorderCollateral ( tableName,keyName [,setName,setValue] )
|
||||
|
||||
Resequences collateral data. Typically useful after deleting a collateral item to remove the gap created by the deletion.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue