Commits

Osiloke Emoekpere  committed 22528cb

fixed bug with widget js, removed tooltips

  • Participants
  • Parent commits 1348577
  • Branches enhancements

Comments (0)

Files changed (3)

File widget/static/widget/js/widget.coffee

 
         )
     #some neccessary jq config
-    $(".widget-edit-link, .widget-delete-link").tooltip {placement:"right"}
+    # $(".widget-edit-link, .widget-delete-link").tooltip {placement:"right"}
+    @setupAdmin()
+    @setupWidgetForms()
+    @setupSortableWidgets()
+    @setupWidgetStatusHandler()
     @
 
   setupAdmin: () =>
     # AJAX callback that's triggered when dragging a widget to re-order
     # Based on mezzanine
     updateOrdering = (event, ui) ->
+#      $uiItem = $(ui.item)
+#      if $uiItem.parent().is('.widget-sortable') then $uiItem.remove()
+
       next = ui.item.next()
       next.css({'-moz-transition':'none', '-webkit-transition':'none', 'transition':'none'})
       setTimeout(next.css.bind(next, {'-moz-transition':'border-top-width 0.1s ease-in', '-webkit-transition':'border-top-width 0.1s ease-in', 'transition':'border-top-width 0.1s ease-in'}))
       args =
         'ordering_from': $(this).sortable('toArray').toString(),
         'ordering_to': $(ui.item).parent().sortable('toArray').toString(),
-
+#      console.log $(this), $(ui.item)
       if args['ordering_from'] != args['ordering_to']
         # Branch changed - set the new parent ID.
         args['moved_widget'] = $(ui.item).attr('id')
 
       $.post(window.__widget_ordering_url, args, (data) ->
         if not data
-          alert("Error occured: " + data + "\nOrdering wasn't updated.");
+          alert("Error occured: " + data + "\nWidget ordering wasn't updated.");
 
-      )
-    stylesheet =`$('style[name=impostor_size]')[0].sheet,
-          rule = stylesheet.rules ? stylesheet.rules[0].style : stylesheet.cssRules[0].style,
-        setPadding = function(atHeight) {
-        rule.cssText = 'border-top-width: '+atHeight+'px';
-        }`
+      ) 
+    stylesheet = $('style[name=impostor_size]')[0].sheet
+    `rule = stylesheet.rules ? stylesheet.rules[0].style : stylesheet.cssRules[0].style`
+    setPadding = (atHeight) ->
+        rule.cssText = 'border-top-width: '+atHeight+'px'
 
     $('.widget-sortable').sortable({
-    handle: '.ordering', opacity: '.7', stop: updateOrdering,
-    forcePlaceholderSize: true,
-    placeholder: "ui-state-highlight",
-    forcePlaceholderSize: true,
-    placeholder: 'marker',
-    revert: 150,
-    start: (ev, ui) ->
-      setPadding(ui.item.height())
-    }).sortable('option', 'connectWith', '.widget-sortable')
-    $('.widget-sortable').disableSelection()
+      handle: '.ordering',
+      opacity: '.7',
+      stop: updateOrdering,
+      forcePlaceholderSize: true,
+      dropOnEmpty: true,
+      placeholder: 'placeholder',
+      helper: 'clone',
+      revert: 150,
 
-    @
+#      start: (ev, ui) ->
+#        setPadding(ui.item.height())
+    })
+      .sortable('option', 'connectWith', '.widget-sortable')
+      .bind('sortstart', (event, ui) ->
+          setPadding(ui.item.height())
+#          $uiItem = $(ui.item)
+#          $uiItem.clone().show().insertBefore($uiItem)
+      )
+      .disableSelection()
+
   #edit form handler
   onEditForm: (link, widget_id, widget_title) ->
     widget = this

File widget/static/widget/js/widget.js

