Completed
Push — master ( 84905b...948707 )
by Jean-Christophe
01:52
created

MessagesTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A showSimpleMessage() 0 11 3
A showConfMessage() 0 11 1
1
<?php
2
3
namespace Ubiquity\controllers\semantic;
4
5
use Ajax\semantic\html\elements\HtmlButton;
6
use Ubiquity\utils\base\UString;
7
use Ajax\semantic\html\elements\HtmlDivider;
8
use Ajax\semantic\html\base\HtmlSemDoubleElement;
9
use Ajax\semantic\html\collections\HtmlMessage;
10
use Ajax\JsUtils;
11
12
/**
13
 * @author jc
14
 * @property JsUtils $jquery
15
 *
16
 */
17
trait MessagesTrait {
18
	protected function showSimpleMessage($content, $type, $icon = "info", $timeout = NULL, $staticName = null): HtmlMessage {
19
		$semantic = $this->jquery->semantic ();
20
		if (! isset ( $staticName ))
21
			$staticName = "msg-" . rand ( 0, 50 );
22
			$message = $semantic->htmlMessage ( $staticName, $content, $type );
23
			$message->setIcon ( $icon );
24
			$message->setDismissable ();
25
			if (isset ( $timeout ))
26
				$message->setTimeout ( 3000 );
27
				return $message;
28
	}
29
	
30
	protected function showConfMessage($content, $type, $url, $responseElement, $data, $attributes = NULL) {
31
		$messageDlg = $this->showSimpleMessage ( $content, $type, "help circle" );
32
		$btOkay = new HtmlButton( "bt-okay", "Confirm", "negative" );
33
		$btOkay->addIcon ( "check circle" );
34
		$btOkay->postOnClick ( $url, "{data:'" . $data . "'}", $responseElement, $attributes );
35
		$btCancel = new HtmlButton ( "bt-cancel-" . UString::cleanAttribute ( $url ), "Cancel" );
36
		$btCancel->addIcon ( "remove circle outline" );
37
		$btCancel->onClick ( $messageDlg->jsHide () );
38
		$messageDlg->addContent ( [ new HtmlDivider( "" ),new HtmlSemDoubleElement( "", "div", "", [ $btOkay->floatRight (),$btCancel->floatRight () ] ) ] );
39
		return $messageDlg;
40
	}
41
}
42
43