]> gitweb.fluxo.info Git - drupal/muamba.git/commitdiff
Widget updates
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 7 Oct 2011 01:41:35 +0000 (22:41 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 7 Oct 2011 01:41:35 +0000 (22:41 -0300)
CREDITS.txt
images/cancel.orig.png [new file with mode: 0644]
images/cancel.png [new file with mode: 0644]
images/unavailable.orig.png [new file with mode: 0644]
images/unavailable.png [new file with mode: 0644]
muamba-widget.tpl.php
muamba.misc.inc
muamba.module
muamba.theme.inc

index ee9123995794354f9c0f1b97baca58007ae4c5b1..85e71bd18a5b9394985303b4dcc7cb5e2ac1e365 100644 (file)
@@ -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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..7b4f6d4
Binary files /dev/null and b/images/unavailable.png differ
index 3caf6148cea3ad75f4b2d3feb80643ddb91176e1..6923de8db5879c62a2eff9b27b2b29dc02b9bf9f 100644 (file)
@@ -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  = '<div class="muamba-widget">';
-$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 .= '</div>';
 
 print $output;
index b5c11114635eda0da3486952ee03cb5651189efd..70aa5988369ca517a59d84d68a4d11d3be6afc07 100644 (file)
@@ -76,7 +76,7 @@ function muamba_actions($code = NULL) {
     MUAMBA_LOST      => 'lost',
   );
 
-  if ($code == NULL) {
+  if ($code === NULL) {
     return $status;
   }
 
index fcd656544a986571c20d2b437f464b9f4a958b14..b530bb90dd7b1afecf871654847a6ac5efd18fae 100644 (file)
@@ -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',
+    ),
   );
 }
 
index 4e201f7611f42b6a416fea85fefcc4ae96eb6169..a51f6f668d5cb878162b31c8f53a2b59d32a6432 100644 (file)
@@ -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;
+}