如何在malhar角度小部件上保存样式更改?

时间:2015-12-07 13:24:48

标签: javascript angularjs angular-module

我在AngularJS应用程序中安装了malhar-angular-dashboard模块。 我配置了一个显式保存的布局。 问题是我无法弄清楚如何保存小部件样式的更改。 关闭我的模型设置窗口后,我想更改并保存 contentStyle 的背景(背景:红色)

的JavaScript

'use strict';

angular.module('widget-area')

.factory('widgetDefinitions', function() {
return [
  {
    name: 'widgetComments', // attr required
    title:' ',
    templateUrl: 'views/dashboards/widget-area/sarciniPrimiteComentarii.html',
    settingsModalOptions:{
      templateUrl: 'views/dashboards/widget-area/modalSettings/widgetCommentsModalTmpl.html',
      controller:'widgetCommentsCtrl'
    },
    onSettingsClose: function(resultFromModal, widgetModel, dashboardScope) {
      // do something to update widgetModel, like the default implementation:
      //jQuery.extend(true, widget, result);
      widgetModel.contentStyle = {
        background:'red'
      };
      // something here to save the state
    },
    size: {
      width: '100%',
      height: '250px'
    }
  },
  {
    name: 'widgetInfoSarciniPrimite', // attr required
    title:' ',
    templateUrl: 'views/dashboards/widget-area/infoSarciniPrimite.html'
  },
  {
    name: 'widgetInfoColaborare', // attr required
    title:' ',
    templateUrl: 'views/dashboards/widget-area/infoColaborariSarciniPrimite.html'
  },
  {
    name:'widgetTest',
    title:' titleTest ',
    template:'<div><h2>Widget {{widget.title}}</h2></div>'
  }
];
})
.factory('defaultWidgets', function() {
return [
  {name: 'widgetComments'}, //attr required
  {name: 'widgetInfoSarciniPrimite'},
  {name: 'widgetInfoColaborare'},
  {name: 'widgetTest'}
];
})
.controller('widgetCtrl',['$scope','$interval', '$window','$translate','widgetDefinitions','defaultWidgets',
function($scope,$interval,$window,$translate,widgetDefinitions,defaultWidgets){

  $scope.layoutOptions = { // layout with explicit save
    storageId: 'demo-layouts-explicit-save',
    storage: localStorage,
    storageHash: 'fs4df4d51',
    widgetDefinitions: widgetDefinitions,
    defaultWidgets: defaultWidgets,
    explicitSave: true,
    defaultLayouts: [
      { title: 'Layout 1', active: true , defaultWidgets: defaultWidgets },
      { title: 'Layout 2', active: false, defaultWidgets: defaultWidgets },
      { title: 'Layout 3', active: false, defaultWidgets: defaultWidgets }
    ]
  };
}]);

1 个答案:

答案 0 :(得分:2)

必须覆盖小部件定义对象中的序列化(功能)并包含我要序列化的属性: contentStyle

  

此功能将确定如何保存小部件的状态

.factory('widgetDefinitions',function(){
   return [
     {
        {
          name: 'widgetInfoSarciniPrimite', // attr required
          title:' ',
          templateUrl: 'views/dashboards/widget-area/infoSarciniPrimite.html',
          serialize: function() {
             return _.pick(this, ['title', 'name', 'style', 'size', 'contentStyle', 'dataModelOptions', 'attrs', 'storageHash']);
          }
         }
     }
   ];
})