2017-10-23 16:50:48 -07:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { get, set } from '@ember/object';
|
2017-11-01 09:10:42 -07:00
|
|
|
import { run, next } from '@ember/runloop';
|
2017-10-20 21:34:58 -07:00
|
|
|
import {
|
|
|
|
baseCommentEditorOptions,
|
|
|
|
exemptPolicy,
|
|
|
|
isExempt,
|
|
|
|
PurgePolicy,
|
|
|
|
purgePolicyProps
|
|
|
|
} from 'wherehows-web/constants';
|
2017-10-19 18:17:16 -07:00
|
|
|
import noop from 'wherehows-web/utils/noop';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
exemptPolicy,
|
|
|
|
|
|
|
|
purgePolicyProps,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The dataset's platform
|
|
|
|
*/
|
|
|
|
platform: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently save policy for the dataset purge
|
|
|
|
*/
|
2017-10-23 16:50:48 -07:00
|
|
|
purgePolicy: <PurgePolicy>'',
|
|
|
|
|
|
|
|
requestExemptionReason: false,
|
2017-10-19 18:17:16 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An options hash for the purge exempt reason text editor
|
|
|
|
* @type {}
|
|
|
|
*/
|
|
|
|
editorOptions: {
|
|
|
|
...baseCommentEditorOptions,
|
|
|
|
placeholder: {
|
2017-11-01 09:10:42 -07:00
|
|
|
text: 'Please provide an explanation for why this dataset is marked "Purge Exempt" status',
|
|
|
|
hideOnClick: false
|
2017-10-19 18:17:16 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to handle policy change, by default a no-op function
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
onPolicyChange: noop,
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.checkExemption(get(this, 'purgePolicy'));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks that the selected purge policy is exempt, if so, set the
|
|
|
|
* flag to request the exemption to true
|
|
|
|
* @param {PurgePolicy} purgePolicy
|
|
|
|
*/
|
|
|
|
checkExemption(purgePolicy: PurgePolicy) {
|
|
|
|
const exemptionReasonRequested = isExempt(purgePolicy);
|
|
|
|
set(this, 'requestExemptionReason', exemptionReasonRequested);
|
2017-11-01 09:10:42 -07:00
|
|
|
|
|
|
|
if (exemptionReasonRequested) {
|
|
|
|
// schedule for a future queue, 'likely' post render
|
|
|
|
// this allows us to ensure that editor it visible after the set above has been performed
|
|
|
|
run(() => next(this, 'focusEditor'));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies cursor / document focus to the purge note text editor
|
|
|
|
*/
|
|
|
|
focusEditor() {
|
|
|
|
const exemptionReasonElement = <HTMLElement>get(this, 'element').querySelector('.comment-new__content');
|
|
|
|
|
|
|
|
if (exemptionReasonElement) {
|
|
|
|
exemptionReasonElement.focus();
|
|
|
|
}
|
2017-10-19 18:17:16 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
/**
|
|
|
|
* Handles the change to the currently selected purge policy
|
|
|
|
* @param {string} _name unused name for the radio group
|
|
|
|
* @param {PurgePolicy} purgePolicy the selected purge policy
|
|
|
|
*/
|
|
|
|
onChange(_name: string, purgePolicy: PurgePolicy) {
|
|
|
|
return get(this, 'onPolicyChange')(purgePolicy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|