From fe5d67700ceb54bdc951dbd1f5f98e9dcae89855 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 6 Oct 2011 22:41:35 -0300 Subject: Widget updates --- CREDITS.txt | 2 ++ images/cancel.orig.png | Bin 0 -> 44388 bytes images/cancel.png | Bin 0 -> 10838 bytes images/unavailable.orig.png | Bin 0 -> 69262 bytes images/unavailable.png | Bin 0 -> 12484 bytes muamba-widget.tpl.php | 42 ++++++++++++++++++++++++++++-------------- muamba.misc.inc | 2 +- muamba.module | 7 +++++++ muamba.theme.inc | 24 ++++++++++++++++++++++++ 9 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 images/cancel.orig.png create mode 100644 images/cancel.png create mode 100644 images/unavailable.orig.png create mode 100644 images/unavailable.png diff --git a/CREDITS.txt b/CREDITS.txt index ee91239..85e71bd 100644 --- a/CREDITS.txt +++ b/CREDITS.txt @@ -17,3 +17,5 @@ http://www.openclipart.org/detail/57079/recover-symbol-by-doctormo http://www.openclipart.org/detail/147421/home-by-netalloy-147421 http://www.openclipart.org/detail/107473/folder-inbox-by-anonymous http://www.openclipart.org/detail/160369/eshop-by-lbear +http://www.openclipart.org/detail/110/red-square-error-warning-icon-by-molumen +http://www.openclipart.org/detail/57745/denied-by-chovynz diff --git a/images/cancel.orig.png b/images/cancel.orig.png new file mode 100644 index 0000000..c65dc65 Binary files /dev/null and b/images/cancel.orig.png differ diff --git a/images/cancel.png b/images/cancel.png new file mode 100644 index 0000000..e6ec59d Binary files /dev/null and b/images/cancel.png differ diff --git a/images/unavailable.orig.png b/images/unavailable.orig.png new file mode 100644 index 0000000..945bcfc Binary files /dev/null and b/images/unavailable.orig.png differ diff --git a/images/unavailable.png b/images/unavailable.png new file mode 100644 index 0000000..7b4f6d4 Binary files /dev/null and b/images/unavailable.png differ diff --git a/muamba-widget.tpl.php b/muamba-widget.tpl.php index 3caf614..6923de8 100644 --- a/muamba-widget.tpl.php +++ b/muamba-widget.tpl.php @@ -3,27 +3,41 @@ /** * @file * Template for displaying the muamba widget. - * - * @todo: use $transaction - * Show item status: can it be requested? - * Is this item already requested? */ -// Add javascript and CSS files +// User and path $path = drupal_get_path('module', 'muamba'); +global $user; + +// Add javascript and CSS files drupal_add_js($path .'/muamba.js'); drupal_add_css($path .'/muamba.css'); -$icon = theme('image', - array( - 'path' => $path .'/images/basket.png', - 'alt' => t('Request item'), - 'title' => t('Request item'), - ) -); - $output = '
'; -$output .= l($icon, 'muamba/request/'. $nid, array('html' => TRUE)); + +if (empty($transaction)) { + $output .= theme('muamba_widget_icon', array('status' => MUAMBA_REQUESTED, 'id' => $nid)); +} +elseif ($transaction['uid'] == $user->uid) { + foreach (muamba_actions_available('sent', $transaction['status']) as $action) { + $output .= theme('muamba_widget_icon', array('status' => $action, 'id' => $transaction['mid'])); + } +} +elseif ($transaction['owner'] == $user->uid) { + foreach (muamba_actions_available('received', $transcation['status']) as $action) { + $output .= theme('muamba_widget_icon', array('status' => $action, 'id' => $transaction['mid'])); + } +} +else { + $icon = theme('image', + array( + 'path' => $path .'/images/unavailable.png', + 'alt' => t('Item unavailable'), + 'title' => t('Item unavailable'), + ) + ); +} + $output .= '
'; print $output; diff --git a/muamba.misc.inc b/muamba.misc.inc index b5c1111..70aa598 100644 --- a/muamba.misc.inc +++ b/muamba.misc.inc @@ -76,7 +76,7 @@ function muamba_actions($code = NULL) { MUAMBA_LOST => 'lost', ); - if ($code == NULL) { + if ($code === NULL) { return $status; } diff --git a/muamba.module b/muamba.module index fcd6565..b530bb9 100644 --- a/muamba.module +++ b/muamba.module @@ -198,6 +198,13 @@ function muamba_theme($existing, $type, $theme, $path) { ), 'file' => 'muamba.theme.inc', ), + 'muamba_widget_icon' => array( + 'variables' => array( + 'status' => MUAMBA_REQUESTED, + 'id' => NULL, + ), + 'file' => 'muamba.theme.inc', + ), ); } diff --git a/muamba.theme.inc b/muamba.theme.inc index 4e201f7..a51f6f6 100644 --- a/muamba.theme.inc +++ b/muamba.theme.inc @@ -134,3 +134,27 @@ function theme_muamba_recovered_message($transaction = NULL) { function theme_muamba_lost_message($transaction = NULL) { return t('I declare that my item is lost'); } + +/** + * Theme callback. + */ +function theme_muamba_widget_icon($variables) { + $status = $variables['status']; + $id = $variables['id']; + $path = drupal_get_path('module', 'muamba'); + $action = muamba_actions($status); + $image = $path .'/images/'. $action .'.png'; + $title = ucfirst($action) .' item'; + + $icon = theme('image', + array( + 'path' => $image, + 'alt' => t($title), + 'title' => t($title), + ) + ); + + $output = l($icon, 'muamba/'. $action .'/'. $id, array('html' => TRUE)); + + return $output; +} -- cgit v1.2.3