| 
73 | 73 |         SimpleToast('ERROR', 'ERROR: There is already a project');  | 
74 | 74 |         return;  | 
75 | 75 |       }  | 
76 |  | - | 
 | 76 | +        | 
77 | 77 |       this.createNew(projectTitle, $rootScope.r);  | 
78 | 78 |     };  | 
79 | 79 | 
 
  | 
 | 
100 | 100 | 
 
  | 
101 | 101 |     this.createNew = (projectTitle, data) => {  | 
102 | 102 |       if (projectTitle && angular.isObject(data)) {  | 
 | 103 | +        data = $window._.omit(data, OMITTED_LS_FIELDS);  | 
 | 104 | +            | 
103 | 105 |         // save new project  | 
104 | 106 |         let newProject = {  | 
105 | 107 |           title: projectTitle,  | 
106 | 108 |           id: Uid(),  | 
107 |  | -          data: $window._.omit(LS_DEFAULTS, OMITTED_LS_FIELDS)  | 
 | 109 | +          data: {}  | 
108 | 110 |         };  | 
 | 111 | +            | 
 | 112 | +        this.updateNewFields(newProject);  | 
 | 113 | +            | 
 | 114 | +        // update data for current new project from current data  | 
 | 115 | +        for (let field in data) {  | 
 | 116 | +            newProject.data[field] = data[field];  | 
 | 117 | +        }  | 
109 | 118 | 
 
  | 
110 | 119 |         // update $rootScope.r.projects  | 
111 | 120 |         $rootScope.r.projects.push(newProject);  | 
 | 
115 | 124 |         projects.push(newProject);  | 
116 | 125 |         AppStorage.saveProjects(projects);  | 
117 | 126 | 
 
  | 
118 |  | -        // update data for current new project from current data  | 
119 |  | -        this.updateProjectData(newProject.id, data);  | 
120 |  | - | 
121 | 127 |         // switch to new project  | 
122 | 128 |         this.changeCurrent(newProject);  | 
123 | 129 |       }  | 
 | 
161 | 167 |         this.removeOmittedFields(newCurrentProject);  | 
162 | 168 | 
 
  | 
163 | 169 |         // clean up $rootScope.r  | 
164 |  | -        _.forOwn($rootScope, (val, property) => {  | 
 | 170 | +        _.forOwn($rootScope.r, (val, property) => {  | 
165 | 171 |           if (!angular.isFunction(val) && GLOBAL_LS_FIELDS.indexOf(property) === -1) {  | 
166 |  | -            $rootScope.r[property] = undefined;  | 
 | 172 | +            delete $rootScope.r[property];  | 
167 | 173 |           }  | 
168 | 174 |         });  | 
169 | 175 | 
 
  | 
 | 
173 | 179 |             $rootScope.r[property] = newCurrentProject.data[property];  | 
174 | 180 |           }  | 
175 | 181 |         });  | 
176 |  | - | 
 | 182 | +           | 
177 | 183 |         // update ls current project  | 
178 | 184 |         $rootScope.r.currentProject = newCurrentProject;  | 
179 | 185 |         $rootScope.$broadcast(EV_PROJECT_CHANGED);  | 
 | 
0 commit comments