Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
UI isn't the best, but it does prevent from the screen locking up (no
action possible due to overlay)

This will probably be cleaned up even more in the near future
  • Loading branch information
slusarz committed Mar 23, 2014
1 parent a2b64dc commit c955c19
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 43 deletions.
85 changes: 59 additions & 26 deletions imp/js/dimpbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ var DimpBase = {
case 'ctx_mbox_create':
case 'ctx_remoteauth_create':
tmp = this.contextMbox(e);
RedBox.loading();
DimpCore.doAction('createMailboxPrepare', {
mbox: tmp.retrieve('mbox')
},{
Expand All @@ -878,6 +879,7 @@ var DimpBase = {
case 'ctx_container_rename':
case 'ctx_mbox_rename':
tmp = this.contextMbox(e);
RedBox.loading();
DimpCore.doAction('deleteMailboxPrepare', {
mbox: tmp.retrieve('mbox'),
type: 'rename'
Expand All @@ -888,6 +890,7 @@ var DimpBase = {

case 'ctx_mbox_empty':
tmp = this.contextMbox(e);
RedBox.loading();
DimpCore.doAction('emptyMailboxPrepare', {
mbox: tmp.retrieve('mbox')
},{
Expand All @@ -902,6 +905,7 @@ var DimpBase = {
case 'ctx_mbox_delete':
case 'ctx_vfolder_delete':
tmp = this.contextMbox(e);
RedBox.loading();
DimpCore.doAction('deleteMailboxPrepare', {
mbox: tmp.retrieve('mbox'),
type: 'delete'
Expand Down Expand Up @@ -3076,43 +3080,59 @@ var DimpBase = {
{
switch (type) {
case 'create':
this._createMboxForm(elt, 'createsub', DimpCore.text.createsub_prompt.sub('%s', this.fullMboxDisplay(elt)));
if (r.result) {
this._createMboxForm(elt, 'createsub', DimpCore.text.createsub_prompt.sub('%s', this.fullMboxDisplay(elt)));
} else {
RedBox.close();
}
break;

case 'delete':
this.viewaction = function(e) {
DimpCore.doAction('deleteMailbox', {
container: ~~elt.hasClassName('imp-sidebar-container'),
mbox: elt.retrieve('mbox'),
subfolders: e.element().down('[name=delete_subfolders]').getValue()
if (r.result) {
this.viewaction = function(e) {
DimpCore.doAction('deleteMailbox', {
container: ~~elt.hasClassName('imp-sidebar-container'),
mbox: elt.retrieve('mbox'),
subfolders: e.element().down('[name=delete_subfolders]').getValue()
});
};
HordeDialog.display({
form: new Element('DIV').insert(
new Element('INPUT', { name: 'delete_subfolders', type: 'checkbox' })
).insert(
DimpCore.text.delete_mbox_subfolders.sub('%s', this.fullMboxDisplay(elt))
),
form_id: 'dimpbase_confirm',
text: elt.hasClassName('imp-sidebar-container') ? null : DimpCore.text.delete_mbox.sub('%s', this.fullMboxDisplay(elt))
});
};
HordeDialog.display({
form: new Element('DIV').insert(
new Element('INPUT', { name: 'delete_subfolders', type: 'checkbox' })
).insert(
DimpCore.text.delete_mbox_subfolders.sub('%s', this.fullMboxDisplay(elt))
),
form_id: 'dimpbase_confirm',
text: elt.hasClassName('imp-sidebar-container') ? null : DimpCore.text.delete_mbox.sub('%s', this.fullMboxDisplay(elt))
});
} else {
RedBox.close();
}
break;

case 'empty':
this.viewaction = function() {
DimpCore.doAction('emptyMailbox', {
mbox: elt.retrieve('mbox')
if (r.result) {
this.viewaction = function() {
DimpCore.doAction('emptyMailbox', {
mbox: elt.retrieve('mbox')
});
};
HordeDialog.display({
form_id: 'dimpbase_confirm',
noinput: true,
text: DimpCore.text.empty_mbox.sub('%s', this.fullMboxDisplay(elt)).sub('%d', r)
});
};
HordeDialog.display({
form_id: 'dimpbase_confirm',
noinput: true,
text: DimpCore.text.empty_mbox.sub('%s', this.fullMboxDisplay(elt)).sub('%d', r)
});
} else {
RedBox.close();
}
break;

case 'rename':
this._createMboxForm(elt, 'rename', DimpCore.text.rename_prompt.sub('%s', this.fullMboxDisplay(elt)), elt.retrieve('l').unescapeHTML());
if (r.result) {
this._createMboxForm(elt, 'rename', DimpCore.text.rename_prompt.sub('%s', this.fullMboxDisplay(elt)), elt.retrieve('l').unescapeHTML());
} else {
RedBox.close();
}
break;

case 'subscribe':
Expand Down Expand Up @@ -4125,6 +4145,18 @@ var DimpBase = {
onAjaxException: function()
{
HordeCore.notify(HordeCore.text.ajax_error, 'horde.error');
},

onAjaxFailure: function()
{
switch (e.memo[0].request.action) {
case 'createMailboxPrepare':
case 'deleteMailboxPrepare':
case 'emptyMailboxPrepare':
case 'mailboxSize':
RedBox.close();
break;
}
}

};
Expand Down Expand Up @@ -4202,6 +4234,7 @@ document.observe('HordeDialog:close', DimpBase.dialogCloseHandler.bind(DimpBase)

/* AJAX related events. */
document.observe('HordeCore:ajaxException', DimpBase.onAjaxException.bind(DimpBase));
document.observe('HordeCore:ajaxFailure', DimpBase.onAjaxFailure.bind(DimpBase));
document.observe('HordeCore:runTasks', function(e) {
DimpBase.tasksHandler(e.memo);
});
Expand Down
42 changes: 25 additions & 17 deletions imp/lib/Ajax/Application/Handler/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ class IMP_Ajax_Application_Handler_Dynamic
* - mbox: (string) The name of the mailbox to check (base64url
* encoded).
*
* @return boolean True if submailboxes can be created.
* @return object Object with the following properties:
* - result: (boolean) True if submailboxes can be created.
*/
public function createMailboxPrepare()
{
$mbox = IMP_Mailbox::formFrom($this->vars->mbox);
$ret = new stdClass;
$ret->result = true;

if ($mbox->access_creatembox) {
return true;
if (!$mbox->access_creatembox) {
$GLOBALS['notification']->push(sprintf(_("You may not create child mailboxes in \"%s\"."), $mbox->display), 'horde.error');
$ret->result = false;
}

$GLOBALS['notification']->push(sprintf(_("You may not create child mailboxes in \"%s\"."), $mbox->display), 'horde.error');
return false;
return $ret;
}

/**
Expand Down Expand Up @@ -96,14 +99,17 @@ public function createMailbox()
* encoded).
* - type: (string) Either 'delete' or 'rename'.
*
* @return boolean True if mailbox can be deleted/renamed.
* @return object Object with the following properties:
* - result: (boolean) True if mailbox can be deleted/renamed.
*/
public function deleteMailboxPrepare()
{
$mbox = IMP_Mailbox::formFrom($this->vars->mbox);
$ret = new stdClass;

if ($mbox->access_deletembox) {
return true;
$ret->result = true;
return $ret;
}

switch ($this->vars->type) {
Expand All @@ -116,7 +122,8 @@ public function deleteMailboxPrepare()
break;
}

return false;
$ret->result = false;
return $ret;
}

/**
Expand Down Expand Up @@ -177,24 +184,25 @@ public function renameMailbox()
* - mbox: (string) The name of the mailbox to check (base64url
* encoded).
*
* @return integer The number of messages to be deleted.
* @return object Object with the following properties:
* - result: (integer) The number of messages to be deleted.
*/
public function emptyMailboxPrepare()
{
$mbox = IMP_Mailbox::formFrom($this->vars->mbox);
$res = new stdClass;
$res->result = 0;

if (!$mbox->access_empty) {
$GLOBALS['notification']->push(sprintf(_("The mailbox \"%s\" may not be emptied."), $mbox->display), 'horde.error');
return 0;
}

$poll_info = $mbox->poll_info;
if (empty($poll_info->msgs)) {
$GLOBALS['notification']->push(sprintf(_("The mailbox \"%s\" is already empty."), $mbox->display), 'horde.message');
return 0;
} else {
$poll_info = $mbox->poll_info;
if (!($res->result = $poll_info->msgs)) {
$GLOBALS['notification']->push(sprintf(_("The mailbox \"%s\" is already empty."), $mbox->display), 'horde.message');
}
}

return $poll_info->msgs;
return $res;
}

/**
Expand Down

0 comments on commit c955c19

Please sign in to comment.