MCPcopy Index your code
hub / github.com/JLiscom/OpenNote / save

Function save

openNote/controllers/noteController.js:121–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

119 * Save a note
120 */
121 var save = function() {
122 $(".notePartial").fadeOut(config.fadeSpeedShort(), function() {
123 $scope.note.type = "note";
124 $scope.note.note = $scope.editor.getValue();
125
126 /**
127 * Callback after successful save to reload note
128 */
129 var saveCallback = function(response) {
130 if (!response.ok){
131 alertify.error("There was an error saving the note");
132 console.error(response);
133 throw response;
134 }
135
136 detachWindowUnload();
137
138 //Tags
139 $scope.note._id = response.id;
140 $rootScope.$emit("noteSaved", $scope.note); //Let any number of services know we have saved a note
141
142 $location.url("/note/" + response.id + "?rev=" + response.rev); //revision number is here only to force angular to reload
143 alertify.success("Note Saved"); //all done. close the notify dialog
144 $scope.$apply();
145 };
146
147 //Upsert
148 if (!$scope.note._id)
149 storageService.post($scope.note).then(saveCallback, function() {
150 alertify.error("Error saving note");
151 });
152 else
153 storageService.put($scope.note).then(saveCallback, function() {
154 alertify.error("Error modifing note");
155 });
156 });
157 };
158
159 /**
160 * Delete a note

Callers 1

saveButtonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected