Skip to content

Commit

Permalink
Fixed Notification of dirty metadata when moving from one file to ano…
Browse files Browse the repository at this point in the history
…ther while there are unsaved changes in the metadata editor. Window refresh and back button are not intercepted yet (how to do this??)
  • Loading branch information
silvae86 committed Nov 8, 2017
1 parent 9172651 commit dd5db69
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
3 changes: 2 additions & 1 deletion public/app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var dendroApp = angular.module("dendroApp", [
startTrackingWithGoogleAnalytics(dendroApp);
}
);
}]).run(function ($http, $rootScope)
}]).run(function ($http, $rootScope, $window)
{
$http.get("/shared/public_config.json")
.then(function (response)
Expand All @@ -84,3 +84,4 @@ var dendroApp = angular.module("dendroApp", [
console.log("Unable to load remote config");
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ angular.module("dendroApp.controllers")
windowService.get_change_log();
}
}
});
}, $scope.dirty_metadata());
};

$scope.select_item_in_folder_browser = function (index)
Expand Down Expand Up @@ -579,7 +579,7 @@ angular.module("dendroApp.controllers")
}
);
}
});
}, $scope.dirty_metadata());
};

$scope.toggle_show_deleted_files = function ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,6 @@ angular.module("dendroApp.controllers")
});
};

$scope.dirty_metadata = function ()
{
return metadataService.dirty_metadata(
$scope.shared.initial_metadata,
$scope.shared.metadata
);
};

$scope.inherit_metadata = function ()
{
var requestUri = $scope.get_calling_uri("?parent_metadata");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ angular.module("dendroApp.controllers")
$scope.shared.metadata = metadataService.deserialize_metadata(metadata.descriptors);
$scope.shared.metadata = $filter("filter")($scope.shared.metadata, $scope.only_editable_metadata_descriptors);
$scope.shared.initial_metadata = metadataService.deserialize_metadata(metadata.descriptors);
$scope.shared.initial_metadata = $filter("filter")($scope.shared.initial_metadata, $scope.only_editable_metadata_descriptors);
$scope.shared.is_project_root = metadata.is_project_root;
$scope.shared.is_a_file = metadata.is_a_file;
$scope.shared.file_extension = metadata.file_extension;
Expand Down Expand Up @@ -526,6 +527,14 @@ angular.module("dendroApp.controllers")
}
};

$scope.dirty_metadata = function ()
{
return metadataService.dirty_metadata(
$scope.shared.initial_metadata,
$scope.shared.metadata
);
};

// initialization
$scope.init = function ()
{
Expand All @@ -537,16 +546,44 @@ angular.module("dendroApp.controllers")
$scope.recommendationService = recommendationService;

// monitor url change events (ask to save if metadata changed)
$scope.$on("$routeChangeStart", function (next, current)
{
console.log("Changing location from " + current + " to " + next);
$scope.shared.initial_metadata = $filter("filter")($scope.shared.initial_metadata, $scope.only_editable_metadata_descriptors);
$scope.shared.metadata = $filter("filter")($scope.shared.metadata, $scope.only_editable_metadata_descriptors);
$scope.change_location(next,
metadataService.dirty_metadata(
$scope.shared.initial_metadata,
$scope.shared.metadata
));

window.onbeforeunload = function (event) {
event.preventDefault();
if ($scope.dirty_metadata())
{
$scope.confirm_change_of_resource_being_edited(function(confirmed)
{
if (confirmed)
{
$scope.change_location(next,
metadataService.dirty_metadata(
$scope.shared.initial_metadata,
$scope.shared.metadata
));
}
}, $scope.dirty_metadata());
}
};

$scope.$on('$locationChangeStart', function(event, next, current) {
if ($scope.dirty_metadata())
{
$scope.confirm_change_of_resource_being_edited(function(confirmed)
{
if (confirmed)
{
$scope.change_location(next,
metadataService.dirty_metadata(
$scope.shared.initial_metadata,
$scope.shared.metadata
));
}
else
{
event.preventDefault();
}
}, $scope.dirty_metadata());
}
});

$scope.load_metadata().then(
Expand Down

0 comments on commit dd5db69

Please sign in to comment.