]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #1793 - added a basic add new widgets view - it is not wired up yet
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 17 Nov 2010 22:08:39 +0000 (22:08 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 17 Nov 2010 22:08:39 +0000 (22:08 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7333 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/widgets.php
js/lib/ui.widgets.js
languages/en.php
views/default/css.php
views/default/layouts/widgets.php
views/default/widgets/add.php [new file with mode: 0644]
views/default/widgets/add_button.php [new file with mode: 0644]

index e3ab0722712cdd8faa7e680266654d601e7ff01f..1de114833e257c16ab47b0624fc18c77c112d8ac 100644 (file)
@@ -146,13 +146,23 @@ function get_widgets($user_guid, $context, $column) {
 }
 
 /**
- * Displays a particular widget
+ * Get widgets for a particular context in order of display
  *
- * @param ElggObject $widget The widget to display
+ * @param int    $user_guid The owner user GUID
+ * @param string $context   The context (profile, dashboard, etc)
  *
- * @return string The HTML for the widget, including JavaScript wrapper
+ * @return array|false An array of widget ElggObjects, or false
+ */
+function elgg_get_widgets($user_guid, $context) {
+       // @todo implement elgg_get_entities_from_private_settings() first
+       return false;
+}
+
+/**
+ * @deprecated 1.8
  */
 function display_widget(ElggObject $widget) {
+       elgg_deprecated_notice("display_widget() was been deprecated. Use elgg_view_entity().", 1.8);
        return elgg_view_entity($widget);
 }
 
@@ -479,6 +489,25 @@ function reorder_widgets_from_panel($panelstring1, $panelstring2, $panelstring3,
        return $return;
 }
 
+/**
+ * Can the user edit the widgets
+ *
+ * @param int $user_guid The GUID of the user or 0 for logged in user
+ * @return bool
+ */
+function elgg_can_edit_widgets($user_guid = 0) {
+       $return = false;
+       if (isadminloggedin()) {
+               $return = true;
+       }
+       if (elgg_get_page_owner_guid() == get_loggedin_userid()) {
+               $return = true;
+       }
+
+       // @todo add plugin hook
+       return $return;
+}
+
 /**
  * Regsiter entity of object, widget as ElggWidget objects
  *
index cf13d6e954c97fc31b190a35be3ecb746577ba85..f4fa4b25611ae5fbafd48f97fbbff93fee3aec44 100644 (file)
@@ -9,6 +9,12 @@ elgg.ui.widgets.init = function() {
                placeholder:          'widget_placeholder'\r
        });\r
 \r
+       $('#widget_add_button a').bind('click', function(event) {\r
+               $('.widgets_add').slideToggle('medium');\r
+               event.preventDefault();\r
+       });\r
+\r
+\r
 };\r
 \r
 //List active widgets for each page column\r
index ad6461fd030c581d3bbcf521bf19b1b9024471bd..e78d01c816176bc09dfc1ad201a286f47edb6a25 100644 (file)
@@ -227,10 +227,8 @@ $english = array(
        'dashboard:configure' => "Edit page",
        'dashboard:nowidgets' => "Your dashboard is your gateway into the site. Click 'Edit page' to add widgets to keep track of content and your life within the system.",
 
-       'widgets:add' => 'Add widgets to your page',
-       'widgets:add:description' => "Choose the features you want to add to your page by dragging them from the <b>Widget gallery</b> on the right, to any of the three widget areas below, and position them where you would like them to appear.
-
-To remove a widget drag it back to the <b>Widget gallery</b>.",
+       'widgets:add' => 'Add widgets',
+       'widgets:add:description' => "Click on any widget button below to add it to your page.",
        'widgets:position:fixed' => '(Fixed position on page)',
 
        'widgets' => "Widgets",
index 8409ceb8b4b784c3bda7070bbc184001e1b5e49b..edb0ebe07eccc64b0a7fdd4885bcacef48d744b6 100644 (file)
@@ -881,6 +881,28 @@ li.navigation_more ul li {
 .widget_first_col {
        margin-right: 0;
 }
+#widget_add_button {
+       padding: 0px;
+       background-color: transparent;
+       text-align: right;
+}
+.widgets_add {
+       width: 100%;
+       padding: 10px;
+       margin-bottom: 15px;
+       background: #dedede;
+}
+.widgets_add li {
+       float: left;
+       margin: 2px 10px;
+       list-style: none;
+}
+.widgets_add li a {
+       display: block;
+       width: 200px;
+       padding: 4px;
+       background-color: #cccccc;
+}
 .widget {
        background-color: #dedede;
        padding: 2px;
index 21d942080f829872490e9b365679e4aec660aa0d..5d6e42a431c02822c3ebe4f678eef83f6a3922e9 100644 (file)
@@ -4,21 +4,25 @@
  *
  * @uses $vars['box'] Optional display box at the top of layout
  * @uses $vars['num_columns'] Number of widget columns for this layout
+ * @uses $vars['show_add_widgets'] Display the add widgets button
  */
 
+$box = elgg_get_array_value('box', $vars, '');
+$num_columns = elgg_get_array_value('num_columns', $vars, 3);
+$show_add_widgets = elgg_get_array_value('show_add_widgets', $vars, true);
+
 $owner = elgg_get_page_owner();
 $context = elgg_get_context();
 elgg_push_context('widgets');
 
-if (isset($vars['box'])) {
-       echo $vars['box'];
-}
+elgg_get_widgets($owner->guid, $context);
 
-$num_columns = 3;
-if (isset($vars['num_columns'])) {
-       $num_columns = $vars['num_columns'];
+if (elgg_can_edit_widgets()) {
+       echo elgg_view('widgets/add', array('widgets' => $widgets));
 }
 
+echo $vars['box'];
+
 $widget_class = "widget_col_$num_columns";
 for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
        $widgets = get_widgets($owner->guid, $context, $column_index);
@@ -33,6 +37,12 @@ for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
        $first = ($column_index == 1) ? 'widget_first_col' : '';
 
        echo "<div class=\"widget_column $widget_class $first\">";
+       // button for adding new widgets
+       if ($column_index == 1) {
+               if ($show_add_widgets && elgg_can_edit_widgets()) {
+                       echo elgg_view('widgets/add_button');
+               }
+       }
        if (is_array($widgets) && sizeof($widgets) > 0) {
                foreach ($widgets as $widget) {
                        echo elgg_view_entity($widget);
diff --git a/views/default/widgets/add.php b/views/default/widgets/add.php
new file mode 100644 (file)
index 0000000..2cc06da
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+$widgets = $vars['widgets'];
+$widget_types = get_widget_types();
+
+?>
+<div class="widgets_add hidden">
+       <p>
+               <?php echo elgg_echo('widgets:add:description'); ?>
+       </p>
+       <ul>
+               <?php
+                       foreach ($widget_types as $widget_type) {
+                               $link = elgg_view('output/url', array('text' => $widget_type->name, 'href' => '#'));
+                               echo "<li>$link</li>";
+                       }
+               ?>
+       </ul>
+       <div class="clearfloat"></div>
+</div>
diff --git a/views/default/widgets/add_button.php b/views/default/widgets/add_button.php
new file mode 100644 (file)
index 0000000..8ec36b0
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+?>
+<div class="widget" id="widget_add_button">
+<?php
+$options = array(
+       'href' => '#',
+       'text' => elgg_echo('widgets:add'),
+       'class' => 'action_button',
+);
+echo elgg_view('output/url', $options);
+?>
+</div>