+// Generated by CoffeeScript 1.3.3
 (function() {
   var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
 
 
     function WidgetAdmin() {
       this.setupWidgetStatusHandler = __bind(this.setupWidgetStatusHandler, this);
+
       this.setupWidgetForms = __bind(this.setupWidgetForms, this);
+
       this.setupAdmin = __bind(this.setupAdmin, this);
+
       var not_impl;
       not_impl = $('a.not-implemented');
-      if (not_impl.length > 0) not_impl.each(function(i) {});
-      $(".widget-edit-link, .widget-delete-link").tooltip({
-        placement: "right"
-      });
+      if (not_impl.length > 0) {
+        not_impl.each(function(i) {});
+      }
+      this.setupAdmin();
+      this.setupWidgetForms();
+      this.setupSortableWidgets();
+      this.setupWidgetStatusHandler();
       this;
+
     }
 
     WidgetAdmin.prototype.setupAdmin = function() {
     };
 
     WidgetAdmin.prototype.setupSortableWidgets = function() {
-      var stylesheet, updateOrdering;
+      var setPadding, stylesheet, updateOrdering;
       updateOrdering = function(event, ui) {
         var args, next;
         next = ui.item.next();
         }
         return $.post(window.__widget_ordering_url, args, function(data) {
           if (!data) {
-            return alert("Error occured: " + data + "\nOrdering wasn't updated.");
+            return alert("Error occured: " + data + "\nWidget ordering wasn't updated.");
           }
         });
       };
-      stylesheet = $('style[name=impostor_size]')[0].sheet,
-          rule = stylesheet.rules ? stylesheet.rules[0].style : stylesheet.cssRules[0].style,
-        setPadding = function(atHeight) {
-        rule.cssText = 'border-top-width: '+atHeight+'px';
-        };
-      $('.widget-sortable').sortable({
+      stylesheet = $('style[name=impostor_size]')[0].sheet;
+      rule = stylesheet.rules ? stylesheet.rules[0].style : stylesheet.cssRules[0].style;
+
+      setPadding = function(atHeight) {
+        return rule.cssText = 'border-top-width: ' + atHeight + 'px';
+      };
+      return $('.widget-sortable').sortable({
         handle: '.ordering',
         opacity: '.7',
         stop: updateOrdering,
         forcePlaceholderSize: true,
-        placeholder: "ui-state-highlight",
-        forcePlaceholderSize: true,
-        placeholder: 'marker',
-        revert: 150,
-        start: function(ev, ui) {
-          return setPadding(ui.item.height());
-        }
-      }).sortable('option', 'connectWith', '.widget-sortable');
-      $('.widget-sortable').disableSelection();
-      return this;
+        dropOnEmpty: true,
+        placeholder: 'placeholder',
+        helper: 'clone',
+        revert: 150
+      }).sortable('option', 'connectWith', '.widget-sortable').bind('sortstart', function(event, ui) {
+        return setPadding(ui.item.height());
+      }).disableSelection();
     };
 
     WidgetAdmin.prototype.onEditForm = function(link, widget_id, widget_title) {
             break;
           default:
             this;
+
         }
       }
       return this;
     WidgetAdmin.prototype.preSubmit = function(e, form) {
       form.hide();
       $('#editable-loading').show();
-      if (typeof tinyMCE !== "undefined") return tinyMCE.triggerSave();
+      if (typeof tinyMCE !== "undefined") {
+        return tinyMCE.triggerSave();
+      }
     };
 
     WidgetAdmin.prototype.resultParsed = function(e, params) {
           default:
             $("#editForm h3#title").text("You are done! Click save");
             this;
+
         }
       }
       $('#editable-loading').hide();

File widget/templates/widget/widget_loader.html

                 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
             }
         });
-
-        var WidgetController = new WidgetAdmin();
-        WidgetController.setupWidgetForms();
-        WidgetController.setupSortableWidgets();
+        
         window.__widget_ordering_url = "{% url "widget_ordering" %}";
+        var WidgetController = new WidgetAdmin(); 
     });
 </script>