Add admin UI/backend for adding a new Service

This commit is contained in:
2011-12-21 02:16:37 +00:00
parent 411e22b48b
commit fd0b0e1a26
4 changed files with 72 additions and 2 deletions

View File

@@ -21,6 +21,14 @@ var sb = {
}); });
}, },
admin: {
init: function() {
}
},
usercp: { usercp: {
init: function() { init: function() {

View File

@@ -10,6 +10,16 @@ class StatusBoard_Service extends StatusBoard_DatabaseObject {
protected $sites = null; protected $sites = null;
public static function newService($name, $description) {
$new_service = new self();
$new_service->name = $name;
$new_service->description = $description;
$new_service->create();
return $new_service;
}
public function sites($ignore_cache = false) { public function sites($ignore_cache = false) {
if ($this->sites === null || $ignore_cache) { if ($this->sites === null || $ignore_cache) {
$this->sites = StatusBoard_Site::all_for_service($this); $this->sites = StatusBoard_Site::all_for_service($this);

View File

@@ -9,6 +9,35 @@ if ( ! $auth->isAuthenticated() || ! $auth->hasPermission(StatusBoard_Permission
throw new StatusBoard_Exception_NotAuthorised(); throw new StatusBoard_Exception_NotAuthorised();
} }
$activity = null;
$success = true;
if ($request->exists('do')) {
$activity = $request->get('do');
switch ($activity) {
case 'add-service': {
$name = StatusBoard_Main::issetelse($_POST['name'], 'Sihnon_Exception_InvalidParameters');
$description = StatusBoard_Main::issetelse($_POST['description'], 'Sihnon_Exception_InvalidParameters');
$service = StatusBoard_Service::newService($name, $description);
$messages[] = array(
'severity' => 'success',
'content' => 'The service was created succesfully.',
);
} break;
default: {
$messages[] = array(
'severity' => 'warning',
'content' => "The activity '{$activity}' is not supported.",
);
}
}
}
$this->smarty->assign('tab', $request->get('tab', 'admin')); $this->smarty->assign('tab', $request->get('tab', 'admin'));
$services = StatusBoard_Service::all(); $services = StatusBoard_Service::all();
@@ -21,5 +50,6 @@ $this->smarty->assign('users', $users);
$this->smarty->assign('debug_displayexceptions', $config->get('debug.display_exceptions')); $this->smarty->assign('debug_displayexceptions', $config->get('debug.display_exceptions'));
$this->smarty->assign('cache_basedir', $config->get('cache.base_dir')); $this->smarty->assign('cache_basedir', $config->get('cache.base_dir'));
$this->smarty->assign('templates_tmppath', $config->get('templates.tmp_path')); $this->smarty->assign('templates_tmppath', $config->get('templates.tmp_path'));
$this->smarty->assign('messages', $messages);
?> ?>

View File

@@ -28,8 +28,30 @@
You haven't created any services yet. Create some with the button below. You haven't created any services yet. Create some with the button below.
{/if} {/if}
<form id="admin_addservice" method="post" action="{$base_uri}admin/add-service/"> <form id="admin_addservice" method="post" action="{$base_uri}admin/tab/services/do/add-service/">
<input type="button" class="btn success" name="addservice" value="Add Service" /> <fieldset>
<legend>Add Service</legend>
<div class="clearfix">
<label for="admin_service_add_name">Name</label>
<div class="text">
<input class="xlarge span5" id="admin_service_add_name" name="name" type="text" value="" />
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<label for="admin_service_add_description">Description</label>
<div class="text">
<textarea class="span12" id="admin_service_add_description" name="description"></textarea>
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<div class="input">
<input type="submit" class="btn success" name="addservice" value="Add Service" />
</div>
</div>
</fieldset>
</form> </form>
</div> </div>