6ce403407b400d5ecc1d2370194071529b1add10
[dlux.git] / modules / common-yangutils-resources / src / main / resources / yangutils / services / data-backup.services.js
1 define([], function () {
2     'use strict';
3
4     function DataBackupService(){
5         var bck = {};
6
7         bck.storedData = {};
8
9         var getKey = function(key) {
10             return key || 'DEFAULT';
11         };
12
13         bck.storeFromScope = function(variables, scope, key) {
14             var data = {};
15             key = getKey(key);
16
17             variables.forEach(function(k) {
18                 if(scope.hasOwnProperty(k)) {
19                     data[k] = scope[k];
20                 } else {
21                     console.warn('scope doesn\'t have variable',k);
22                 }
23             });
24             bck.storedData[key] = data;
25         };
26
27         bck.getToScope = function(variables, scope, key) {
28             var data = {};
29
30             key = getKey(key);
31             if(bck.storedData.hasOwnProperty(key)) {
32                 data = bck.storedData[key];
33
34                 variables.forEach(function(k) {
35                     if(data.hasOwnProperty(k)) {
36                         scope[k] = data[k];
37                     } else {
38                         console.warn('storet data doesn\'t have variable',k);
39                     }
40                 });
41             }
42         };
43
44         return bck;
45     }
46
47     DataBackupService.$inject=[];
48
49     return DataBackupService;
50
51 });