<button id="btn_job_actions" type="button" class="w3-bar-item w3-button tab_btn w3-grey" onclick="W3Tabs.open(this.id, 'job_actions'); job_callback_func(); oRunningJobStatus.init_refresh();"><%[ Actions ]%></button>
<com:TActiveLinkButton
CssClass="w3-bar-item w3-button tab_btn"
- Attributes.onclick="W3Tabs.open(this.id, 'job_config'); clear_node('#fileset_config div.directive_field'); clear_node('#schedule_config div.directive_field');"
+ Attributes.onclick="W3Tabs.open(this.id, 'job_config');"
Text="<%[ Configure job ]%>"
Visible="<%=!empty($_SESSION['dir'])%>"
OnClick="loadJobConfig"
/>
<com:TActiveLinkButton
CssClass="w3-bar-item w3-button tab_btn"
- Attributes.onclick="W3Tabs.open(this.id, 'fileset_config'); clear_node('#job_config div.directive_field'); clear_node('#schedule_config div.directive_field');"
+ Attributes.onclick="W3Tabs.open(this.id, 'fileset_config');"
Text="<%[ Configure fileset ]%>"
Visible="<%=!empty($_SESSION['dir'])%>"
OnClick="loadFileSetConfig"
/>
<com:TActiveLinkButton
CssClass="w3-bar-item w3-button tab_btn"
- Attributes.onclick="W3Tabs.open(this.id, 'schedule_config'); clear_node('#job_config div.directive_field'); clear_node('#fileset_config div.directive_field');"
+ Attributes.onclick="W3Tabs.open(this.id, 'schedule_config');"
Text="<%[ Configure schedule ]%>"
Visible="<%=!empty($_SESSION['dir'])%>"
OnClick="loadScheduleConfig"
ComponentType="dir"
ResourceType="Job"
ShowCancelButton="false"
+ OnSave="reloadJobInfo"
+ DisableRename="true"
/>
</div>
<div class="w3-container tab_item" id="fileset_config" style="display: none">
ResourceType="Fileset"
ShowRemoveButton="false"
ShowCancelButton="false"
+ OnSave="reloadJobInfo"
/>
</div>
<div class="w3-container tab_item" id="schedule_config" style="display: none">
ResourceType="Schedule"
ShowRemoveButton="false"
ShowCancelButton="false"
+ OnSave="reloadJobInfo"
/>
</div>
<div id="job_delete_confirm" class="w3-modal" style="display: none">
public function onInit($param) {
parent::onInit($param);
- $this->JobConfig->attachEventHandler('OnSave', [$this, 'reloadJobInfo']);
$job_name = $this->getJobName();
$this->RunJobModal->setJobId($this->getJobId());
$this->RunJobModal->setJobName($job_name);
/**
* Reload job information.
*
+ * @param BaculaConfigDirectives $sender sender object
* @param mixed $param save event parameter
* @return none
*/
- public function reloadJobInfo($param) {
+ public function reloadJobInfo($sender, $param) {
$job_name = $this->getJobName();
$this->setJobInfo($job_name);
}
$this->JobConfig->setResourceName($this->getJobName());
$this->JobConfig->setLoadValues(true);
$this->JobConfig->raiseEvent('OnDirectiveListLoad', $this, null);
+ $this->FileSetConfig->unloadDirectives();
+ $this->ScheduleConfig->unloadDirectives();
}
}
$this->FileSetConfig->setResourceName($job_info['fileset']['name']);
$this->FileSetConfig->setLoadValues(true);
$this->FileSetConfig->raiseEvent('OnDirectiveListLoad', $this, null);
+ $this->JobConfig->unloadDirectives();
+ $this->ScheduleConfig->unloadDirectives();
}
}
}
$this->ScheduleConfig->setResourceName($job_info['schedule']['name']);
$this->ScheduleConfig->setLoadValues(true);
$this->ScheduleConfig->raiseEvent('OnDirectiveListLoad', $this, null);
+ $this->JobConfig->unloadDirectives();
+ $this->FileSetConfig->unloadDirectives();
+ } else {
+ $this->ScheduleConfig->unloadDirectives();
}
}
}
<button id="btn_job_actions" type="button" class="w3-bar-item w3-button tab_btn w3-grey" onclick="W3Tabs.open(this.id, 'job_actions');"><%[ Actions ]%></button>
<com:TActiveLinkButton
CssClass="w3-bar-item w3-button tab_btn"
- Attributes.onclick="W3Tabs.open(this.id, 'job_config'); clear_node('#fileset_config div.directive_field'); clear_node('#schedule_config div.directive_field');"
+ Attributes.onclick="W3Tabs.open(this.id, 'job_config')"
Text="<%[ Configure job ]%>"
Visible="<%=!empty($_SESSION['dir'])%>"
OnClick="loadJobConfig"
/>
<com:TActiveLinkButton
CssClass="w3-bar-item w3-button tab_btn"
- Attributes.onclick="W3Tabs.open(this.id, 'fileset_config'); clear_node('#job_config div.directive_field'); clear_node('#schedule_config div.directive_field');"
+ Attributes.onclick="W3Tabs.open(this.id, 'fileset_config')"
Text="<%[ Configure fileset ]%>"
Visible="<%=!empty($_SESSION['dir'])%>"
OnClick="loadFileSetConfig"
/>
<com:TActiveLinkButton
CssClass="w3-bar-item w3-button tab_btn"
- Attributes.onclick="W3Tabs.open(this.id, 'schedule_config'); clear_node('#job_config div.directive_field'); clear_node('#fileset_config div.directive_field');"
+ Attributes.onclick="W3Tabs.open(this.id, 'schedule_config')"
Text="<%[ Configure schedule ]%>"
Visible="<%=!empty($_SESSION['dir'])%>"
OnClick="loadScheduleConfig"
CssClass="w3-bar-item w3-button tab_btn"
Text="<%[ Job schedules ]%>"
OnCallback="loadSchedules"
- Attributes.onclick="W3Tabs.open(this.id, 'job_schedules'); clear_node('#job_config div.directive_field'); clear_node('#fileset_config div.directive_field'); clear_node('#schedule_config div.directive_field');"
+ Attributes.onclick="W3Tabs.open(this.id, 'job_schedules');"
/>
</div>
<div class="w3-container tab_item" id="job_actions">
ComponentType="dir"
ResourceType="Job"
ShowCancelButton="false"
+ OnSave="reloadJobInfo"
+ DisableRename="true"
/>
</div>
<div class="w3-container tab_item" id="fileset_config" style="display: none">
ResourceType="Fileset"
ShowRemoveButton="false"
ShowCancelButton="false"
+ OnSave="reloadJobInfo"
/>
</div>
<div class="w3-container tab_item" id="schedule_config" style="display: none">
ResourceType="Schedule"
ShowRemoveButton="false"
ShowCancelButton="false"
+ OnSave="reloadJobInfo"
/>
</div>
<div class="w3-container tab_item" id="job_history" style="display: none">
public function onInit($param) {
parent::onInit($param);
- $this->JobConfig->attachEventHandler('OnSave', [$this, 'reloadJobInfo']);
if ($this->IsCallBack || $this->IsPostBack) {
return;
}
/**
* Reload job information.
*
+ * @param BaculaConfigDirectives $sender sender object
* @param mixed $param save event parameter
* @return none
*/
- public function reloadJobInfo($param) {
+ public function reloadJobInfo($sender, $param) {
if ($this->Request->contains('job')) {
$this->setJobInfo($this->Request['job']);
}
$this->JobConfig->setResourceName($this->getJobName());
$this->JobConfig->setLoadValues(true);
$this->JobConfig->raiseEvent('OnDirectiveListLoad', $this, null);
+ $this->FileSetConfig->unloadDirectives();
+ $this->ScheduleConfig->unloadDirectives();
}
}
$this->FileSetConfig->setResourceName($job_info['fileset']['name']);
$this->FileSetConfig->setLoadValues(true);
$this->FileSetConfig->raiseEvent('OnDirectiveListLoad', $this, null);
+ $this->JobConfig->unloadDirectives();
+ $this->ScheduleConfig->unloadDirectives();
}
}
}
$this->ScheduleConfig->setResourceName($job_info['schedule']['name']);
$this->ScheduleConfig->setLoadValues(true);
$this->ScheduleConfig->raiseEvent('OnDirectiveListLoad', $this, null);
+ $this->JobConfig->unloadDirectives();
+ $this->FileSetConfig->unloadDirectives();
} else {
$this->ScheduleConfig->unloadDirectives();
}
const SHOW_ALL_DIRECTIVES = 'ShowAllDirectives';
const SHOW_BOTTOM_BUTTONS = 'ShowBottomButtons';
const SAVE_DIRECTIVE_ACTION_OK = 'SaveDirectiveActionOk';
+ const DISABLE_RENAME = 'DisableRename';
private $show_all_directives = false;
$predefined = true;
}
}
-
$data_desc = $this->Application->getModule('data_desc');
$resource_desc = $data_desc->getDescription($component_type, $resource_type);
foreach ($resource_desc as $directive_name => $directive_desc) {
}
$directive_name = $controls[$j]->getDirectiveName();
$directive_value = $controls[$j]->getDirectiveValue();
+
$default_value = null;
if (key_exists($directive_name, $resource_desc)) {
$default_value = $resource_desc[$directive_name]->DefaultValue;
}
}
$load_values = $this->getLoadValues();
+ $res_name_dir = key_exists('Name', $directives) ? $directives['Name'] : '';
+ $resource_name = $this->getResourceName();
if ($load_values === true) {
- $resource_name = $this->getResourceName();
+ if ($resource_name !== $res_name_dir) {
+ // RENAME RESOURCE
+ if ($this->renameResource($res_name_dir)) {
+ // set new resource name
+ $this->setResourceName($res_name_dir);
+ $resource_name = $res_name_dir;
+ }
+ }
} else {
- $resource_name = array_key_exists('Name', $directives) ? $directives['Name'] : '';
+ $resource_name = $res_name_dir;
}
$params = array(
}
}
+ /**
+ * Rename resource.
+ * This rename method takes into account resource dependencies
+ * and updates them as well.
+ *
+ * @param string $new_resource_name new resource name to set
+ * @return boolean true on success, false on failure
+ */
+ public function renameResource($resource_name_new) {
+ $success = true;
+ $component_type = $this->getComponentType();
+ if (empty($_SESSION[$component_type])) {
+ return false;
+ }
+ $host = null;
+ $resource_type = $this->getResourceType();
+ $resource_name = $this->getResourceName();
+ $config = $this->getConfigData($host, array($component_type));
+ $deps = $this->getModule('data_deps')->checkDependencies(
+ $component_type,
+ $resource_type,
+ $resource_name,
+ $config
+ );
+ $this->renameResourceInConfig(
+ $config,
+ $deps,
+ $resource_type,
+ $resource_name,
+ $resource_name_new,
+ );
+ $result = $this->getModule('api')->set(
+ array('config', $component_type),
+ array('config' => json_encode($config)),
+ $host,
+ false
+ );
+ if ($result->error != 0) {
+ $success = false;
+ $emsg = 'Error while renaming resource: ' . $result->output;
+ $this->Application->getModule('logging')->log(
+ __FUNCTION__,
+ $emsg,
+ Logging::CATEGORY_APPLICATION,
+ __FILE__,
+ __LINE__
+ );
+ }
+ return $success;
+ }
+
+ /**
+ * Rename resource in config.
+ * Note, passing config by reference.
+ *
+ * @param array $config entire config
+ * @param string $resource_type resource type to rename
+ * @param string $resource_name resource name to rename
+ * @param string $resource_name_new new resource name to set
+ * @return none
+ */
+ private function renameResourceInConfig(&$config, $deps, $resource_type, $resource_name, $resource_name_new) {
+ for ($i = 0; $i < count($config); $i++) {
+ foreach ($config[$i] as $rtype => $resource) {
+ for ($j = 0; $j < count($deps); $j++) {
+ if ($rtype === $deps[$j]['resource_type'] && $resource->Name === $deps[$j]['resource_name']) {
+ // Change resource name in dependent resources
+ $config[$i]->{$rtype}->{$deps[$j]['directive_name']} = $resource_name_new;
+ }
+ }
+ if ($rtype === $resource_type && $resource->Name === $resource_name) {
+ // Change resource name
+ $config[$i]->{$rtype}->Name = $resource_name_new;
+ }
+ }
+ }
+ }
+
/**
* Set if remove button should be available.
*
public function onSave($param) {
$this->raiseEvent('OnSave', $this, $param);
}
+
+ /**
+ * Set if name field should be disabled.
+ *
+ * @return none;
+ */
+ public function setDisableRename($rename) {
+ $rename = TPropertyValue::ensureBoolean($rename);
+ $this->setViewState(self::DISABLE_RENAME, $rename);
+ }
+
+ /**
+ * Get if name field should be disabled.
+ *
+ * @return bool true if field is disabled, otherwise false
+ */
+ public function getDisableRename() {
+ return $this->getViewState(self::DISABLE_RENAME, false);
+ }
}
?>
$control->setGroupName($data['group_name']);
$control->setParentName($data['parent_name']);
$control->setResourceNames($this->SourceTemplateControl->getResourceNames());
+ if ($data['directive_name'] === 'Name') {
+ $control->setDisabled($this->SourceTemplateControl->getDisableRename());
+ }
} elseif (in_array($type, $this->directive_list_types)) {
$control->setHost($data['host']);
$control->setComponentType($data['component_type']);
const IS_DIRECTIVE_CREATED = 'IsDirectiveCreated';
const VALIDATION_GROUP = 'ValidationGroup';
const CSSCLASS = 'CssClass';
+ const DISABLED = 'Disabled';
public $display_directive;
public function setCssClass($cssclass) {
$this->setViewState(self::CSSCLASS, $cssclass);
}
+
+ public function getDisabled() {
+ return $this->getViewState(self::DISABLED);
+ }
+
+ public function setDisabled($disabled) {
+ $disabled = TPropertyValue::ensureBoolean($disabled);
+ $this->setViewState(self::DISABLED, $disabled);
+ }
}
?>
}
}
$this->Directive->setText($directive_value);
+ if ($this->getDisabled()) {
+ $this->Directive->setReadOnly(true);
+ }
$validate = $this->getRequired();
$this->DirectiveValidator->setVisible($validate);
$cssclass = $this->getCssClass();