Procházet zdrojové kódy

Dashboard :onversion notification wip

idleman před 2 roky
rodič
revize
ae3edced4d

+ 0 - 40
plugin/notification/action.php

@@ -85,46 +85,6 @@
 
 	});
 
-	Action::register('notification_widget_load',function(&$response){
-		global $myUser;
-		User::check_access('notification','read');
-		require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
-		$widget = DashboardWidget::current();
-		$widget->title = 'Dernières alertes';
-		ob_start();
-		require_once(__DIR__.SLASH.'widget.php');
-		$widget->content = ob_get_clean();
-		echo json_encode($widget);
-	});
-
-	Action::register('notification_widget_configure_save',function(&$response){
-
-			global $myUser,$_;
-			User::check_access('notification','read');
-			require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
-			$widget = DashboardWidget::getById($_['id']);
-
-			if(!isset($_['types'])) throw new Exception("Au moins un type de notification à afficher est requis");
-			if(!isset($_['notification-number'])) $_['notification-number'] = 5;
-			if(!isset($_['notification-length'])) $_['notification-length'] = 150;
-
-			$widget->data('types',$_['types']);
-			$widget->data('notification-number',$_['notification-number']);
-			$widget->data('notification-length',$_['notification-length']);
-			$widget->save();
-
-	});
-
-	Action::register('notification_widget_configure',function(&$response){
-		global $myUser;
-		User::check_access('notification','read');
-		require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
-		$widget = DashboardWidget::current();
-		ob_start();
-		require_once(__DIR__.SLASH.'widget.configure.php');
-		$content = ob_get_clean();
-		echo $content ;
-	});
 
 	//Récuperation d'une liste de notification
 	Action::register('notification_user_notification_search',function(&$response){

+ 2 - 9
plugin/notification/js/widget.js

@@ -1,7 +1,6 @@
 
-function notification_widget_configure_save(widget,modal){
+function notification_widget_configure_save(){
 
-	var data = $('#notification-widget-form').toJson();
 
 	data.types = [];
 	$('#widget-notification-list input[type="checkbox"]:checked').each(function(){
@@ -9,11 +8,5 @@ function notification_widget_configure_save(widget,modal){
 	});
 
 
-	data.action = 'notification_widget_configure_save';
-	data.id = modal.attr('data-widget');
-
-	$.action(data,function(){
-		$.message('success','Configuration enregistrée');
-		dashboard_dashboardwidget_search();
-	});
+	$('[data-id="types"]').val(data.types.join(','));
 }

+ 126 - 2
plugin/notification/notification.plugin.php

@@ -179,7 +179,7 @@ function notification_cron($time){
 	Plugin::need('notification/Notification');
 	Notification::clear();
 }
-
+/*
 function notification_widget(&$widgets){
 	Plugin::need('dashboard/DashboardWidget');
 
@@ -198,6 +198,130 @@ function notification_widget(&$widgets){
 
 	$widgets[] = $modelWidget;
 }
+*/
+Plugin::addHook('widget',function(&$models){
+		
+		$model = new DashboardWidget();
+		$model->icon = 'fas fa-bell';
+		$model->headerBackground = '#ffbe5c';
+		$model->description = 'Affiche un menu sélectionné';
+		$model->label = 'Notification';
+		$model->width = 3;
+		$model->height = 3;
+		$model->model = 'notification';
+		$model->css = array(__DIR__.'/css/widget.css?v='.time());
+		$model->js = array(__DIR__.'/js/widget.js?v='.time());
+		
+		
+		$model->content = function(&$widget){
+			global $myUser;
+			User::check_access('notification','read');
+			Plugin::need('dashboard/DashboardWidget');
+
+			$widget->title = 'Dernières alertes';
+		
+		
+			if(empty($widget->meta['label'])) $widget->meta['label'] =  'Bloc Menu';
+			if(empty($widget->meta['url'])) $widget->meta['url'] = '';
+			if(empty($widget->meta['color'])) $widget->meta['color'] = '#007bff';
+			ob_start();
+
+			require_once(__DIR__.SLASH.'Notification.class.php');
+			require_once(__DIR__.SLASH.'UserNotification.class.php');
+
+			$types = isset($widget->meta['types'])? $widget->meta['types'] :array('announcement');
+			$max = isset($widget->meta['notification-number'])?$widget->meta['notification-number']:5;
+			$maxlength = isset($widget->meta['notification-length'])?$widget->meta['notification-length']:250 ;
+			$userNotifications = UserNotification::byUser($myUser,array(
+				'limit' => $max,
+				'unread' => false,
+				'types' => $types,
+			));
+
+			?>
+			<div class="notification-container">
+				<h5 class="text-uppercase w-100 text-center"><i class="far fa-bell"></i> Alertes</h5>
+				<ul class="notification-widget-list">
+				<?php foreach($userNotifications  as $infos):
+					$infos['created-relative'] = isset($_['synthesis']) ? relative_time($infos['created'], null, 7) : relative_time($infos['created'], null, 7, true);
+					$meta = json_decode($infos['meta']);
+					$infos['link'] =  'index.php?module=notification#'.$infos['id'];
+					$type = Notification::types($infos['type']);
+				?>
+					<li>
+						<h5 onclick="document.location.href='<?php echo $infos['link']; ?>';" class="pointer mb-0 mt-1" style="color: <?php echo $type['color']; ?>;">
+							<div><i title="<?php echo $type['label'] ?>" class="<?php echo $type['icon'] ?>"></i> <?php echo $infos['label']; ?></div>
+							<small class="text-muted d-block"><i class="far fa-clock"></i> <?php echo $infos['created-relative']; ?></small>
+						</h5>
+			            <p class=""><?php echo truncate($infos['html'],$maxlength,array('html'=>true)); ?></p>
+						<a class="btn btn-link d-block w-100 text-center" href="<?php echo $infos['link']; ?>">+ d'informations</a>
+					</li>
+				<?php endforeach; ?>
+				</ul>
+			</div>
+			<?php
+
+			$widget->content = ob_get_clean();
+		};
+
+		$model->configure = function($widget){
+			global $myUser;
+			User::check_access('notification','read');
+			require_once(__DIR__.SLASH.'Notification.class.php');
+			ob_start();
+
+			$selectedTypes =  isset($widget->meta['types'])? $widget->meta['types'] :array('announcement');
+			$max =  isset($widget->meta['notification-number'])?$widget->meta['notification-number']:5;
+			$maxlength =  isset($widget->meta['notification-length'])?$widget->meta['notification-length']:250 ;
+			?>
+			<div id="navigation-widget-form">
+				<div id="notification-widget-form">
+					<div class="row">
+						<div class="col-md-6 col-sm-12">
+							<label for="notification-number">Nb de notifications affichées :</label>
+							<input type="number" class="form-control mb-2" value="<?php echo $max; ?>" id="notification-number">
+						</div>
+						<div class="col-md-6 col-sm-12">
+							<label for="notification-length">Nb de caractères affichés :</label>
+							<input type="number" class="form-control mb-2" value="<?php echo $maxlength; ?>" id="notification-length">
+						</div>
+						<div class="col-md-12 col-sm-12">
+							<label for="">Types de notifications à afficher :</label>
+							<ul class="list-group" id="widget-notification-list">
+							<?php foreach(Notification::types() as $slug=>$type): ?>
+								<li class="list-group-item p-0">
+									<label class="m-0 pointer p-2"><input type="checkbox" onchange="notification_widget_configure_save()"; <?php echo in_array($slug, $selectedTypes)?'checked="checked"':''; ?> value="<?php echo $slug; ?>" data-type="checkbox"><i class="<?php echo $type['icon']; ?>"></i> <?php echo $type['label']; ?> <small class="text-muted">- <?php echo $type['description']; ?></small></label>
+								</li>
+							<?php endforeach; ?>
+							</ul>
+							<input type="hidden" id="types" data-id="types" value="<?php echo implode(',',$selectedTypes);?>">
+						</div>
+					</div>
+				</div>
+			</div>
+			<?php
+		};
+
+		$model->save = function($widget,$form){
+
+			global $myUser,$_;
+			User::check_access('notification','read');
+			require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
+			
+			if(!isset($form['types'])) throw new Exception("Au moins un type de notification à afficher est requis");
+			if(!isset($form['notification-number'])) $form['notification-number'] = 5;
+			if(!isset($form['notification-length'])) $form['notification-length'] = 150;
+			$widget->meta['types'] = $form['types'];
+			$widget->meta['notification-number'] = $form['notification-number'];
+			$widget->meta['notification-length'] = $form['notification-length'];
+			$widget->save();
+
+			$widget->save();
+		};
+
+		$models[$model->model] = $model;
+});
+
 
 //Déclaration des settings de base
 //Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
@@ -215,7 +339,7 @@ Plugin::addCss("/css/main.css");
 Plugin::addJs("/js/main.js");
 
 //Mapping hook / fonctions
-Plugin::addHook("widget", "notification_widget");
+
 Plugin::addHook("install", "notification_install");
 Plugin::addHook("uninstall", "notification_uninstall");
 

+ 0 - 33
plugin/notification/widget.configure.php

@@ -1,33 +0,0 @@
-<?php
-require_once(__DIR__.SLASH.'Notification.class.php');
-
-$selectedTypes = $widget->data('types');
-$selectedTypes = $selectedTypes==''? array("announcement"):$selectedTypes;
-$max = $widget->data('notification-number');
-$max = $max =="" ? 5 : $max ;
-
-$maxlength = $widget->data('notification-length');
-$maxlength = $maxlength =="" ? 150 : $maxlength ;
-?>
-<div id="notification-widget-form">
-	<div class="row">
-		<div class="col-md-6 col-sm-12">
-			<label for="notification-number">Nb de notifications affichées :</label>
-			<input type="number" class="form-control mb-2" value="<?php echo $max; ?>" id="notification-number">
-		</div>
-		<div class="col-md-6 col-sm-12">
-			<label for="notification-length">Nb de caractères affichés :</label>
-			<input type="number" class="form-control mb-2" value="<?php echo $maxlength; ?>" id="notification-length">
-		</div>
-		<div class="col-md-12 col-sm-12">
-			<label for="">Types de notifications à afficher :</label>
-			<ul class="list-group" id="widget-notification-list">
-			<?php foreach(Notification::types() as $slug=>$type): ?>
-				<li class="list-group-item p-0">
-					<label class="m-0 pointer p-2"><input type="checkbox" <?php echo in_array($slug, $selectedTypes)?'checked="checked"':''; ?> value="<?php echo $slug; ?>" data-type="checkbox"><i class="<?php echo $type['icon']; ?>"></i> <?php echo $type['label']; ?> <small class="text-muted">- <?php echo $type['description']; ?></small></label>
-				</li>
-			<?php endforeach; ?>
-			</ul>
-		</div>
-	</div>
-</div>

+ 0 - 40
plugin/notification/widget.php

@@ -1,40 +0,0 @@
-<?php
-global $myUser;
-require_once(__DIR__.SLASH.'Notification.class.php');
-require_once(__DIR__.SLASH.'UserNotification.class.php');
-
-$types = $widget->data('types');
-$types = $types==''? array('announcement'):$types;
-$max = $widget->data('notification-number');
-$max = $max =="" ? 5 : $max ;
-
-$maxlength = $widget->data('notification-length');
-$maxlength = $maxlength =="" ? 250 : $maxlength ;
-
-$userNotifications = UserNotification::byUser($myUser,array(
-	'limit' => $max,
-	'unread' => false,
-	'types' => $types,
-));
-
-?>
-<div class="notification-container">
-	<h5 class="text-uppercase"><i class="far fa-bell"></i> Alertes</h5>
-	<ul class="notification-widget-list">
-	<?php foreach($userNotifications  as $infos):
-		$infos['created-relative'] = isset($_['synthesis']) ? relative_time($infos['created'], null, 7) : relative_time($infos['created'], null, 7, true);
-		$meta = json_decode($infos['meta']);
-		$infos['link'] =  'index.php?module=notification#'.$infos['id'];
-		$type = Notification::types($infos['type']);
-	?>
-		<li>
-			<h5 onclick="document.location.href='<?php echo $infos['link']; ?>';" class="pointer mb-0 mt-1" style="color: <?php echo $type['color']; ?>;">
-				<div><i title="<?php echo $type['label'] ?>" class="<?php echo $type['icon'] ?>"></i> <?php echo $infos['label']; ?></div>
-				<small class="text-muted d-block"><i class="far fa-clock"></i> <?php echo $infos['created-relative']; ?></small>
-			</h5>
-            <p class=""><?php echo truncate($infos['html'],$maxlength,array('html'=>true)); ?></p>
-			<a class="btn btn-link d-block w-100 text-center" href="<?php echo $infos['link']; ?>">+ d'informations</a>
-		</li>
-	<?php endforeach; ?>
-	</ul>
-</div>