mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
[Edit] Allow inline-editing the name only if the object is editable
Made the contenteditable attribute conditional based on whether the object can be edited or not. If the object is not editable, the attribute is removed. Add Tests. Fixes #1746
This commit is contained in:
@ -32,7 +32,8 @@ define(
|
||||
*/
|
||||
function ObjectHeaderController($scope) {
|
||||
this.$scope = $scope;
|
||||
$scope.editing = false;
|
||||
this.domainObject = $scope.domainObject;
|
||||
this.editable = this.allowEdit();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,18 +46,16 @@ define(
|
||||
var name = event.currentTarget.innerHTML;
|
||||
|
||||
if (name.length === 0) {
|
||||
name = "Unnamed " + this.$scope.domainObject.getCapability("type").typeDef.name;
|
||||
name = "Unnamed " + this.domainObject.getCapability("type").typeDef.name;
|
||||
event.currentTarget.innerHTML = name;
|
||||
}
|
||||
|
||||
if (name !== this.$scope.domainObject.model.name) {
|
||||
this.$scope.domainObject.getCapability('mutation').mutate(function (model) {
|
||||
this.domainObject.getCapability('mutation').mutate(function (model) {
|
||||
model.name = name;
|
||||
});
|
||||
}
|
||||
|
||||
this.$scope.editing = false;
|
||||
|
||||
if (event.which === 13) {
|
||||
event.currentTarget.blur();
|
||||
}
|
||||
@ -64,10 +63,14 @@ define(
|
||||
};
|
||||
|
||||
/**
|
||||
* Marks the status of the field as editing.
|
||||
* Checks if the domain object is editable.
|
||||
*
|
||||
* @private
|
||||
* @return true if object is editable
|
||||
*/
|
||||
ObjectHeaderController.prototype.edit = function () {
|
||||
this.$scope.editing = true;
|
||||
ObjectHeaderController.prototype.allowEdit = function () {
|
||||
var type = this.domainObject && this.domainObject.getCapability('type');
|
||||
return !!(type && type.hasFeature('creation'));
|
||||
};
|
||||
|
||||
return ObjectHeaderController;
|
||||
|
Reference in New Issue
Block a user