Piotr Labudda 11 лет назад
Родитель
Сommit
20bab175a7
2 измененных файлов с 68 добавлено и 2 удалено
  1. 6 1
      SE/se-lib/Route/Msgs.php
  2. 62 1
      SE/se-lib/tmpl/msgsForTable.php

+ 6 - 1
SE/se-lib/Route/Msgs.php

@@ -47,7 +47,11 @@ class Route_Msgs extends RouteBase {
 		if ($msgId > 0) {
 			$this->runByMessageId($msgId);
 		}
-		die('OK');
+		$jsonData = new stdClass();
+		$jsonData->type = 'success';
+		$jsonData->msg = 'Gotowe';
+		echo json_encode($jsonData);
+		exit;
 	}
 
 	public function addTestMsgAction() {
@@ -124,6 +128,7 @@ class Route_Msgs extends RouteBase {
 		while ($r = $db->fetch($res)) {
 			if ($msg = $this->parseMessage($r)) {
 				$msg['link'] = 'index.php?_route=Msgs&_task=run&_msgId=' . $r->ID;
+				$msg['linkType'] = 'ajax';
 				$msgs[$r->ID] = $msg;
 			}
 		}

+ 62 - 1
SE/se-lib/tmpl/msgsForTable.php

@@ -4,9 +4,70 @@
 		<?php foreach ($msgs as $msgId => $msg) : ?>
 			<div class="alert alert-<?php echo V::get('type', 'info', $msg); ?>">
 				<?php echo $msg['message']; ?>
-				 <a class="btn btn-primary btn-xs" target="_blank" href="<?php echo $msg['link']; ?>">uruchom</a>
+				<?php if ('ajax' == V::get('linkType', '', $msg)) : ?>
+					<a class="btn btn-primary btn-xs" target="_blank" onclick="return msgAjaxAction(this);" href="<?php echo $msg['link']; ?>">uruchom</a>
+				<?php else : ?>
+					<a class="btn btn-primary btn-xs" target="_blank" href="<?php echo $msg['link']; ?>">uruchom</a>
+				<?php endif; ?>
 			</div>
 		<?php endforeach; ?>
 	<?php endif; ?>
 
 </div>
+
+
+<script type="text/javascript">
+	function msgAjaxAction(n) {
+		var $n = jQuery(n);
+		$n.text($n.text() + '...').attr('disabled', 'disabled');
+
+		function notifyAjaxCallback(data) {
+			var notify = {};
+			notify.type = (data && data.type)? data.type : '';
+			notify.msg = (data && data.msg)? data.msg : '';
+			switch (notify.type) {
+				case 'success':
+					if (!notify.msg) notify.msg = 'Gotowe';
+					break;
+				case 'error':
+					if (!notify.msg) notify.msg = 'Wystąpiły błędy';
+					break;
+				case 'warning':
+					notify.type = 'warn';
+					if (!notify.msg) notify.msg = 'Wystąpiły błędy';
+					break;
+				default:
+					notify.msg = 'Nieznany błąd';
+					if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
+					notify.type = '';
+			}
+			jQuery.notify(notify.msg, notify.type);
+		}
+
+		$.ajax({
+			data: {},
+			dataType: 'json',
+			type: "GET",
+			url: $n.attr('href')
+		})
+		.done(function(data, textStatus, jqXHR){
+			notifyAjaxCallback(data);
+			$n.closest('.alert').fadeOut('slow');//.remove()
+		})
+		.fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
+			if (jqXHR.responseJSON) {
+				notifyAjaxCallback(jqXHR.responseJSON);
+			}
+			else {
+				var txt = jqXHR.responseText || 'Wystąpiły błędy';
+				if (jqXHR.status == 404) {
+					jQuery.notify(jqXHR.responseText, 'error');
+				} else {
+					jQuery.notify(jqXHR.responseText, 'warn');
+				}
+			}
+		});
+
+		return false;
+	}
+</script>