mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 19:41:15 -03:00
web_config: add support for adding and editing abbreviations
Possible future enhancements include explanatory text and an image for the 'save' action. Work on #731.
This commit is contained in:
@@ -287,10 +287,45 @@ controllers.controller("bindingsController", function($scope, $http) {
|
||||
|
||||
controllers.controller("abbreviationsController", function($scope, $http) {
|
||||
$scope.abbreviations = [];
|
||||
$scope.addBlank = function() {
|
||||
// Add blank entry if it is missing
|
||||
hasBlank = {hasBlank: false}
|
||||
angular.forEach($scope.abbreviations, function(value, key) {
|
||||
if (value.phrase === "" && value.word === "") {
|
||||
this.hasBlank = true;
|
||||
}
|
||||
}, hasBlank);
|
||||
if (! hasBlank.hasBlank) {
|
||||
$scope.abbreviations.push({phrase: "", word: "", editable: true})
|
||||
}
|
||||
}
|
||||
$scope.fetchAbbreviations = function() {
|
||||
$http.get("abbreviations/").success(function(data, status, headers, config) {
|
||||
$scope.abbreviations = data;
|
||||
$scope.addBlank();
|
||||
})};
|
||||
|
||||
$scope.editAbbreviation = function(abbreviation) {
|
||||
abbreviation.editable = true;
|
||||
}
|
||||
|
||||
$scope.saveAbbreviation = function(abbreviation) {
|
||||
if (abbreviation.word && abbreviation.phrase) {
|
||||
$http.post("save_abbreviation/", abbreviation).success(function(data, status, headers, config) {
|
||||
abbreviation.editable = false;
|
||||
$scope.addBlank();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.removeAbbreviation = function(abbreviation) {
|
||||
if (abbreviation.word) {
|
||||
$http.post("remove_abbreviation/", abbreviation).success(function(data, status, headers, config) {
|
||||
$scope.abbreviations.splice($scope.abbreviations.indexOf(abbreviation), 1);
|
||||
$scope.addBlank();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.fetchAbbreviations();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user