From 43bc68c732338be2e82c5c516f20704e12d82a7c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 4 Feb 2015 17:58:01 +0100 Subject: Finish config module editing --- apis/taskmanager.inc.php | 1 + inc/up_json_encode.php | 7 +++++ lang/de/messages.json | 1 + lang/en/messages.json | 1 + modules/sysconfig.inc.php | 35 ++++++++++++++++++++++++ modules/sysconfig/addmodule.inc.php | 2 ++ modules/sysconfig/addmodule_branding.inc.php | 2 +- modules/sysconfig/addmodule_custommodule.inc.php | 27 +++++++++++++++--- script/custom.js | 19 ++++++++----- templates/sysconfig/_page.html | 34 ++++++++++++++++++++--- templates/sysconfig/custom-fileselect.html | 3 +- templates/sysconfig/custom-upload.html | 1 + 12 files changed, 116 insertions(+), 17 deletions(-) diff --git a/apis/taskmanager.inc.php b/apis/taskmanager.inc.php index 102352d2..c7cdb881 100644 --- a/apis/taskmanager.inc.php +++ b/apis/taskmanager.inc.php @@ -32,4 +32,5 @@ foreach ($_POST['ids'] as $id) { } } +Header('Content-Type: application/json'); echo json_encode(array('tasks' => $return)); diff --git a/inc/up_json_encode.php b/inc/up_json_encode.php index 28556923..c33cb012 100644 --- a/inc/up_json_encode.php +++ b/inc/up_json_encode.php @@ -1,5 +1,10 @@ fetch(PDO::FETCH_ASSOC)) { + $outMods[] = $row['moduleid']; + } + // Confs + $string = '0'; + foreach ($confs as $conf) { + if (is_numeric($conf)) + $string .= ',' . $conf; + } + $res = Database::simpleQuery("SELECT configid FROM configtgz WHERE configid in ($string) AND status = 'OK'"); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $outConfs[] = $row['configid']; + } + Header('Content-Type: application/json'); + die(json_encode(array('mods' => $outMods, 'confs' => $outConfs))); + } + } /** * List all configurations and configuration modules. diff --git a/modules/sysconfig/addmodule.inc.php b/modules/sysconfig/addmodule.inc.php index 5e9ecb3a..31f3823a 100644 --- a/modules/sysconfig/addmodule.inc.php +++ b/modules/sysconfig/addmodule.inc.php @@ -100,6 +100,8 @@ abstract class AddModule_Base if (self::$instance === false) { Util::traceError('No step instance yet'); } + if (self::$instance->edit !== false) + Message::addInfo('replacing-module', self::$instance->edit->title ()); self::$instance->renderInternal(); } diff --git a/modules/sysconfig/addmodule_branding.inc.php b/modules/sysconfig/addmodule_branding.inc.php index 527b2e7b..7fc7abc5 100644 --- a/modules/sysconfig/addmodule_branding.inc.php +++ b/modules/sysconfig/addmodule_branding.inc.php @@ -58,7 +58,7 @@ class Branding_ProcessFile extends AddModule_Base 'tarFile' => $this->tarFile, 'svgFile' => $this->svgFile )); - $this->task = Taskmanager::waitComplete($this->task); + $this->task = Taskmanager::waitComplete($this->task, 5000); if (Taskmanager::isFailed($this->task)) { @unlink($this->svgFile); Taskmanager::addErrorMessage($this->task); diff --git a/modules/sysconfig/addmodule_custommodule.inc.php b/modules/sysconfig/addmodule_custommodule.inc.php index bd66f417..dfa03a19 100644 --- a/modules/sysconfig/addmodule_custommodule.inc.php +++ b/modules/sysconfig/addmodule_custommodule.inc.php @@ -13,7 +13,8 @@ class CustomModule_Start extends AddModule_Base { Session::set('mod_temp', false); Render::addDialog(Dictionary::translate('config-module', 'custom_title'), false, 'sysconfig/custom-upload', array( - 'step' => 'CustomModule_ProcessUpload' + 'step' => 'CustomModule_ProcessUpload', + 'edit' => $this->edit ? $this->edit->id() : false )); } @@ -84,9 +85,17 @@ class CustomModule_ProcessUpload extends AddModule_Base $list[] = $file; } } + if ($this->edit !== false) + $title = $this->edit->title(); + elseif (isset($_FILES['modulefile']['name'])) + $title = basename($_FILES['modulefile']['name']); + else + $title = ''; Render::addDialog(Dictionary::translate('config-module', 'custom_title'), false, 'sysconfig/custom-fileselect', array( 'step' => 'CustomModule_CompressModule', 'files' => $list, + 'edit' => $this->edit ? $this->edit->id() : false, + 'title' => $title )); Session::save(); } @@ -123,20 +132,30 @@ class CustomModule_CompressModule extends AddModule_Base $this->taskError($status); } // Seems ok, create entry - $module = ConfigModule::getInstance('CustomModule'); + if ($this->edit === false) + $module = ConfigModule::getInstance('CustomModule'); + else + $module = $this->edit; if ($module === false) { Message::addError('error-read', 'custommodule.inc.php'); Util::redirect('?do=SysConfig&action=addmodule&step=CustomModule_Start'); } $module->setData('tmpFile', $destFile); - if (!$module->insert($title)) + if ($this->edit !== false) + $ret = $module->update(); + else + $ret = $module->insert($title); + if (!$ret) Util::redirect('?do=SysConfig&action=addmodule&step=CustomModule_Start'); elseif (!$module->generate(true, NULL, 200)) Util::redirect('?do=SysConfig&action=addmodule&step=CustomModule_Start'); Session::set('mod_temp', false); Session::save(); // Yay - Message::addSuccess('module-added'); + if ($this->edit !== false) + Message::addSuccess('module-edited'); + else + Message::addSuccess('module-added'); Util::redirect('?do=SysConfig'); } diff --git a/script/custom.js b/script/custom.js index 675bf581..b2c5b2a7 100644 --- a/script/custom.js +++ b/script/custom.js @@ -13,15 +13,20 @@ function loadContent(elem, source) function forceTable(t) { var pwidth = t.parent().innerWidth(); - t.width(pwidth - 5); var rows = t.find('tr'); + var row = rows.first(); + pwidth = Math.round(pwidth); + t.width(pwidth); var sum = 0; - rows.first().find('td').each(function (index) { + row.find('td').each(function() { if (!$(this).hasClass('slx-width-ignore')) - sum += $(this).outerWidth(); - }); - var w = pwidth - (sum + 30); - rows.find('.slx-dyn-ellipsis').each(function (index) { - $(this).width(w).css('width', w + 'px').css('max-width', w + 'px'); + sum += $(this).outerWidth(true); }); + var w = Math.round(pwidth - sum); + do { + rows.find('.slx-dyn-ellipsis').each(function() { + $(this).width(w).css('width', w + 'px').css('max-width', w + 'px'); + }); + w -= 3; + } while (t.width() > pwidth); } \ No newline at end of file diff --git a/templates/sysconfig/_page.html b/templates/sysconfig/_page.html index 93169e6a..2f46f2cf 100644 --- a/templates/sysconfig/_page.html +++ b/templates/sysconfig/_page.html @@ -30,10 +30,10 @@ @@ -88,10 +88,10 @@ @@ -187,4 +187,30 @@ $(e).addClass("slx-bold"); } } + + var statusChecks = 0; + function checkBuildStatus() { + var mods = []; + var confs = []; + $(".refmod.btn-primary").each(function (index) { + mods.push($(this).val()); + }); + $(".refconf.btn-primary").each(function (index) { + confs.push($(this).val()); + }); + if (mods.length === 0 && confs.length === 0) return; + if (++statusChecks < 10) setTimeout(checkBuildStatus, 200 + 50 * statusChecks); + console.log("POSTING"); + $.post('?do=SysConfig', { mods: mods.join(), confs: confs.join(), token: TOKEN, action: 'status' }, function (data) { + if (typeof data === 'undefined') return; + if (typeof data.mods === 'object') updateButtonColor($(".refmod.btn-primary"), data.mods); + if (typeof data.confs === 'object') updateButtonColor($(".refconf.btn-primary"), data.confs); + }, 'json'); + } + function updateButtonColor(list,ids) { + list.each(function() { + if (ids.indexOf($(this).val()) >= 0) $(this).removeClass('btn-primary').addClass('btn-default'); + }); + } + setTimeout(checkBuildStatus, 300); // --> \ No newline at end of file diff --git a/templates/sysconfig/custom-fileselect.html b/templates/sysconfig/custom-fileselect.html index 0c2d88e9..000c8d10 100644 --- a/templates/sysconfig/custom-fileselect.html +++ b/templates/sysconfig/custom-fileselect.html @@ -1,9 +1,10 @@
+
{{lang_moduleName}} - +
diff --git a/templates/sysconfig/custom-upload.html b/templates/sysconfig/custom-upload.html index 9ab71eaa..02f813f6 100644 --- a/templates/sysconfig/custom-upload.html +++ b/templates/sysconfig/custom-upload.html @@ -4,6 +4,7 @@ +
{{lang_file}} -- cgit v1.2.3-55-g7522