1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37: Yii::import ('application.components.X2Widget');
38: Yii::import ('application.components.sortableWidget.dataWidgets');
39:
40: 41: 42: 43: 44:
45: abstract class SortableWidget extends X2Widget {
46:
47: const PROFILE_WIDGET_PATH_ALIAS = 'application.components.sortableWidget.profileWidgets';
48: const RECORD_VIEW_WIDGET_PATH_ALIAS =
49: 'application.components.sortableWidget.recordViewWidgets';
50:
51:
52: public static $createByDefault = true;
53:
54: public static $canBeCreated = true;
55:
56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66:
67: public $widgetType;
68:
69: 70: 71:
72: public $widgetManager;
73:
74: 75: 76: 77:
78: public $sortableWidgetJSClass = 'SortableWidget';
79:
80: public $defaultTitle;
81:
82: 83: 84:
85: public $widgetUID = '';
86:
87: 88: 89:
90: public $info = '';
91:
92: 93: 94:
95: public $profile;
96:
97: 98: 99:
100: public $isAjaxRequest = false;
101:
102: 103: 104:
105: public $viewFile = '';
106:
107: 108: 109:
110: public $relabelingEnabled = false;
111:
112: 113: 114:
115: public $canBeDeleted = false;
116:
117: 118: 119: 120: 121: 122:
123: public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{closeButton}{minimizeButton}</div>{widgetContents}';
124:
125: 126: 127: 128:
129: protected $_JSSortableWidgetParams;
130:
131: 132: 133: 134:
135: protected $_translations;
136:
137: 138: 139:
140: protected $containerClass = 'sortable-widget-container x2-layout-island';
141:
142: 143: 144:
145: protected $_packages;
146:
147: 148: 149:
150: protected $_setupScript;
151:
152: 153: 154:
155: protected $_sharedCss;
156:
157: 158: 159:
160: protected $_css;
161:
162: 163: 164: 165:
166: protected $_viewFileParams;
167:
168: 169: 170: 171:
172: protected $_sharedViewFile;
173:
174: 175: 176:
177: protected $_settingsFormFields;
178:
179: 180: 181: 182: 183:
184: private static $_JSONPropertiesStructure;
185:
186:
187: private $_widgetLabel;
188:
189: private $_widgetProperties;
190:
191: 192: 193: 194:
195: public static function getParentType ($widgetType) {
196: if (!in_array ($widgetType, array ('data', 'recordView', 'profile'))) {
197: return 'recordView';
198: } else {
199: return $widgetType;
200: }
201: }
202:
203: 204: 205: 206:
207: public static function getPathAlias ($widgetType) {
208: switch ($widgetType) {
209: case 'profile':
210: $pathAlias = self::PROFILE_WIDGET_PATH_ALIAS;
211: break;
212: case 'topics':
213: case 'recordView':
214: $pathAlias = self::RECORD_VIEW_WIDGET_PATH_ALIAS;
215: break;
216:
217: default:
218: throw new CException ('invalid widget type');
219: }
220: return $pathAlias;
221: }
222:
223: 224: 225: 226: 227:
228: public static function getWidgetSubtypes ($widgetType) {
229: static $cache = array ();
230:
231: if (!in_array ($widgetType, array ('profile', 'topics', 'recordView'
232: ))) {
233:
234: throw new CException ('invalid widget type');
235: }
236:
237:
238:
239: if (!isset ($cache[$widgetType])) {
240: $excludeList = array ('TemplatesGridViewProfileWidget.php');
241: $cache[$widgetType] = array_map (function ($file) {
242: return preg_replace ("/\.php$/", '', $file);
243: },
244: array_filter (
245: scandir(Yii::getPathOfAlias(self::getPathAlias ($widgetType))),
246: function ($file) use ($excludeList) {
247: return !in_array ($file, $excludeList) && preg_match ("/\.php$/", $file);
248: }
249: ));
250: }
251: return $cache[$widgetType];
252: }
253:
254: public static function subtypeIsValid ($widgetType, $widgetSubtype) {
255:
256:
257: if ($widgetType === 'profile' && $widgetSubtype === 'TemplatesGridViewProfileWidget' ||
258: in_array ($widgetSubtype, SortableWidget::getWidgetSubtypes ($widgetType))) {
259:
260: return true;
261: } else {
262: return false;
263: }
264: }
265:
266: public static function getCreatableWidgetOptions ($widgetType) {
267: $widgetSubtypes = self::getWidgetSubtypeOptions ($widgetType);
268: $filtered = array ();
269: foreach ($widgetSubtypes as $type => $label) {
270: if (preg_match ('/TemplatesGridViewProfileWidget$/', $type)) {
271: $className = 'TemplatesGridViewProfileWidget';
272: } else {
273: $className = $type;
274: }
275: if (class_exists ($className) && $className::$canBeCreated) $filtered[$type] = Yii::t('app',$label);
276: }
277: return $filtered;
278: }
279:
280: 281: 282: 283:
284: public static function getWidgetSubtypeOptions ($widgetType) {
285: static $cache = array ();
286: if (!isset ($cache[$widgetType])) {
287: $widgetSubtypes = self::getWidgetSubtypes ($widgetType);
288:
289: $cache[$widgetType] = array_combine (
290: $widgetSubtypes,
291: array_map (function ($widgetType) {
292: $jsonPropertiesStruct = $widgetType::getJSONPropertiesStructure ();
293: return $jsonPropertiesStruct['label'];
294: }, $widgetSubtypes)
295: );
296:
297:
298: if ($widgetType === 'profile') {
299: $customModules = Modules::model ()->getCustomModules (true);
300:
301: foreach ($customModules as $module) {
302: $modelName = ucfirst ($module->name);
303: if ($module->name !== 'document' && class_exists ($modelName)) {
304:
305: $cache[$widgetType][$modelName.'::TemplatesGridViewProfileWidget'] =
306: Yii::t(
307: 'app', '{modelName} Summary', array ('{modelName}' => Modules::displayName(true, $module->name)));
308: }
309: }
310: }
311: }
312: return $cache[$widgetType];
313: }
314:
315: 316: 317: 318: 319: 320: 321: 322: 323:
324: public static function getWidgetContents (
325: $controller, $profile, $widgetType, $widgetUID, $extraWidgetParams=array ()) {
326:
327: return CJSON::encode (array (
328: 'uid' => $widgetUID,
329: 'widget' => $controller->renderPartial (
330: 'application.components.sortableWidget.views._ajaxWidgetContents',
331: array (
332: 'widgetClass' => get_called_class (),
333: 'widgetType' => $widgetType,
334: 'profile' => $profile,
335: 'widgetUID' => $widgetUID,
336: 'extraWidgetParams' => $extraWidgetParams,
337: ), true, true)));
338: }
339:
340: 341: 342:
343: public static function getJSONPropertiesStructure () {
344: if (!isset (self::$_JSONPropertiesStructure)) {
345: self::$_JSONPropertiesStructure = array (
346: 'label' => '',
347: 'uid' => '',
348: 'hidden' => false,
349: 'minimized' => false,
350: 'containerNumber' => 1,
351: 'softDeleted' => false,
352: );
353: }
354: return self::$_JSONPropertiesStructure;
355: }
356:
357: 358: 359: 360: 361: 362:
363: public static function instantiateWidget (
364: $widgetLayoutKey, $profile, $widgetType = 'profile', $options = array()) {
365:
366: list($widgetClass, $widgetUID) = SortableWidget::parseWidgetLayoutKey ($widgetLayoutKey);
367: if ($widgetClass::getJSONProperty (
368: $profile, 'softDeleted', $widgetType, $widgetUID)) {
369:
370: return;
371: }
372: return Yii::app()->controller->widget(
373: 'application.components.sortableWidget.'.$widgetClass, array_merge(
374: array(
375: 'widgetUID' => $widgetUID,
376: 'profile' => $profile,
377: 'widgetType' => $widgetType,
378: )
379: , $options));
380: }
381:
382: 383: 384: 385: 386:
387: public static function parseWidgetLayoutKey ($widgetLayoutKey) {
388: if (preg_match ("/_(\w*)$/", $widgetLayoutKey, $matches)) {
389: $widgetUID = $matches[1];
390: } else {
391: $widgetUID = '';
392: }
393:
394: $widgetClass = preg_replace ("/_\w*/", '', $widgetLayoutKey);
395: return array ($widgetClass, $widgetUID);
396: }
397:
398: 399: 400: 401: 402: 403: 404: 405:
406: public static function createSortableWidget (
407: $profile, $widgetClass, $widgetType, $widgetSettings=array ()) {
408:
409: if (!self::subtypeIsValid ($widgetType, $widgetClass)) {
410: return array (false, null);
411: }
412:
413: $widgetLayoutPropertyName = $widgetType . 'WidgetLayout';
414: $layout = $profile->$widgetLayoutPropertyName;
415:
416:
417: if (isset ($layout[$widgetClass]) && $layout[$widgetClass]['softDeleted']) {
418: $layout[$widgetClass]['softDeleted'] = false;
419:
420: $profile->$widgetLayoutPropertyName = $layout;
421: if ($profile->save ()) {
422: return array (true, '');
423: } else {
424: return array (false, null);
425: }
426: }
427:
428: $uniqueId = uniqid ();
429: $widgetUniqueName = $widgetClass.'_'.$uniqueId;
430: while (true) {
431: if (!isset ($layout[$widgetUniqueName])) {
432: break;
433: }
434: $uniqueId = uniqid ();
435: $widgetUniqueName = $widgetClass.'_'.$uniqueId;
436: }
437:
438: $layout[$widgetUniqueName] = array_merge (
439: array (
440: 'hidden' => false,
441: 'minimized' => false,
442: ), $widgetSettings);
443:
444: $profile->$widgetLayoutPropertyName = $layout;
445:
446: if ($profile->update ()) {
447: return array (true, $uniqueId);
448: } else {
449: return array (false, null);
450: }
451: }
452:
453: 454: 455: 456: 457: 458: 459:
460: public static function deleteSortableWidget (
461: $profile, $widgetClass, $widgetUID, $widgetLayoutName) {
462:
463: $widgetLayoutPropertyName = $widgetLayoutName . 'WidgetLayout';
464: $layout = $profile->$widgetLayoutPropertyName;
465: if ($widgetUID !== '')
466: $widgetKey = $widgetClass.'_'.$widgetUID;
467: else
468: $widgetKey = $widgetClass;
469:
470: if (!isset ($layout[$widgetKey])) {
471: return false;
472: }
473:
474: if ($widgetUID === '') {
475:
476: $layout[$widgetKey]['softDeleted'] = true;
477: } else {
478: unset ($layout[$widgetKey]);
479: }
480:
481: $profile->$widgetLayoutPropertyName = $layout;
482:
483: if ($profile->update ()) {
484: return true;
485: } else {
486: return false;
487: }
488: }
489:
490: 491: 492: 493: 494: 495: 496: 497: 498:
499: public static function setSortOrder ($profile, $widgetOrder, $widgetType) {
500: $widgetLayoutName = $widgetType . 'WidgetLayout';
501: $layout = $profile->$widgetLayoutName;
502: $newLayout = array ();
503:
504:
505: foreach ($widgetOrder as $widgetKey) {
506: if (in_array ($widgetKey, array_keys ($layout))) {
507: $newLayout[$widgetKey] = $layout[$widgetKey];
508: unset ($layout[$widgetKey]);
509: }
510: }
511:
512:
513: foreach ($layout as $widgetClass => $settings) {
514: $newLayout[$widgetClass] = $layout[$widgetClass];
515: }
516:
517: $profile->$widgetLayoutName = $newLayout;
518: if ($profile->save ()) {
519: return true;
520: }
521: return false;
522: }
523:
524: 525: 526: 527: 528: 529: 530: 531: 532: 533:
534: public static function setJSONProperty ($profile, $key, $value, $widgetType, $widgetUID) {
535: return self::setJSONProperties (
536: $profile, array ($key => $value), $widgetType, $widgetUID);
537: }
538:
539: 540: 541: 542: 543: 544: 545: 546:
547: public static function setJSONProperties ($profile, array $props, $widgetType, $widgetUID) {
548: $widgetLayoutName = $widgetType . 'WidgetLayout';
549: $widgetClass = get_called_class ();
550:
551: if ($widgetUID !== '')
552: $widgetKey = $widgetClass.'_'.$widgetUID;
553: else
554: $widgetKey = $widgetClass;
555:
556: $layout = $profile->$widgetLayoutName;
557: $update = false;
558: foreach ($props as $key => $value) {
559: if (isset ($layout[$widgetKey])) {
560: if (in_array ($key, array_keys ($layout[$widgetKey]))) {
561: $layout[$widgetKey][$key] = $value;
562: $update = true;
563: }
564: }
565: }
566: if ($update) {
567: $profile->$widgetLayoutName = $layout;
568: if ($profile->update ()) {
569: return true;
570: }
571: }
572: return false;
573: }
574:
575: 576: 577: 578: 579: 580: 581: 582:
583: public static function getJSONProperty ($profile, $key, $widgetType, $widgetUID) {
584: $properties = self::getJSONProperties($profile, $widgetType, $widgetUID);
585: if (isset($properties[$key])) {
586: return $properties[$key];
587: }
588: return null;
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607: }
608:
609: 610: 611: 612: 613: 614: 615: 616:
617: public static function getJSONProperties ($profile, $widgetType, $widgetUID) {
618: $widgetClass = get_called_class ();
619: $widgetLayoutName = $widgetType . 'WidgetLayout';
620:
621: if ($widgetUID !== '')
622: $widgetKey = $widgetClass.'_'.$widgetUID;
623: else
624: $widgetKey = $widgetClass;
625:
626: $layout = $profile->$widgetLayoutName;
627:
628: if (isset ($layout[$widgetKey])) {
629: return $layout[$widgetKey];
630: }
631: return null;
632: }
633:
634: 635: 636:
637: private static function compareOffset ($a, $b) {
638: return $a[1] > $b[1];
639: }
640:
641: 642: 643:
644: public function getWidgetKey () {
645: return get_called_class () . '_' . $this->widgetUID;
646: }
647:
648: 649: 650: 651:
652: public function getWidgetProperty ($key) {
653: if (!isset ($this->_widgetProperties)) {
654: $this->getWidgetProperties ();
655: }
656: if (!isset ($this->_widgetProperties[$key])) {
657: return null;
658: }
659: return $this->_widgetProperties[$key];
660: }
661:
662: public function getWidgetProperties () {
663: if (!isset ($this->_widgetProperties)) {
664: $this->_widgetProperties = self::getJSONProperties (
665: $this->profile, $this->widgetType, $this->widgetUID);
666: }
667: return $this->_widgetProperties;
668: }
669:
670: 671: 672: 673: 674:
675: public function setWidgetProperties (array $props) {
676: if (self::setJSONProperties (
677: $this->profile, $props, $this->widgetType, $this->widgetUID)) {
678:
679: foreach ($props as $key => $value) {
680: $this->_widgetProperties[$key] = $value;
681: }
682: return true;
683: }
684: return false;
685: }
686:
687: 688: 689: 690: 691: 692:
693: public function setWidgetProperty ($key, $value) {
694: if (self::setJSONProperties (
695: $this->profile, array ($key => $value), $this->widgetType, $this->widgetUID)) {
696:
697: $this->_widgetProperties[$key] = $value;
698: return true;
699: }
700: return false;
701: }
702:
703: 704: 705:
706: public function getWidgetLabel () {
707: return Yii::t('app',$this->getWidgetProperty ('label'));
708: }
709:
710: public function getSharedViewFile () {
711: if (!isset ($this->_sharedViewFile)) {
712: $this->_sharedViewFile = self::getParentType ($this->widgetType) . 'Widget';
713: }
714: return $this->_sharedViewFile;
715: }
716:
717: public function setSharedViewFile ($sharedViewFile) {
718: $this->_sharedViewFile = $sharedViewFile;
719: }
720:
721: 722: 723:
724: public function getPackages () {
725: if (!isset ($this->_packages)) {
726: $this->_packages = array_merge (parent::getPackages (), array (
727: 'auxlib' => array(
728: 'baseUrl' => Yii::app()->request->baseUrl,
729: 'js' => array(
730: 'js/auxlib.js',
731: ),
732: ),
733: 'SortableWidgetJS' => array(
734: 'baseUrl' => Yii::app()->request->baseUrl,
735: 'js' => array(
736: 'js/sortableWidgets/SortableWidget.js',
737: ),
738: 'depends' => array ('auxlib', 'X2Widget')
739: ),
740: ));
741: }
742: return $this->_packages;
743: }
744:
745: 746: 747: 748:
749: public function setPackages ($packages) {
750: $this->_packages = $packages;
751: }
752:
753: 754: 755: 756:
757: public function addPackage ($package) {
758: $this->packages = array_merge ($this->packages, $package);
759: }
760:
761: public function getJSInstanceName () {
762: $widgetClass = get_called_class ();
763: return $widgetClass.$this->widgetUID;
764: }
765:
766: 767: 768: 769:
770: public function getSetupScript () {
771: if (!isset ($this->_setupScript)) {
772: $this->_setupScript = "
773: $(function () {
774: x2.".$this->getJSInstanceName ()." = new $this->sortableWidgetJSClass (".
775: CJSON::encode ($this->getJSSortableWidgetParams ()).
776: ");
777: });
778: ";
779: }
780: return $this->_setupScript;
781: }
782:
783: 784: 785:
786: public function registerSharedCss () {
787: $sharedCss = $this->sharedCss;
788: foreach ($sharedCss as $cssName => $css) {
789: Yii::app()->clientScript->registerCss($cssName, $css);
790: }
791: foreach ($this->sharedCssFileNames as $filename) {
792: Yii::app()->clientScript->registerCssFile(
793: Yii::app()->theme->baseUrl.'/css/'.$filename);
794: }
795: }
796:
797: 798: 799:
800: public function registerCss () {
801: $css = $this->css;
802: foreach ($css as $cssName => $css) {
803: Yii::app()->clientScript->registerCss($cssName, $css);
804: }
805: }
806:
807: 808: 809: 810: 811: 812:
813: public function getViewFileParams () {
814: if (!isset ($this->_viewFileParams)) {
815: $this->_viewFileParams = array (
816: 'isAjaxRequest' => $this->isAjaxRequest
817: );
818: }
819: return $this->_viewFileParams;
820: }
821:
822: private $_errors = array ();
823: public function addError ($message) {
824: $this->_errors[] = $message;
825: }
826:
827: public function hasError () {
828: return count ($this->_errors);
829: }
830:
831: 832: 833: 834:
835: public function renderWidget () {
836:
837: $hidden = self::getJSONProperty (
838: $this->profile, 'hidden', $this->widgetType, $this->widgetUID);
839:
840: if ($hidden !== null && $hidden) return;
841:
842: $this->registerCss ();
843:
844:
845: $itemMatches = array ();
846: $htmlMatches = array ();
847:
848: if (method_exists ($this, 'getTemplate')) {
849: $template = $this->getTemplate ();
850: } else {
851: $template = $this->template;
852: }
853: preg_match_all ("/(?:^([^{]+)\{)|(?:\}([^{]+)\{)|(?:\}([^{]+)$)/", $template,
854: $htmlMatches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
855: preg_match_all ("/{([^}]+)}/", $template, $itemMatches,
856: PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
857:
858: $templateHTML = array ();
859: $templateItems = array ();
860:
861:
862: for ($i = 1; $i < sizeof ($htmlMatches); ++$i) {
863: for ($j = 0; $j < sizeof ($htmlMatches[$i]); ++$j) {
864: if (is_array ($htmlMatches[$i][$j]) && $htmlMatches[$i][$j][1] >= 0) {
865: $templateHTML[] = array_merge ($htmlMatches[$i][$j], array ('html'));
866: }
867: }
868: }
869:
870:
871: for ($i = 0; $i < sizeof ($itemMatches[1]); ++$i) {
872: if (is_array ($itemMatches[1][$i]) && $itemMatches[1][$i][1] >= 0) {
873: $templateItems[] = array_merge ($itemMatches[1][$i], array ('item'));
874: }
875: }
876:
877:
878:
879:
880: $allTemplateItems = array_merge ($templateItems, $templateHTML);
881: usort ($allTemplateItems, array ('self', 'compareOffset'));
882:
883:
884:
885:
886: for ($i = 0; $i < sizeof ($allTemplateItems); ++$i) {
887: if ($allTemplateItems[$i][2] == 'html') {
888: echo $allTemplateItems[$i][0];
889: } else {
890: $fnName = 'render' . ucfirst ($allTemplateItems[$i][0]);
891: if (method_exists ($this, $fnName)) {
892: $this->$fnName ();
893: }
894: }
895: }
896: }
897:
898: private $_minimized;
899: public function getMinimized () {
900: if (!isset ($this->_minimized)) {
901: $this->_minimized = self::getJSONProperty (
902: $this->profile, 'minimized', $this->widgetType, $this->widgetUID);
903: }
904: return $this->_minimized;
905: }
906:
907: public function setMinimized ($minimized) {
908: $this->_minimized = $minimized;
909: }
910:
911: 912: 913: 914:
915: public function renderWidgetContents () {
916: Yii::app()->clientScript->registerPackages ($this->packages);
917:
918: 919: 920: 921: 922:
923: Yii::app()->clientScript->registerScript (
924: get_called_class ().$this->widgetUID.'Script', $this->setupScript,
925: ($this->isAjaxRequest ? CClientScript::POS_END: CClientScript::POS_BEGIN));
926:
927: $minimized = $this->getMinimized ();
928: echo "<div id='".get_called_class ()."-widget-content-container-".$this->widgetUID."'".
929: ($minimized ? " style='display: none;'" : '').">";
930:
931: if ($this->hasError ()) {
932: $this->renderErrors ();
933: } elseif ($this->viewFile) {
934: $this->render (
935: 'application.components.sortableWidget.views.'.$this->viewFile,
936: $this->getViewFileParams ());
937: }
938:
939: echo "</div>";
940: }
941:
942: public function renderErrors () {
943: Yii::app()->controller->renderPartial (
944: 'application.components.sortableWidget.views._widgetError', array (
945: 'errors' => $this->_errors,
946: ));
947: }
948:
949: 950: 951: 952:
953: public function renderWidgetLabel () {
954: $label = $this->getWidgetLabel ();
955: echo "<div class='widget-title'>".htmlspecialchars($label)."</div>";
956: }
957:
958: 959: 960:
961: public function () {
962: $themeUrl = Yii::app()->theme->getBaseUrl();
963: $htmlStr =
964: "<a href='#' class='widget-settings-button x2-icon-button' style='display:none;'>";
965: $htmlStr .= CHtml::tag(
966: 'span',
967: array (
968: 'title' => Yii::t('app', 'Show Widget Settings'),
969: 'class' => 'fa fa-cog fa-lg'
970:
971: ), ' ');
972: $htmlStr .= '</a>';
973: echo $htmlStr;
974: echo $this->settingsMenuContent;
975: }
976:
977: 978: 979: 980:
981: public function renderMinimizeButton () {
982: $themeUrl = Yii::app()->theme->getBaseUrl();
983: $htmlStr =
984: "<a href='#' class='widget-minimize-button x2-icon-button' style='display:none;'>";
985: $minimized = self::getJSONProperty (
986: $this->profile, 'minimized', $this->widgetType, $this->widgetUID);
987: $htmlStr .= CHtml::openTag(
988: 'span',
989: array (
990: 'class' => 'fa fa-caret-left fa-lg',
991: 'title' => Yii::t('app', 'Maximize Widget'),
992: 'style' => ($minimized ? '': 'display: none;')
993: ));
994:
995: $htmlStr .= '</span>';
996: $htmlStr .= CHtml::openTag(
997: 'span',
998: array (
999: 'class' => 'fa fa-caret-down fa-lg',
1000: 'title' => Yii::t('app', 'Minimize Widget'),
1001: 'style' => ($minimized ? 'display: none;' : '')
1002: ));
1003:
1004: $htmlStr .= '</span>';
1005: $htmlStr .= '</a>';
1006: echo $htmlStr;
1007: }
1008:
1009: 1010: 1011: 1012:
1013: public function renderCloseButton () {
1014: $themeUrl = Yii::app()->theme->getBaseUrl();
1015: echo "<a class='widget-close-button x2-icon-button' href='#' style='display:none;'>";
1016: echo CHtml::tag('span',
1017: array (
1018: 'class' => 'fa fa-times fa-lg',
1019: 'title' => Yii::t('app', 'Close Widget')
1020: ), ' ');
1021: echo "</a>";
1022: }
1023:
1024: 1025: 1026:
1027: public function run () {
1028: $hidden = self::getJSONProperty (
1029: $this->profile, 'hidden', $this->widgetType, $this->widgetUID);
1030: if ($hidden === null) $hidden = false;
1031: $this->registerSharedCss ();
1032: $this->render ('application.components.sortableWidget.views.'.$this->sharedViewFile,
1033: array (
1034: 'widgetClass' => get_called_class (),
1035: 'profile' => $this->profile,
1036: 'hidden' => $hidden,
1037: 'widgetUID' => $this->widgetUID,
1038: ));
1039: }
1040:
1041:
1042: 1043: 1044:
1045:
1046: 1047: 1048: 1049:
1050: protected function () {
1051: $htmlStr =
1052: '<div class="widget-settings-menu-content" style="display:none;">
1053: <ul>'.
1054: $this->getSettingsMenuContentEntries ().
1055: '</ul>
1056: </div>';
1057: $htmlStr .= $this->getSettingsMenuContentDialogs ();
1058: return $htmlStr;
1059: }
1060:
1061:
1062: 1063: 1064:
1065: protected function () {
1066: return ($this->relabelingEnabled ?
1067: '<li class="relabel-widget-button">'.
1068: X2Html::fa('fa-edit').
1069: Yii::t('app', 'Rename Widget').
1070: '</li>' : '').
1071: ($this->canBeDeleted ?
1072: '<li class="delete-widget-button">'.
1073: X2Html::fa('fa-trash').
1074: Yii::t('app', 'Delete Widget').
1075: '</li>' : '');
1076: }
1077:
1078: 1079: 1080:
1081: protected function () {
1082: $htmlStr = '';
1083: if ($this->relabelingEnabled) {
1084: $htmlStr .=
1085: '<div id="relabel-widget-dialog-'.$this->widgetUID.'" style="display: none;">
1086: <div>'.Yii::t('app', 'Enter a new name:').'</div>
1087: <input class="new-widget-name">
1088: </div>';
1089: }
1090: if ($this->canBeDeleted) {
1091: $htmlStr .=
1092: '<div id="delete-widget-dialog-'.$this->widgetUID.'" style="display: none;">
1093: <div>'.
1094: Yii::t('app', 'Performing this action will cause this widget\'s settings '.
1095: 'to be lost. This action cannot be undone.').
1096: '</div>
1097: </div>';
1098: }
1099: return $htmlStr;
1100: }
1101:
1102: 1103: 1104:
1105: protected $_sharedCssFileNames;
1106: public function getSharedCssFileNames () {
1107: if (!isset ($this->_sharedCssFileNames)) {
1108: $this->_sharedCssFileNames = array (
1109: 'components/sortableWidget/SortableWidget.css',
1110: );
1111: }
1112: return $this->_sharedCssFileNames;
1113: }
1114:
1115: 1116: 1117: 1118: 1119:
1120: protected function getSharedCss () {
1121: if (!isset ($this->_sharedCss)) {
1122: $this->_sharedCss = array ();
1123: }
1124: return $this->_sharedCss;
1125: }
1126:
1127: 1128: 1129: 1130: 1131:
1132: protected function getCss () {
1133: if (!isset ($this->_css)) {
1134: $this->_css = array ();
1135: }
1136: return $this->_css;
1137: }
1138:
1139: 1140: 1141:
1142: protected function getTranslations () {
1143: if (!isset ($this->_translations )) {
1144: $this->_translations = array ();
1145: if ($this->relabelingEnabled) {
1146: $this->_translations = array_merge ($this->_translations, array (
1147: 'Rename Widget' => Yii::t('app', 'Rename Widget'),
1148: 'Cancel' => Yii::t('app', 'Cancel'),
1149: 'Rename' => Yii::t('app', 'Rename'),
1150: ));
1151: }
1152: if ($this->canBeDeleted) {
1153: $this->_translations = array_merge ($this->_translations, array (
1154: 'Cancel' => Yii::t('app', 'Cancel'),
1155: 'Delete' => Yii::t('app', 'Delete'),
1156: 'Are you sure you want to delete this widget?' =>
1157: Yii::t('app', 'Are you sure you want to delete this widget?'),
1158: ));
1159: }
1160: }
1161: return $this->_translations;
1162: }
1163:
1164: protected function getJSSortableWidgetParams () {
1165: if (!isset ($this->_JSSortableWidgetParams)) {
1166: $this->_JSSortableWidgetParams = array (
1167: 'widgetClass' => get_called_class (),
1168: 'setPropertyUrl' => Yii::app()->controller->createUrl (
1169: '/profile/setWidgetSetting'),
1170: 'cssSelectorPrefix' => $this->widgetType,
1171: 'widgetType' => $this->widgetType,
1172: 'widgetUID' => $this->widgetUID,
1173: 'translations' => $this->getTranslations (),
1174: 'deleteWidgetUrl' => Yii::app()->controller->createUrl (
1175: '/profile/deleteSortableWidget'),
1176: 'hasError' => $this->hasError ()
1177: );
1178: }
1179: return $this->_JSSortableWidgetParams;
1180: }
1181:
1182: public function init () {
1183: if (!isset ($this->namespace))
1184: $this->namespace = $this->getWidgetKey ();
1185: parent::init ();
1186: }
1187:
1188: }
1189: ?>
1190: