 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

  w.updateSettings = (needContentReload=true) ->
    meta = {}
    angular.forEach(w.settings, (setting) ->
      extendDeep(meta,setting.toMetadata())
    )
    pushMetadata(meta, needContentReload) if !_.isEmpty(meta)
    return true

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