Parcourir la source

Dashboard : properties wip

carruesco il y a 1 an
Parent
commit
1f8eed287a

+ 2 - 1
plugin/dashboard/DashboardWidget.class.php

@@ -10,7 +10,7 @@ class DashboardWidget extends Entity{
 	public $id;
 	public $model; //Modèle (Texte)
 	public $type; //Type (Liste classique)
-	public $meta; //Meta (Texte Long)
+	public $meta = array(); //Meta (Texte Long)
 	public $column = 0 ; //Colonne (Nombre Entier)
 	public $row = 0 ; //Ligne (Nombre Entier)
 	public $width = 1; //Largeur (Nombre Entier)
@@ -72,6 +72,7 @@ class DashboardWidget extends Entity{
 	public static function loadAll($columns = array(), $order = null, $limit = null, $selColumn = array('*'), $joins = 0,$alterator = null){
 		return parent::loadAll($columns, $order, $limit, $selColumn, $joins,function(&$item){
 			$item->meta = json_decode($item->meta,true);
+			if(!is_array($item->meta)) $item->meta = array();
 		});
 	}
 

+ 38 - 1
plugin/dashboard/action.php

@@ -168,10 +168,47 @@ Action::register('dashboard_widget_configure',function(&$response){
 	$widget = DashboardWidget::getById($_['id'],1);
 	if(!$widget) throw new Exception('Widget introuvable');
 
-	$widget->fromArray($_);
+	switch($_['type']){
+		case 'style':
+			$widget->fromArray($_);
+		break;
+		case 'model':
+			$widget->fromArray($_);
+		break;
+		case 'properties':
+			$model = DashboardWidget::model($widget->model);
+			if(isset($model->save)){
+				$save = $model->save;
+				if(!is_array($widget->meta)) $widget->meta = array();
+				$save($widget,$_['meta']);
+			}else{
+				$widget->meta = $_['meta'];
+			}
+		break;
+	}
+	
 	$widget->save();
 });
 
+Action::register('dashboard_widget_configure_form',function(&$response){
+	global $_;
+	User::check_access('dashboard','edit');
+	require_once(__DIR__.SLASH.'DashboardWidget.class.php');
+	require_once(__DIR__.SLASH.'Dashboard.class.php');
+
+	if(empty($_['id'])) throw new Exception('Aucun identifiant renseigné');
+
+	$widget = DashboardWidget::getById($_['id'],1);
+
+	if(!is_array($widget->meta)) $widget->meta = array();
+	
+	if(!$widget) throw new Exception('Widget introuvable');
+	$model = DashboardWidget::model($widget->model);
+
+	$configure = $model->configure;
+	$configure($widget);
+	exit();
+});
 
 
 

+ 19 - 14
plugin/dashboard/dashboard.plugin.php

@@ -132,7 +132,11 @@ function dashboard_application_bottom(){
 								</ul>
 						</template>
 						<template id="properties-model">
-								<h3>Propriétés</h3>
+								<div class="p-3">
+									<h3>Propriétés</h3>
+									<div id="dashboard-properties-form"></div>
+									<div class="btn btn-primary mt-1" id="dashboard-properties-save">Enregistrer</div>
+								</div>
 						</template>
 						<template id="configure-style">
 							<div class="row">
@@ -195,7 +199,7 @@ function dashboard_application_bottom(){
 				</div>
 			</div>
 			<div class="modal-footer">
-				<button type="button" class="btn">Fermer</button>
+				<button type="button" class="btn" data-dismiss="modal">Fermer</button>
 			</div>
 		</div>
 	</div>
@@ -215,20 +219,21 @@ Plugin::addHook('widget',function(&$models){
 		$model->css = array(__DIR__.'/css/widget-clock.css?v='.time());
 		$model->js = array(__DIR__.'/js/widget-clock.js?v='.time());
 		$model->content = function(&$widget){
-			$widget->content = '<div class="text-center m-auto widget-clock-content">'.date('H:i:s').'</div>';
-			$widget->label = 'Horloge '.date('d-m-Y H:i:s');
+			if(empty($widget->meta['hour-format'])) $widget->meta['hour-format'] = 'H:i:s';
+			$widget->content = '<div class="text-center m-auto widget-clock-content">'.date($widget->meta['hour-format']).'</div>';
+			$widget->label = 'Horloge '.date($widget->meta['hour-format']);
 		};
-		$model->configure = function($widget,$form){
-			//conf form @todo
-			$form[] = array(
-				'type' => 'boolean',
-				'value' => $widget->meta['enabled'],
-				'label' => 'Activé',
-				'sort' => 1
-			);
+		$model->configure = function($widget){
+			if(empty($widget->meta['hour-format'])) $widget->meta['hour-format'] = 'H:i:s';
+			?>
+			<label>Format de l'heure : </label>
+			<input class="form-control" type="text" id="hour-format" placeholder="H:i:s" value="<?php echo $widget->meta['hour-format']; ?>">
+			<?php
 		};
-		$model->save = function($widget){
-			//save conf action @todo
+		$model->save = function($widget,$form){
+
+			$widget->meta['hour-format'] = $form['hour-format'];
+			$widget->save();
 		};
 		$models[$model->model] = $model;
 });

+ 16 - 3
plugin/dashboard/js/component.js

@@ -6,6 +6,7 @@ function init_components_dashboard(input){
 		onRemove: 'dashboard_widget_delete',
 		onResize: 'dashboard_widget_resize',
 		onConfigure: 'dashboard_widget_configure',
+		onConfigureForm : 'dashboard_widget_configure_form',
 		onRefresh: 'dashboard_widget_refresh',
 		onAdd: 'dashboard_widget_add'
 	},{
@@ -144,6 +145,7 @@ function init_components_dashboard(input){
 					    		$(this).addClass('active');
 					    		$.action({
 							        action : data.onConfigure,
+							        type : menu,
 							        id : widget.id,
 							        model : $(this).attr('data-model')
 							    },function(response){
@@ -151,11 +153,21 @@ function init_components_dashboard(input){
 					    	});
 					    });
 			 		break;
-			 		case "model":
+			 		case "properties":
+
+			 			$('#dashboard-configure-content').html($('#properties-model').html());
 
-			 			$('#dashboard-configure-content').html($('#property-model').html());
+			 			$('#dashboard-properties-form').load('action.php',{action:data.onConfigureForm,id :  widget.id});
 
-			 			//TODO
+			 			$('#dashboard-properties-save').click(function(){
+			 				var bundle ={
+		 						action :  data.onConfigure,
+		 						type : menu,
+		 						id :  widget.id,
+		 						meta : $('#dashboard-properties-form').toJson()
+			 				};
+			 				$.action(bundle);
+			 			});
 			 			
 			 		break;
 			 		case "style":
@@ -197,6 +209,7 @@ function init_components_dashboard(input){
 			 					$.action({
 			 						action :  data.onConfigure,
 			 						id :  widget.id,
+			 						type : menu,
 			 						headerBackground : widget.headerBackground,
 									bodyBackground : widget.bodyBackground,
 									bodyColor : widget.bodyColor,