use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
-our $VERSION = "1.050";
+our $VERSION = "1.051";
=head1 NAME
my @metafields = $file->metafields($self->cfg);
$req->set_variable(file => $file);
+ $req->set_variable(fields => { BSE::TB::ArticleFile->fields });
my $it = BSE::Util::Iterate->new;
my $current_meta;
use base qw(Squirrel::Row BSE::MetaOwnerBase);
use Carp 'confess';
-our $VERSION = "1.012";
+our $VERSION = "1.013";
sub columns {
return qw/id articleId displayName filename sizeInBytes description
);
}
+sub fields {
+ my ($self, $cfg) = @_;
+
+ $cfg ||= BSE::Cfg->single;
+
+ return
+ (
+ file =>
+ {
+ htmltype => "file",
+ description => "File",
+ },
+ description =>
+ {
+ description => "Description",
+ rules => "dh_one_line",
+ },
+ name =>
+ {
+ description => "Identifier",
+ htmltype => "text",
+ width => 20,
+ },
+ contentType =>
+ {
+ description => "Content-Type",
+ htmltype => "text",
+ width => 20,
+ },
+ notes =>
+ {
+ description => "Notes",
+ htmltype => "textarea",
+ },
+ forSale =>
+ {
+ description => "Require payment",
+ htmltype => "checkbox",
+ },
+ download =>
+ {
+ description => "Treat as download",
+ htmltype => "checkbox",
+ },
+ requireUser =>
+ {
+ description => "Require login",
+ htmltype => "checkbox",
+ },
+ hide_from_list =>
+ {
+ description => "Hide from list",
+ htmltype => "checkbox",
+ },
+ storage =>
+ {
+ description => "Storage",
+ htmltype => "select",
+ select =>
+ {
+ id => "id",
+ label => "label",
+ values =>
+ [
+ { id => "", label => "(Auto)" },
+ (
+ map
+ +{ id => $_->name, label => $_->description },
+ BSE::TB::ArticleFiles->file_manager($cfg)->all_stores
+ ),
+ ],
+ },
+ },
+ );
+}
+
sub full_filename {
my ($self, $cfg) = @_;
<input type="hidden" name="_t" value="file" />
<input type="hidden" name="save_file_flags" value="1" />
<:csrfp admin_save_file hidden:>
- <table class="editform editformsmall" id="filelist">
- <tr>
- <th align="left">Replacement file:</th>
- <td>
- <:efile displayName:><:ifEfile file_exists:><:or:><br /><span class="alert">This file is missing!</span><:eif:><br /><input type="file" name="file" size="40" /><br />Choose a file to replace the current file or leave blank to keep the current file.
- </td>
- <td class="help"><:help file file:> <:error_img file:></td>
- </tr>
- <tr>
- <th align="left">Description:</th>
- <td>
- <input type="text" name="description" value="<:old description efile description:>" size="60"/>
- </td>
- <td class="help"><:help file description:> <:error_img description:></td>
- </tr>
- <tr>
- <th align="left">Notes:</th>
- <td>
- <textarea name="notes" rows="10" cols="60"><:old notes efile notes:></textarea>
- </td>
- <td class="help"><:help file notes:> <:error_img notes:></td>
- </tr>
- <tr>
- <th align="left">Content-Type:</th>
- <td>
- <input type="text" name="contentType" value="<:old contentType efile contentType:>" size="40" />
- </td>
- <td class="help"><:help file content_type:> <:error_img contentType:></td>
- </tr>
- <tr>
- <th align="left">Identifier:</th>
- <td>
- <input type="text" name="name" value="<:old name efile name:>" /> </td>
- <td class="help"><:help file name:> <:error_img name:></td>
- </tr>
- <tr>
- <th align="left">Treat as download:</th>
- <td>
- <input type="checkbox" name="download" value="1" <:ifOldChecked download:>checked="checked"<:or:><:eif:> />
- </td>
- <td class="help"><:help file download:> <:error_img download:></td>
- </tr>
- <tr>
- <th align="left">Require payment:</th>
- <td>
- <input type="checkbox" name="forSale" value="1" <:ifOldChecked forSale:>checked="checked"<:or:><:eif:> />
- </td>
- <td class="help"><:help file forSale:> <:error_img forSale:></td>
- </tr>
- <tr>
- <th align="left">Require login:</th>
- <td>
- <input type="checkbox" name="requireUser" value="1" <:ifOldChecked requireUser:>checked="checked"<:or:><:eif:>/>
- </td>
- <td class="help"><:help file requireUser:> <:error_img requireUser:></td>
- </tr>
- <tr>
- <th align="left">Hide from list:</th>
- <td>
- <input type="checkbox" name="hide_from_list" value="1" <:ifOldChecked hide_from_list:>checked="checked"<:or:><:eif:>/>
- </td>
- <td class="help"><:help file hide_from_list:> <:error_img hide_from_list:></td>
- </tr>
- <tr>
- <th align="left">Storage:</th>
- <td>
-<select name="storage">
-<option value="">(Auto)</option>
-<:iterator begin file_stores:>
-<option value="<:file_store name:>" <:ifEq [efile storage] [file_store name]:>selected="selected"<:or:><:eif:>><:file_store description:></option>
-<:iterator end file_stores:>
-</select>
- </td>
- <td class="help"><:help file hide_from_list:> <:error_img hide_from_list:></td>
- </tr>
-<tr><td colspan="3">
+<:.set object = file -:>
+<fieldset>
+ <legend>File Details</legend>
+<:.call "field", name:"file",
+ options: {
+ default: file.displayName,
+ note: "Choose a file to replace the current file or leave blank to keep the current file."
+ } :>
+<:.call "field", name:"description" :>
+<:.call "field", name:"notes" :>
+<:.call "field", name:"contentType" :>
+<:.call "field", name:"name" :>
+<:.call "field", name:"download" :>
+<:.call "field", name:"forSale" :>
+<:.call "field", name:"requireUser" :>
+<:.call "field", name:"hide_from_list" :>
+<:.call "field", name:"storage" :>
+</fieldset>
<:.set metas = [ file.metafields ] :>
<:.if metas.size :>
<fieldset>
<: .call "inlinefield", name: name, field: m.field, delete: 1, object: tmpobj :>
<: .end if :>
<: .end for :>
-</td></tr>
- <tr>
- <td colspan="3" align="right">
+</fieldset>
+ <p class="buttons">
<input type="submit" name="a_save_file" value="Save File" />
- </td>
- </tr>
- </table>
+ </p>
</form>
<:.call "error_img_n", index:0 -:>
<:.end define -:>
-<:.define input -:>
+<:.define input; options: {} -:>
<:# parameters:
name - field name
field - entry from fields
object - source for defaults in edit mode
-:>
-<: .if object -:>
-<: .set default = object.$name -:>
-<: .elsif field.default -:>
-<: .set default = field.default -:>
-<: .else -:>
-<: .set default = "" -:>
+<: .set default = options.default -:>
+<: .if !default.defined -:>
+<: .if object -:>
+<: .set default = object.$name -:>
+<: .elsif field.default -:>
+<: .set default = field.default -:>
+<: .else -:>
+<: .set default = "" -:>
+<: .end if -:>
<: .end if -:>
<: .if field.type and field.type eq "date" and default ne "" -:>
<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
<: .set default = cgi.param(name) -:>
<: .end if -:>
<: .if field.htmltype eq "textarea" -:>
-<textarea id="<:= name | html :>" name="<:= name | html :>" rows="<:= field.height ? field.height : cfg.entry("forms", "textarea_rows", 10) :>" cols=<:= field.width ? field.width : cfg.entry("textarea_cols", 60) | html :>>
+<textarea id="<:= name | html :>" name="<:= name | html :>" rows="<:= field.height ? field.height : cfg.entry("forms", "textarea_rows", 10) :>" cols=<:= field.width ? field.width : cfg.entry("forms", "textarea_cols", 60) | html :>>
<:-= default | html -:>
</textarea>
<: .elsif field.htmltype eq "checkbox" -:>
<: .end if -:>
<:.end define -:>
-<:.define field -:>
+<:.define field; options: {} -:>
<:# parameters:
name - field name
fields - hash of fields (may be set by page instead)
+ object - object containing defaults (can be set globally instead)
+ default - a default value not dependent on object (overrides object)
:>
<:.if fields.is_hash -:>
<:.set f = fields[name] -:>
<:.if f -:>
- <:.call "inlinefield", field:f, name:name -:>
+ <:.call "inlinefield", field:f, name:name, options: options -:>
<:.else -:>
<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
<:.end if -:>
<:.end if -:>
<:.end define -:>
-<:.define inlinefield; object: 0 -:>
+<:.define inlinefield; options: {} -:>
<:# parameters:
name - the field name
field - a field, as an entry in fields
<label for="<:= name | html :>"><:= field.nolabel ? "" : field.description | html :>:</label>
<span>
<:-.if field.readonly -:>
-<:-.call "display", name:name -:>
+<:-.call "display", name:name, options: options -:>
<:.else -:>
-<:-.call "input", name:name -:><:.call "error_img", field:name :>
+<:-.call "input", name:name, options: options -:><:.call "error_img", field:name :>
<:-.end if -:>
<:-.if field.units -:>
<:-= field.units | html -:>
<:-.end if -:>
+ <:-.if options.note -:>
+<br /><:= options.note | raw :>
+ <:-.end if -:>
</span>
</div>
<:.end if -:>