%#============================================================================
%# ePortal - WEB Based daily organizer
%# Author - S.Rusakov <rusakov_sa@users.sourceforge.net>
%#
%# Copyright (c) 2000-2004 Sergey Rusakov. All rights reserved.
%# This program is open source software
%#
%#
%#----------------------------------------------------------------------------
<&| /dialog.mc:edit_dialog,
title => pick_lang(rus => "Ðåñóðñ êàòàëîãà", eng => "Catalogue resource"),
width => 550,
obj => $obj,
multipart => 1,
focus => 'title' &>
<& /dialog.mc:read_only, id => 'recordtype' &>
<&| /dialog.mc:cell &><hr></&>
<& /dialog.mc:field, id => 'parent_id' &>
<& /dialog.mc:field, id => 'title' &>
%# <& /dialog.mc:buttons, ok_label => pick_lang(rus => "Ñîõðàíèòü ðåñóðñ", eng => "Save the resource"),
%# apply_button => 1 &>
%#
%# LINK ============================================================
%#
% if ($obj->recordtype eq 'link') {
<& /dialog.mc:field, id => 'url' &>
% }
%#
%# Text of resource ============================================================
%#
% if ($obj->recordtype eq 'file') {
<&| /dialog.mc:cell, -align => 'center' &>
<span class="dlglabel"><% pick_lang(rus => "Òåêñò ðåñóðñà", eng => "Text of resource") %></span>
<br>
<& /dialog.mc:textarea, id => 'text', -class => 's10' &>
</&>
<& /dialog.mc:field, id => 'texttype' &>
% }
%#
%# Composite resource ======================================================
%#
% if ($obj->recordtype eq 'composite') {
<&| /dialog.mc:collapse, collapse => 0,
title => pick_lang(rus => "Êàòåãîðèè ðåñóðñà", eng => "Resource categories") &>
<& /dialog.mc:field, id => 'catname_date' &>
<& /dialog.mc:field, id => 'catname_1' &>
<&| /dialog.mc:cell, -class => 'memo' &>
<&| /rus.mc &>
×òîáû èñïîëüçîâàòü êàêóþ-ëèáî êàòåãîðèþ íåîáõîäèìî äàòü åé èìÿ.
Ãðóïïèðîâêà ïî äàòå ÿâëÿåòñÿ îáÿçàòåëüíîé.
</&>
<&| /eng.mc &>
Name a category to before use it. Unnamed categories are unused.
Groupping by date is required.
</&>
</&>
</&>
% }
%#
%# OTHER ============================================================
%#
<&| /dialog.mc:collapse, title => pick_lang(rus => "Äîïîëíèòåëüíûå ñâîéñòâà", eng => "More info") &>
<& /dialog.mc:field, id => 'nickname' &>
<& /dialog.mc:field, id => 'priority' &>
<& /dialog.mc:field, id => 'hidden' &>
<& /dialog.mc:field, id => 'show_files', -label => pick_lang({rus => 'Ïîêàçûâàòü ïðèêðåïëåííûå ôàéëû', eng => 'Show attached files'}) &>
<& /dialog.mc:field, id => 'show_info', -label => pick_lang({rus => 'Ïîêàçûâàòü îáù.èíôîðìàöèþ', eng => 'Show common info'}) &>
<&| /dialog.mc:cell, -align=>'center' &>
<b><% pick_lang({rus => "Êðàòêîå îïèñàíèå", eng => "Short description"}) %>:</b><br>
<& /dialog.mc:textarea, id => 'memo' &>
</&>
</&>
%#
%# New Attachment ============================================================
%#
% if ($obj->recordtype eq 'file') {
<&| /dialog.mc:collapse, title => pick_lang(rus => "Ïðèñîåäèíåííûå ôàéëû", eng => "Files attached") &>
<&| /dialog.mc:cell &><hr></&>
<&| /dialog.mc:label_value_row, label => pick_lang(rus => "Ôàéë", eng => "File"), id => "upload_file" &>
<% CGI::filefield({-name => 'upload_file', -class => 'dlgfield'}) %>
<% CGI::submit({-name => 'dlgb_apply', -class => 'button', -value => pick_lang(rus => "Ïðèêðåïèòü!", eng => "Attach!")}) %>
<& /dialog.mc:checkbox, id => 'load_as_text',
checkbox_label => pick_lang(rus => "Êàê òåêñò ðåñóðñà", eng => "As resource text"),
value => 0 &>
</&>
<&| /dialog.mc:cell, -align => 'right' &>
</&>
%#
%# List Attachments ============================================================
%#
% $att = new ePortal::Attachment;
% $att->restore_where(obj => $obj);
% if ($att->rows) {
<&| /dialog.mc:cell, -align => 'center' &>
<br>
<&| /list.mc, obj => new ePortal::Attachment, no_footer => 2,
-width => '80%', rows => 10, restore_where => { obj => $obj } &>
<& /list.mc:column_image &>
<&| /list.mc:column, id => 'filename',
-style => 'color: #9966ff;',
title => pick_lang(rus => "Èìÿ ôàéëà", eng => "File name") &>
<b><% $_->filename |h %></b>
</&>
<&| /list.mc:column, id => 'filesize', title => pick_lang(rus => "Ðàçìåð", eng => "Size"), -align => 'center' &>
<% $_->FileSize . ' ' . pick_lang(rus => "áàéò", eng => "bytes") %>
</&>
<& /list.mc:column_checkbox &>
<& /list.mc:action_bar, popup_menu => {
-values => ['delete'],
-labels => { delete => pick_lang(rus => "Óäàëèòü", eng => "Delete")}} &>
</&><!-- list -->
</&><!-- cell -->
% }
</&><!-- collapsed section. file attachments -->
% } # recordtype eq 'file'
%#
%# Access rights ============================================================
%#
% if ($obj->xacl_check_admin) {
<&| /dialog.mc:collapse, title => pick_lang(rus => "Ïðàâà äîñòóïà", eng => "Access rights") &>
<& /dialog.mc:read_only, id => 'uid' &>
<& /dialog.mc:field, id => 'xacl_read' &>
<& /dialog.mc:field, id => 'xacl_write' &>
<& /dialog.mc:field, id => 'xacl_admin' &>
</&>
% }
<&| /dialog.mc:cell &> </&>
<& /dialog.mc:buttons, ok_label => pick_lang(rus => "Ñîõðàíèòü ðåñóðñ", eng => "Save the resource"),
apply_button => 1 &>
%#
%# Additional information ===================================================
%#
<&| /dialog.mc:cell &>
<hr>
</&>
<& /dialog.mc:read_only, id => 'ts' &>
<& /dialog.mc:read_only, id => 'clicks' &>
<& /dialog.mc:read_only, id => 'hits' &>
</&>
<p>
<div class="memo">
<&| /rus.mc &>
Äîïîëíèòåëüíóþ èíôîðìàöèþ î ôîðìàòèðîâàíèè òåêñòà
<a href="/catalog/formatting-rules.htm">ñìîòðèòå çäåñü</a>
</&>
</div>
<p>
%#=== @METAGS attr =========================================================
<%attr>
Title => {rus => "Ðåñóðñ êàòàëîãà", eng => "Catalogue resource"}
</%attr>
%#=== @METAGS onStartRequest ====================================================
<%method onStartRequest><%perl>
$obj = new ePortal::Catalog;
# Get arguments from request and prepare objects
my $back_url = $m->comp('/dialog.mc:back_url');
my $new_att = new ePortal::Attachment;
my $updated_successfully = undef;
# restore object to edit
$obj->restore_or_throw($ARGS{objid}) if $ARGS{objid};
# Get default or new values from URL. Do not save the object !
$m->comp('/dialog.mc:htmlSave', obj => $obj);
# Upload a file
$new_att->upload(r => $r);
if ($new_att->check_id and $obj->Title eq '') {
$obj->Title( $new_att->Filename );
}
if ($new_att->check_id and $ARGS{load_as_text}) {
$obj->Text( $new_att->save_to_string );
}
#initialize ACL
if ( ! $obj->check_id ) { # new object
my $parent = $obj->parent;
$obj->set_acl_from_obj($parent) if $parent;
}
# Save the object
if ( $m->comp('/dialog.mc:isButtonPressed', button => 'ok' ) or
$m->comp('/dialog.mc:isButtonPressed', button => 'apply' )) {
$updated_successfully = try {
# actually update the object
$obj->save(); # 1 on update, 0 on insert, undef on error
if ( $ARGS{load_as_text} == 0 and $new_att->check_id) {
$new_att->link_with_object($obj);
}
1; # success
} catch ePortal::Exception::DataNotValid with {
my $E = shift;
$session{ErrorMessage} = $E->text;
undef;
};
}
# Clear unsuccessful uploads
$new_att->delete if ($new_att->check_id) and ($new_att->state ne 'ok');
# do redirect
if ( $m->comp('/dialog.mc:isButtonPressed', button => 'cancel' )) {
throw ePortal::Exception::Abort(-text => $back_url);
} elsif ($updated_successfully and $m->comp('/dialog.mc:isButtonPressed', button => 'ok' )) {
throw ePortal::Exception::Abort(-text => $back_url);
}
# delete attachment
if ( $m->comp('/list.mc:list_action') eq 'delete' ) {
my $new_att = new ePortal::Attachment;
foreach ($m->comp('/list.mc:checkboxes')) {
if ( $new_att->restore($_) ) {
$new_att->delete;
}
}
}
# Redirect to GET after POST
if ( $r->method eq 'POST' ) {
if ( $obj->check_id ) { # existing object
# delete BIG and unwanted arguments from request
delete $ARGS{$_} foreach (
qw/text load_as_text uid ts/,
grep { /^xacl_/ } keys %ARGS);
$ARGS{objid} = $obj->id;
$ARGS{title} ||= $obj->Title;
}
return href($ENV{SCRIPT_NAME}, %ARGS);
}
</%perl></%method>
%#=== @metags once =========================================================
<%once>
my ($obj, $att);
</%once>
%#=== @metags cleanup =========================================================
<%cleanup>
($obj, $att) = ();
</%cleanup>