Beagle
view release on metacpan or search on metacpan
lib/Beagle/Web.pm view on Meta::CPAN
name => $name,
parent_id => $entry->id,
);
$bh->delete_attachment($att);
}
}
sub add_attachments {
shift @_ if @_ && $_[0] eq 'Beagle::Web';
my ( $entry, @attachments ) = @_;
for my $upload (@attachments) {
next unless $upload;
my $basename = decode_utf8 $upload->filename;
$basename =~ s!\\!/!g;
$basename =~ s!.*/!!;
my $att = Beagle::Model::Attachment->new(
name => $basename,
content_file => $upload->tempname,
parent_id => $entry->id,
);
$bh->create_attachment( $att,
message => 'added attachment '
. $basename
. ' for entry '
. $entry->id );
}
}
lib/Beagle/Web/Router.pm view on Meta::CPAN
# make comment's format be plain by default if from web ui
$entry->format('plain');
}
if ( process_fields( $entry, request()->parameters->mixed ) ) {
my ($created) =
handle()->create_entry( $entry, message => request()->param('message') );
if ($created) {
add_attachments( $entry, request()->upload('attachments') );
if ( request()->header('Accept') =~ /json/ ) {
my $ret = {
status => 'created',
parent_id => $entry->parent_id,
content => render( 'entry_comment', entry => $entry ),
};
status(201);
content_type('application/json');
return to_json($ret);
}
lib/Beagle/Web/Router.pm view on Meta::CPAN
if ( my $entry = handle()->map->{$id} ) {
if ( process_fields( $entry, request()->parameters->mixed ) ) {
handle()->update_entry( $entry, message => request()->param('message') );
my $del = $vars{'delete-attachments'};
delete_attachments( $entry, ref $del ? @$del : $del );
add_attachments( $entry, request()->upload('attachments') );
render 'admin/entry',
entry => $entry,
form => Beagle::Web::Form->new(
field_list => scalar Beagle::Web->field_list($entry) ),
message => 'updated',
prefix => prefix() || '../../';
}
else {
render 'admin/entry',
share/public/js/base/jquery.form.js view on Meta::CPAN
callbacks.push(options.success);
}
options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
var context = options.context || options; // jQuery 1.4+ supports scope context
for (var i=0, max=callbacks.length; i < max; i++) {
callbacks[i].apply(context, [data, status, xhr || $form, $form]);
}
};
// are there files to upload?
var fileInputs = $('input:file', this).length > 0;
var mp = 'multipart/form-data';
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
// options.iframe allows user to force iframe mode
// 06-NOV-09: now defaulting to iframe mode if file input is detected
if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
// hack to fix Safari hang (thanks to Tim Molendijk for this)
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
if (options.closeKeepAlive) {
share/public/js/base/jquery.form.js view on Meta::CPAN
}
else {
$.ajax(options);
}
// fire 'notify' event
this.trigger('form-submit-notify', [this, options]);
return this;
// private function for handling file uploads (hat tip to YAHOO!)
function fileUpload() {
var form = $form[0];
if ($(':input[name=submit],:input[id=submit]', form).length) {
// if there is an input with a name or id of 'submit' then we won't be
// able to invoke the submit fn on the form (at least not x-browser)
alert('Error: Form elements must not have name or id of "submit".');
return;
}
share/public/js/base/jquery.form.js view on Meta::CPAN
if (n && !sub.disabled) {
s.extraData = s.extraData || {};
s.extraData[n] = sub.value;
if (sub.type == "image") {
s.extraData[n+'.x'] = form.clk_x;
s.extraData[n+'.y'] = form.clk_y;
}
}
}
// take a breath so that pending repaints get some cpu time before the upload starts
function doSubmit() {
// make sure form attrs are set
var t = $form.attr('target'), a = $form.attr('action');
// update form attrs in IE friendly way
form.setAttribute('target',id);
if (form.getAttribute('method') != 'POST') {
form.setAttribute('method', 'POST');
}
if (form.getAttribute('action') != s.url) {
share/public/js/base/jquery.form.js view on Meta::CPAN
}
catch(e){
log('error caught:',e);
ok = false;
xhr.error = e;
s.error.call(s.context, xhr, 'error', e);
g && $.event.trigger("ajaxError", [xhr, s, e]);
}
if (xhr.aborted) {
log('upload aborted');
ok = false;
}
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
if (ok) {
s.success.call(s.context, data, 'success', xhr);
g && $.event.trigger("ajaxSuccess", [xhr, s]);
}
g && $.event.trigger("ajaxComplete", [xhr, s]);
( run in 2.425 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )