 module = angular.module('impac.components.widget', [])
 
-module.controller('ImpacWidgetCtrl', ($scope, $timeout, $log, DhbAnalyticsSvc, Utilities) ->
-
-  # ---------------------------------------------------------
-  # ### Widget template scope
-  # ---------------------------------------------------------
-  # ---------------------------------------------------------
-  # ### Toolbox
-  # ---------------------------------------------------------
-
-  # angular.merge doesn't exist in angular 1.2...
-  extendDeep = (dst, src) ->
-    angular.forEach src, (value, key) ->
-      if dst[key] and dst[key].constructor and dst[key].constructor is Object
-        extendDeep dst[key], value
-      else
-        dst[key] = value
+module.controller('ImpacWidgetCtrl', ($scope, $timeout, $log, ImpacWidgetsSvc, Utilities) ->
 
   # ---------------------------------------------------------
   # ### Widget object management

  # Retrieve the widget content from Impac! and initialize the widget from it.
  w.loadContent = (refreshCache=false) ->
    w.isLoading = true
    DhbAnalyticsSvc.widgets.show(w, refreshCache).then(
      (success) ->
        updatedWidget = success.data
        updatedWidget.content ||= {}

    return if _.isEmpty(newMetadata)
    data = { metadata: newMetadata }
    w.isLoading = true if needContentReload
    ImpacWidgetsSvc.update(w,data).then(
      (success) ->
        angular.extend(w,success.data)
        w.loadContent() if needContentReload
