Browse Source

HUE-7426 [frontend] Add gridster Knockout binding

Enrico Berti 8 years ago
parent
commit
361a74f

+ 7 - 0
desktop/core/src/desktop/static/desktop/ext/js/gridster-knockout.min.js

@@ -0,0 +1,7 @@
+/*!
+ * gridster-knockout v0.0.1
+ * (c) Justin Kohlhepp - 
+ * License: MIT (http://www.opensource.org/licenses/mit-license.php)
+ */
+
+ko.bindingHandlers.gridster={init:function(a,b,c,d,e){for(var f=$(a).data("gridster"),g=ko.unwrap(b)(),h=ko.unwrap(g.items),i=ko.unwrap(g.template),j=$("#"+i).html(),k=1,l=0;l<h.length;l++){var m=h[l];m.widgetId&&m.widgetId()>=k&&(k=parseInt(m.widgetId())+1)}for(var n=function(a){var c=void 0!==a.col?parseInt(a.col()):null,d=void 0!==a.row?parseInt(a.row()):null,g=parseInt(a.sizex()),h=parseInt(a.sizey()),i=f.add_widget(j,g,h,c,d);void 0===a.col&&(a.col=ko.observable(i.attr("data-col"))),void 0===a.row&&(a.row=ko.observable(i.attr("data-row"))),void 0===a.widgetId&&(a.widgetId=ko.observable(),a.widgetId(k++)),i.attr("data-widgetId",a.widgetId()),a.gridsterElement=i.get(0);var l=e.createChildContext(a,null,function(a){ko.utils.extend(a,b())});return ko.applyBindingsToDescendants(l,i.get(0)),i},o=function(a){for(var b=0;b<h.length;b++){var c=h[b];if(c.widgetId()==a)return c}return null},l=0;l<h.length;l++)m=h[l],n(m);g.items.subscribe(function(a){a.forEach(function(a){switch(a.status){case"added":{n(a.value)}break;case"deleted":f.remove_widget(a.value.gridsterElement);break;default:throw new Error("Unexpected change.status")}})},null,"arrayChange");var p=function(){for(var a=0;a<h.length;a++){var b=h[a],c=$(b.gridsterElement).attr("data-col"),d=$(b.gridsterElement).attr("data-row");b.col(c),b.row(d)}},q=f.options.resize.stop;f.options.resize.stop=function(a,b,c){var d=c.attr("data-widgetId"),e=c.attr("data-sizex"),f=c.attr("data-sizey"),g=o(d);g.sizex(e),g.sizey(f),p(),void 0!==q&&q(a,b,c)};var r=f.options.draggable.stop;return f.options.draggable.stop=function(a,b){p(),void 0!==r&&r(a,b)},{controlsDescendantBindings:!0}}};

+ 5 - 0
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -2773,7 +2773,9 @@ ${ dashboard.layout_skeleton(suffix='search') }
 <link rel="stylesheet" href="${ static('desktop/ext/chosen/chosen.min.css') }">
 <link rel="stylesheet" href="${ static('desktop/ext/select2/select2.css') }">
 <link rel="stylesheet" href="${ static('desktop/ext/css/selectize.css') }">
+%if USE_GRIDSTER.get():
 <link rel="stylesheet" href="${ static('desktop/ext/css/jquery.gridster.min.css') }">
+%endif
 
 <script src="${ static('desktop/js/hue.json.js') }" type="text/javascript" charset="utf-8"></script>
 
@@ -2795,7 +2797,10 @@ ${ dashboard.import_layout(True) }
 <script src="${ static('desktop/js/ko.selectize.js') }"></script>
 <script src="${ static('dashboard/js/search.ko.js') }" type="text/javascript" charset="utf-8"></script>
 
+%if USE_GRIDSTER.get():
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.gridster.with-extras.min.js') }"></script>
+<script src="${ static('desktop/ext/js/gridster-knockout.min.js') }"></script>
+%endif
 
 ${ dashboard.import_bindings() }