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.extensions.NLSClientScript');
38:
39: 40: 41: 42: 43: 44:
45: class X2ClientScript extends NLSClientScript {
46:
47: public $useAbsolutePaths = false;
48: private $_admin;
49: private $_baseUrl;
50: private $_fullscreen;
51: private $_isGuest;
52: private $_profile;
53: private $_scriptUrl;
54: private $_themeUrl;
55: private $_cacheBuster;
56: private $_defaultPackages;
57:
58: public function getDefaultPackages () {
59: if (!isset ($this->_defaultPackages)) {
60: $this->_defaultPackages = array_merge (
61: $this->getIEDefaultPackages(),
62: array(
63: 'auxlib' => array(
64: 'baseUrl' => Yii::app()->request->baseUrl,
65: 'js' => array(
66: 'js/auxlib.js'
67: )
68: )
69: )
70: );
71: }
72: return $this->_defaultPackages;
73: }
74:
75: public function getIEDefaultPackages() {
76: if (AuxLib::getIEVer() >= 9) {
77: return array();
78: }
79: return array ();
80:
81:
82:
83:
84:
85:
86:
87:
88:
89: }
90:
91: 92: 93: 94:
95: public function getCacheBuster() {
96: if (!isset ($this->_cacheBuster)) {
97: if (YII_DEBUG) {
98: 99: 100: 101:
102: if (!isset ($_SESSION['cacheBuster'])) {
103: $_SESSION['cacheBuster'] = ((string) time ());
104: }
105:
106: $this->_cacheBuster = $_SESSION['cacheBuster'];
107:
108: } else {
109:
110: $this->_cacheBuster = Yii::app()->params->buildDate;
111: }
112: }
113: return $this->_cacheBuster;
114: }
115:
116: 117: 118: 119: 120:
121: public function renderOnRequest($includeScriptFiles = false) {
122: $html='';
123: if($includeScriptFiles) {
124: foreach($this->scriptFiles as $scriptFiles) {
125: foreach($scriptFiles as $scriptFile)
126: $html.=CHtml::scriptFile($scriptFile)."\n";
127: }
128: }
129: foreach($this->scripts as $script)
130: $html.=CHtml::script(implode("\n",$script))."\n";
131:
132: if($html!=='')
133: return $html;
134: }
135:
136: 137: 138: 139: 140: 141:
142: public function echoScripts($captureScripts = false){
143: $cs = $this;
144: $scripts = '';
145: $endScripts = '';
146: foreach($cs->cssFiles as $url => $type){
147: $scripts .= '
148: if($("head link[href=\''.$url.'\']").length == 0) {
149: $.ajax({type:"GET",url:"'.$url.'"}).done(function(response) {
150: $(\'<link rel="stylesheet" type="text/css" href="'.$url.'">\').
151: appendTo("head");
152: });
153: }';
154: }
155: foreach($cs->scriptFiles as $position => $scriptFiles){
156: foreach($scriptFiles as $key => $url){
157: $scripts .= '
158: $.ajax({
159: type:"GET",
160: dataType:"script",
161: url:"'.$url.'"
162: }).always(function(){';
163: $endScripts .= '})';
164: }
165: }
166: if(array_key_exists(CCLientScript::POS_READY, Yii::app()->clientScript->scripts)){
167: foreach(Yii::app()->clientScript->scripts[CClientScript::POS_READY] as $id => $script){
168: if(strpos($id, 'logo') === false)
169: $scripts .= "$script\n";
170: }
171: }
172: if($captureScripts){
173: return $scripts.$endScripts.';';
174: }
175: echo $scripts.$endScripts.';';
176: }
177:
178: 179: 180: 181: 182:
183: public function registerPackages ($packages, $useDefaultPackages=false) {
184: $oldPackages = Yii::app()->clientScript->packages;
185: if ($useDefaultPackages) {
186: Yii::app()->clientScript->packages = array_merge (
187: $this->getDefaultPackages (), $packages);
188: } else {
189: Yii::app()->clientScript->packages = $packages;
190: }
191:
192: foreach (array_keys ($packages) as $packageName) {
193: Yii::app()->clientScript->registerPackage ($packageName);
194: }
195: Yii::app()->clientScript->packages = $oldPackages;
196: }
197:
198: 199: 200: 201: 202:
203: public function registerCoreScript($name)
204: {
205: if(isset($this->coreScripts[$name]))
206: return $this;
207: if(isset($this->packages[$name]))
208: $package=$this->packages[$name];
209: else
210: {
211: if($this->corePackages===null) {
212: $this->corePackages=require(YII_PATH.'/web/js/packages.php');
213:
214: $this->corePackages = array_merge(
215: $this->corePackages,
216: require(implode (DIRECTORY_SEPARATOR, array (
217: Yii::app()->basePath,
218: 'data/packages.php'
219: ))));
220:
221: }
222: if(isset($this->corePackages[$name]))
223: $package=$this->corePackages[$name];
224: }
225: if(isset($package))
226: {
227: if(!empty($package['depends']))
228: {
229: foreach($package['depends'] as $p)
230: $this->registerCoreScript($p);
231: }
232: $this->coreScripts[$name]=$package;
233: $this->hasScripts=true;
234: $params=func_get_args();
235: $this->recordCachingAction('clientScript','registerCoreScript',$params);
236: }
237: elseif(YII_DEBUG)
238: throw new CException('There is no CClientScript package: '.$name);
239: else
240: Yii::log('There is no CClientScript package: '.$name,CLogger::LEVEL_WARNING,'system.web.CClientScript');
241:
242: return $this;
243: }
244:
245: public function getCurrencyConfigScript () {
246:
247: $locale = Yii::app()->locale;
248:
249: $decSym = $locale->getNumberSymbol('decimal');
250: $grpSym = $locale->getNumberSymbol('group');
251: $curSym = Yii::app()->getLocale()->getCurrencySymbol(Yii::app()->params['currency']);
252:
253:
254: $cldScript =
255: ';(function($) {
256: x2.currencyInfo = '.CJSON::encode(array(
257: 'prefix' => isset($curSym)? $curSym : Yii::app()->params['currency'],
258: 'decimal' => $decSym,
259: 'thousands' => $grpSym,
260: )).";
261: })(jQuery);";
262:
263: return $cldScript;
264: }
265:
266: 267: 268: 269: 270: 271:
272: public function getCacheBusterSuffix ($url=null) {
273: $cacheBuster = $this->getCacheBuster ();
274: if ($url === null) {
275: return '?'.$cacheBuster;
276: } else if (preg_match ("/\?/", $url)) {
277: return '&'.$cacheBuster;
278: } else {
279: return '?'.$cacheBuster;
280: }
281: }
282:
283: 284: 285:
286: public function registerResponsiveCssFile ($url, $media='') {
287: if (AuxLib::getLayoutType () === 'responsive') {
288: $this->registerCssFile (
289: $url.$this->getCacheBusterSuffix ($url), $media);
290: }
291: }
292:
293: 294: 295:
296: public function registerResponsiveCss ($id, $css, $media='') {
297: if (AuxLib::getLayoutType () === 'responsive') {
298: $this->registerCss ($id, $css, $media);
299: }
300: }
301:
302: public function makeUrlAbsolute ($url) {
303: $hostInfo = Yii::app()->request->getHostInfo ();
304:
305:
306:
307:
308:
309:
310: if (!preg_match ('/^https?:\/\//', $url) &&
311: !preg_match ('/^'.preg_quote ($hostInfo, '/').'/', $url)) {
312:
313: $url = $hostInfo.$url;
314: }
315: return $url;
316: }
317:
318: 319: 320: 321:
322: public function registerScriptFile ($url, $position=null, array $htmlOptions=array()) {
323: if ($this->useAbsolutePaths) $url = $this->makeUrlAbsolute ($url);
324: $url = $this->getJSPathname ($url);
325: if (X2AssetManager::$enableAssetDomains)
326: $url = Yii::app()->assetManager->substituteAssetDomain ($url);
327: return parent::registerScriptFile (
328: $url.$this->getCacheBusterSuffix ($url), $position,
329: $htmlOptions);
330: }
331:
332: 333: 334:
335: public function renderCoreScripts()
336: {
337: if($this->coreScripts===null)
338: return;
339: $cssFiles=array();
340: $jsFiles=array();
341: foreach($this->coreScripts as $name=>$package)
342: {
343: $baseUrl=$this->getPackageBaseUrl($name);
344: if ($this->useAbsolutePaths) $baseUrl = $this->makeUrlAbsolute ($baseUrl);
345: if(!empty($package['js']))
346: {
347:
348: foreach($package['js'] as $js) {
349: if (X2AssetManager::$enableAssetDomains)
350: $baseUrl = Yii::app()->assetManager->substituteAssetDomain ($this->getPackageBaseUrl($name));
351: $jsFiles[$baseUrl.'/'.$js.$this->getCacheBusterSuffix ($js)]=$baseUrl.'/'.$js;
352: }
353:
354: }
355: if(!empty($package['css']))
356: {
357:
358: foreach($package['css'] as $css) {
359: if (X2AssetManager::$enableAssetDomains && !in_array($css, X2AssetManager::$skipAssets))
360: $baseUrl = Yii::app()->assetManager->substituteAssetDomain ($this->getPackageBaseUrl($name));
361: $cssFiles[$baseUrl.'/'.$css.$this->getCacheBusterSuffix ($css)]='';
362: }
363:
364: }
365: }
366:
367: if($cssFiles!==array())
368: {
369: foreach($this->cssFiles as $cssFile=>$media)
370: $cssFiles[$cssFile]=$media;
371: $this->cssFiles=$cssFiles;
372: }
373: if($jsFiles!==array())
374: {
375: if(isset($this->scriptFiles[$this->coreScriptPosition]))
376: {
377: foreach($this->scriptFiles[$this->coreScriptPosition] as $url => $value)
378: $jsFiles[$url]=$value;
379: }
380: $this->scriptFiles[$this->coreScriptPosition]=$jsFiles;
381: }
382: }
383:
384: 385: 386: 387: 388: 389:
390: public function renderX2TouchAssets () {
391: $html='';
392: $fullPage = 1;
393:
394:
395: $this->renderCoreScripts ();
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415: if(isset($this->scriptFiles[self::POS_HEAD]))
416: {
417: foreach($this->scriptFiles[self::POS_HEAD] as $scriptFileValueUrl=>$scriptFileValue)
418: {
419: if(is_array($scriptFileValue))
420: $html.=CHtml::scriptFile($scriptFileValueUrl,$scriptFileValue)."\n";
421: else
422: $html.=CHtml::scriptFile($scriptFileValueUrl)."\n";
423: }
424: }
425:
426: if(isset($this->scripts[self::POS_HEAD]))
427: $html.=$this->renderScriptBatch($this->scripts[self::POS_HEAD]);
428:
429: if(isset($this->scriptFiles[self::POS_BEGIN]))
430: {
431: foreach($this->scriptFiles[self::POS_BEGIN] as $scriptFileUrl=>$scriptFileValue)
432: {
433: if(is_array($scriptFileValue))
434: $html.=CHtml::scriptFile($scriptFileUrl,$scriptFileValue)."\n";
435: else
436: $html.=CHtml::scriptFile($scriptFileUrl)."\n";
437: }
438: }
439: if(isset($this->scripts[self::POS_BEGIN]))
440: $html.=$this->renderScriptBatch($this->scripts[self::POS_BEGIN]);
441:
442: if(isset($this->scriptFiles[self::POS_END]))
443: {
444: foreach($this->scriptFiles[self::POS_END] as $scriptFileUrl=>$scriptFileValue)
445: {
446: if(is_array($scriptFileValue))
447: $html.=CHtml::scriptFile($scriptFileUrl,$scriptFileValue)."\n";
448: else
449: $html.=CHtml::scriptFile($scriptFileUrl)."\n";
450: }
451: }
452: $scripts=isset($this->scripts[self::POS_END]) ? $this->scripts[self::POS_END] : array();
453: if(isset($this->scripts[self::POS_READY]))
454: {
455: if($fullPage)
456: $scripts[]="jQuery(function($) {\n".implode("\n",$this->scripts[self::POS_READY])."\n});";
457: else
458: $scripts[]=implode("\n",$this->scripts[self::POS_READY]);
459: }
460: if(isset($this->scripts[self::POS_LOAD]))
461: {
462: if($fullPage)
463: $scripts[]="jQuery(window).on('load',function() {\n".implode("\n",$this->scripts[self::POS_LOAD])."\n});";
464: else
465: $scripts[]=implode("\n",$this->scripts[self::POS_LOAD]);
466: }
467: if(!empty($scripts))
468: $html.=$this->renderScriptBatch($scripts);
469:
470: return $html;
471: }
472:
473: 474: 475: 476: 477: 478:
479: public function renderHead(&$output)
480: {
481: parent::renderHead ($output);
482: $html='';
483: foreach($this->metaTags as $meta)
484: $html.=CHtml::metaTag($meta['content'],null,null,$meta)."\n";
485: foreach($this->linkTags as $link)
486: $html.=CHtml::linkTag(null,null,null,null,$link)."\n";
487:
488: if (Auxlib::getIEVer () < 10) {
489:
490: $mergedCss = '';
491: $mediaType = null;
492: foreach ($this->cssFiles as $url => $media) {
493: if ($mediaType === null) {
494: $mediaType = $media;
495: }
496: $text = '@import url("'.$url.'");';
497: if ($media !== $mediaType) {
498: $html .= CHtml::css($mergedCss,$mediaType)."\n";
499: $mergedCss = '';
500: $mediaType = $media;
501: }
502: $mergedCss .= "\n".$text;
503: }
504: if ($mergedCss)
505: $html .= CHtml::css($mergedCss,$mediaType)."\n";
506: } else {
507: foreach($this->cssFiles as $url=>$media)
508: $html.=CHtml::cssFile($url,$media)."\n";
509: }
510: if (Auxlib::getIEVer () < 10) {
511:
512: $mergedCss = '';
513: $mediaType = null;
514: foreach ($this->css as $css) {
515: $text = $css[0];
516: $media = $css[1];
517: if (is_array ($text) && isset ($text['text'])) {
518: $text = $text['text'];
519: }
520: if ($mediaType === null) {
521: $mediaType = $media;
522: }
523:
524: if (preg_match ('/@import/', $text)) {
525: if ($mergedCss)
526: $html .= CHtml::css($mergedCss,$mediaType)."\n";
527: $mergedCss = '';
528: $mediaType = null;
529: $html .= CHtml::css($text,$media)."\n";
530: continue;
531: }
532:
533: if ($media !== $mediaType) {
534: $html .= CHtml::css($mergedCss,$mediaType)."\n";
535: $mergedCss = '';
536: $mediaType = $media;
537: }
538: $mergedCss .= "\n".$text;
539: }
540: if ($mergedCss)
541: $html .= CHtml::css($mergedCss,$mediaType)."\n";
542: } else {
543: foreach($this->css as $css) {
544: $text = $css[0];
545: $media = $css[1];
546:
547: if (is_array ($text) && isset ($text['text']) && isset ($text['htmlOptions'])) {
548:
549: $html.=X2Html::css ($text['text'], $media, $text['htmlOptions']);
550: continue;
551: }
552: $html.=CHtml::css($text, $media)."\n";
553: }
554: }
555:
556:
557: if (!(Yii::app()->controller instanceof AdminController) &&
558: !Yii::app()->user->isGuest &&
559: !Yii::app()->params->isMobileApp) {
560:
561: $globalCssUrl = GlobalCSSFormModel::getGlobalCssUrl ();
562: $html.=CHtml::cssFile($globalCssUrl.$this->getCacheBusterSuffix ($globalCssUrl))."\n";
563: }
564:
565:
566: if($this->enableJavaScript)
567: {
568: if(isset($this->scriptFiles[self::POS_HEAD]))
569: {
570: foreach($this->scriptFiles[self::POS_HEAD] as $scriptFileValueUrl=>$scriptFileValue)
571: {
572: if(is_array($scriptFileValue))
573: $html.=CHtml::scriptFile($scriptFileValueUrl,$scriptFileValue)."\n";
574: else
575: $html.=CHtml::scriptFile($scriptFileValueUrl)."\n";
576: }
577: }
578: if(isset($this->scripts[self::POS_HEAD]))
579: $html.=$this->renderScriptBatch($this->scripts[self::POS_HEAD]);
580: }
581: if($html!=='')
582: {
583: $count=0;
584: $output=preg_replace('/(<title\b[^>]*>|<\\/head\s*>)/is','<###head###>$1',$output,1,$count);
585: if($count)
586: $output=str_replace('<###head###>',$html,$output);
587: else
588: $output=$html.$output;
589: }
590: }
591:
592: public function registerScript($id,$script,$position=null,array $htmlOptions=array())
593: {
594: if($position===null)
595: $position=$this->defaultScriptPosition;
596: $this->hasScripts=true;
597: if(empty($htmlOptions))
598: $scriptValue=$script;
599: else
600: {
601: if($position==self::POS_LOAD || $position==self::POS_READY)
602: throw new CException(Yii::t('yii','Script HTML options are not allowed for "CClientScript::POS_LOAD" and "CClientScript::POS_READY".'));
603: $scriptValue=$htmlOptions;
604: $scriptValue['content']=$script;
605: }
606: $this->scripts[$position][$id]=$scriptValue;
607: if($position===self::POS_READY || $position===self::POS_LOAD)
608: $this->registerCoreScript('jquery');
609: $params=func_get_args();
610: $this->recordCachingAction('clientScript','registerScript',$params);
611: return $this;
612: }
613:
614: 615: 616: 617: 618:
619: private $renderedScripts = array ();
620: protected function renderScriptBatch(array $scripts)
621: {
622: $html = '';
623: $scriptBatches = array();
624:
625: foreach($scripts as $scriptName => $scriptValue)
626: {
627:
628: if (!is_numeric ($scriptName) && isset ($this->renderedScripts[$scriptName])) continue;
629: $this->renderedScripts[$scriptName] = true;
630:
631: if(is_array($scriptValue))
632: {
633: $scriptContent = $scriptValue['content'];
634: unset($scriptValue['content']);
635: $scriptHtmlOptions = $scriptValue;
636: ksort($scriptHtmlOptions);
637: }
638: else
639: {
640: $scriptContent = $scriptValue;
641: $scriptHtmlOptions = array();
642: }
643: $key=serialize($scriptHtmlOptions);
644: $scriptBatches[$key]['htmlOptions']=$scriptHtmlOptions;
645: $scriptBatches[$key]['scripts'][]=$scriptContent;
646: }
647: foreach($scriptBatches as $scriptBatch)
648: if(!empty($scriptBatch['scripts']))
649: $html.=CHtml::script(implode("\n",$scriptBatch['scripts']),$scriptBatch['htmlOptions'])."\n";
650:
651: return $html;
652: }
653:
654: 655: 656: 657:
658: public function registerCssFile ($url, $media='') {
659: if ($this->useAbsolutePaths) $url = $this->makeUrlAbsolute ($url);
660: $url = $this->getCSSPathname ($url);
661: if (X2AssetManager::$enableAssetDomains)
662: $url = Yii::app()->assetManager->substituteAssetDomain ($url);
663: return parent::registerCssFile (
664: $url.$this->getCacheBusterSuffix ($url), $media);
665: }
666:
667: 668: 669: 670: 671: 672: 673: 674:
675: public function registerCssFiles ($id, array $filenames, $prependThemeUrl=true, $media='') {
676: $cssUrl = '';
677: if ($prependThemeUrl) {
678: $cssUrl = $this->getThemeUrl ().'/css/';
679: }
680: $ieVer = Auxlib::getIEVer ();
681: if ($ieVer < 10) {
682: $cacheBuster = $this->getCacheBuster ();
683: $cssStr = '';
684: foreach ($filenames as $file) {
685: $cssStr .= '@import url("'.$cssUrl.$file.'?'.$cacheBuster.'");'."\n";
686: }
687: $this->registerCss ($id, $cssStr, $media);
688: } else {
689: foreach ($filenames as $file) {
690: $this->registerCssFile ($cssUrl.$file, $media);
691: }
692: }
693: }
694:
695: 696: 697: 698: 699:
700: private function registerResponsiveTitleBarCss () {
701: $logo = Media::model()
702: ->findByAttributes(array('associationId' => 1, 'associationType' => 'logo'));
703:
704: if (isset ($logo)) {
705: $dimensions = CJSON::decode ($logo->resolveDimensions ());
706: if (is_array ($dimensions)) {
707: $imgWidth = floor ($dimensions['width'] * (30 / $dimensions['height']));
708: Yii::app()->clientScript->registerScript('logoWidthScript',"
709: if (typeof x2 === 'undefined') x2 = {};
710: x2.logoWidth = ".$imgWidth.";
711: ", CClientScript::POS_HEAD);
712: }
713: }
714:
715: if (isset ($imgWidth)) {
716: $threshold = 915 + $imgWidth;
717: } else {
718: $threshold = 915;
719: }
720:
721: Yii::app()->clientScript->registerResponsiveCss('responsiveTitleBar',"
722: /*
723: Step between full title bar and mobile title bar. Search bar minimizes and expands to make
724: room for user menu links
725: */
726: @media (max-width: ".$threshold."px) {
727: #search-bar-box {
728: display: none;
729: width: 180px;
730: }
731: #search-bar button.x2-button {
732: border-radius: 3px 3px 3px 3px;
733: -moz-border-radius: 3px 3px 3px 3px;
734: -webkit-border-radius: 3px 3px 3px 3px;
735: -o-border-radius: 3px 3px 3px 3px;
736: }
737: }
738:
739: @media (min-width: ".$threshold."px) {
740: #user-menu > li {
741: display: block !important;
742: }
743: #search-bar-box {
744: display: block !important;
745: }
746: }
747: ");
748:
749: }
750:
751: 752: 753:
754: private function registerCombinedCss () {
755: $ieVer = Auxlib::getIEVer ();
756: $cssUrl = $this->getThemeUrl ().'/css';
757:
758: $cssFiles = array (
759: 'screen.css',
760: 'auxlib.css',
761: 'jquery-ui.css',
762: 'dragtable.css',
763: 'main.css',
764: 'ui-elements.css',
765: 'layout.css',
766: 'details.css',
767: 'x2forms.css',
768: 'form.css',
769: 'publisher.css',
770: 'sortableWidgets.css',
771: '../../../js/qtip/jquery.qtip.css',
772: '../../../js/checklistDropdown/jquery.multiselect.css',
773: 'rating/jquery.rating.css',
774: 'fontAwesome/css/font-awesome.css',
775: 'bootstrap/bootstrap.css',
776: 'css-loaders/load8.css',
777: );
778:
779:
780: $cssFiles[] = 'recordView.css';
781:
782: $responsiveCssFiles = array (
783: 'responsiveLayout.css',
784: 'responsiveUIElements.css',
785: 'responsiveX2Forms.css',
786: );
787:
788: $this->registerResponsiveTitleBarCss ();
789:
790: $this->registerCssFiles ('combinedCss', $cssFiles, 'screen, projection');
791:
792: if (AuxLib::getLayoutType () === 'responsive') {
793: $this->registerCssFiles ('responsiveCombinedCss',
794: $responsiveCssFiles, 'screen, projection');
795: }
796: }
797:
798: 799: 800:
801: public function registerX2Flashes () {
802: $this->registerScriptFile($this->baseUrl.'/js/TopFlashes.js', CClientScript::POS_END);
803: $this->registerScriptFile($this->baseUrl.'/js/X2Flashes.js', CClientScript::POS_END);
804: $this->registerScript ('registerX2Flashes', "
805: ;(function () {
806: x2.flashes = new x2.Flashes ({
807: containerId: 'x2-flashes-container',
808: expandWidgetSrc: '".Yii::app()->getTheme()->getBaseUrl().
809: '/images/icons/Expand_Widget.png'."',
810: collapseWidgetSrc: '".Yii::app()->getTheme()->getBaseUrl().
811: '/images/icons/Collapse_Widget.png'."',
812: closeWidgetSrc: '".Yii::app()->getTheme()->getBaseUrl().
813: '/images/icons/Close_Widget.png'."',
814: translations: ".CJSON::encode (array (
815: 'noticeFlashList' => Yii::t('app', '{Action} exectuted with', array(
816: '{Action}'=>Modules::displayName(false, 'Actions')
817: )),
818: 'errorFlashList' => Yii::t('app', '{Action} exectuted with', array(
819: '{Action}'=>Modules::displayName(false, 'Actions')
820: )),
821: 'noticeItemName' => Yii::t('app', 'warnings'),
822: 'errorItemName' => Yii::t('app', 'errors'),
823: 'successItemName' => Yii::t('app', 'successes'),
824: 'close' => Yii::t('app', 'Close'),
825: ))."
826: });
827: }) ();
828: ", CClientScript::POS_READY);
829: }
830:
831: private function registerX2ModelMappingsScript () {
832: $this->registerScript('x2ModelMappingsScript',"
833: x2.associationModels = ".CJSON::encode (X2Model::$associationModels).";
834: x2.modelNameToModuleName = ".CJSON::encode (X2Model::$modelNameToModuleName).";
835: ", CClientScript::POS_READY);
836: }
837:
838:
839: 840: 841:
842: private function registerX2Forms () {
843: $this->registerScriptFile($this->baseUrl.'/js/X2Forms.js');
844: $this->registerScript('registerX2Forms',"
845: x2.forms = new x2.Forms ({
846: translations: ".CJSON::encode (array (
847: 'Check All' => Yii::t('app', 'Check All'),
848: 'Uncheck All' => Yii::t('app', 'Uncheck All'),
849: 'selected' => Yii::t('app', 'selected'),
850: ))."
851: });
852: ", CClientScript::POS_END);
853: }
854:
855: private function registerX2QuickCRUD () {
856: $this->registerPackages (array (
857: 'QuickCRUD' => array(
858: 'baseUrl' => Yii::app()->request->baseUrl,
859: 'js' => array(
860: 'js/X2Widget.js',
861: 'js/X2QuickCRUD.js',
862: 'js/X2QuickCreate.js',
863: 'js/X2QuickRead.js',
864: ),
865: ),
866: ));
867: $modelsWhichSupportQuickCreate =
868: QuickCreateRelationshipBehavior::getModelsWhichSupportQuickCreate (true);
869: $createUrls = QuickCreateRelationshipBehavior::getCreateUrlsForModels (
870: $modelsWhichSupportQuickCreate);
871: $viewUrls = QuickCRUDBehavior::getUrlsForModels (
872: QuickCRUDBehavior::getModelsWhichSupportQuickView (), 'view');
873: $dialogTitles = QuickCreateRelationshipBehavior::getDialogTitlesForModels (
874: $modelsWhichSupportQuickCreate);
875: $this->registerScript('registerQuickCreate',"
876: x2.QuickCreate.createRecordUrls = ".CJSON::encode ($createUrls).";
877: x2.QuickCreate.dialogTitles = ".CJSON::encode ($dialogTitles).";
878: x2.QuickRead.viewRecordUrls = ".CJSON::encode ($viewUrls).";
879: x2.QuickRead.translations = ".CJSON::encode (array (
880: 'View inline record details' => Yii::t('app', 'View inline record details'),
881: )).";
882: x2.QuickRead.dialogTitles = ".CJSON::encode ($dialogTitles).";
883: ", CClientScript::POS_END);
884: }
885:
886: private function registerAttachments () {
887: $this->registerScriptFile($this->baseUrl.'/js/Attachments.js');
888: $this->registerScript('X2ClientScript.registerAttachments',"
889: x2.attachments = new x2.Attachments ({
890: translations: ".CJSON::encode (array (
891: 'filetypeError' => Yii::t('app', '"{X}" is not an allowed filetype.'),
892: ))."
893: });
894: ", CClientScript::POS_END);
895: }
896:
897: 898: 899:
900: private function registerDateFormats () {
901: $this->registerScript('registerDateFormats',"
902: x2.dateFormats = {
903: dateFormat: '".Formatter::formatDatePicker()."',
904: timeFormat: '".Formatter::formatTimePicker()."',
905: ampm: '".Formatter::formatAMPM()."'
906: };
907: ", CClientScript::POS_END);
908: }
909:
910: private function registerAuxLibTranslationsScript () {
911: $this->registerScript('registerDateFormats',"
912: auxlib.translations = ".CJSON::encode (array (
913: 'Are you sure you want to delete this item?' =>
914: Yii::t('app', 'Are you sure you want to delete this item?'),
915: 'Delete item?' => Yii::t('app', 'Delete item?'),
916: 'Cancel' => Yii::t('app','Cancel'),
917: 'Confirm' => Yii::t('app', 'Confirm')
918: )).";
919: ", CClientScript::POS_END);
920: }
921:
922: private function registerTestingScripts () {
923: if (YII_UNIT_TESTING) {
924:
925:
926:
927: Yii::app()->clientScript->registerScript('unitTestingErrorHandler',"
928: ;(function () {
929: if (typeof x2 === 'undefined') return;
930: if (x2.UNIT_TESTING) {
931: var oldErrorHandler = window.onerror;
932: window.onerror = function (errorMessage, url, lineNumber) {
933: $('body').attr (
934: 'x2-js-error', 'Javascript Error: ' + url + ': ' + lineNumber + ': ' +
935: errorMessage);
936:
937: if (oldErrorHandler)
938: return oldErrorHandler (errorMessage, url, lineNumber);
939: return false;
940: };
941: }
942: }) ();
943: ", self::POS_HEAD);
944: }
945: }
946:
947: private function registerDebuggingScripts () {
948: if (YII_DEBUG) {
949: Yii::app()->clientScript->registerScript('debuggingErrorHandler',"
950: ;(function () {
951: if (typeof x2 === 'undefined') return;
952: if (x2.DEBUG) {
953: var oldErrorHandler = window.onerror;
954: window.onerror = function (errorMessage, url, lineNumber) {
955: // alert (
956: // 'JavaScript Error: ' + url + ': ' + lineNumber + ': ' + errorMessage +
957: // '.\\nTo turn these messages off, set YII_DEBUG to false.');
958: if (oldErrorHandler) return oldErrorHandler (errorMessage, url, lineNumber);
959: return false;
960: };
961: }
962: }) ();
963: ", self::POS_HEAD);
964: }
965: }
966:
967: 968: 969:
970: public function registerMain(){
971: $fullscreen = $this->fullscreen;
972: $profile = $this->profile;
973: $baseUrl = $this->baseUrl;
974: $themeUrl = $this->themeUrl;
975: $scriptUrl = $this->scriptUrl;
976: $admin = $this->admin;
977: $isGuest = $this->isGuest;
978:
979:
980:
981: $this->registerCoreScript('jquery')
982: ->registerCoreScript('jquery.ui')
983: ->registerCoreScript('jquery.migrate')
984: ->registerCoreScript('bbq')
985: ;
986:
987: $this->registerPackages($this->getDefaultPackages());
988:
989: $cldScript = $this->getCurrencyConfigScript ();
990:
991: AuxLib::registerPassVarsToClientScriptScript('auxlib', array(
992: 'saveMiscLayoutSettingUrl' =>
993: "'".addslashes(Yii::app()->createUrl('/profile/saveMiscLayoutSetting'))."'"
994: ), 'passAuxLibVars'
995: );
996:
997: $this->registerX2ModelMappingsScript ();
998: $this->registerX2Forms ();
999: $this->registerX2QuickCRUD ();
1000: $this->registerX2Flashes ();
1001:
1002: Yii::app()->clientScript->registerScript('csrfTokenScript', "
1003: x2.csrfToken = '".Yii::app()->request->getCsrfToken ()."';
1004: ", CClientScript::POS_HEAD);
1005:
1006: $this->registerAttachments ();
1007: $this->registerDateFormats ();
1008: if (YII_DEBUG) $this->registerScriptFile($baseUrl.'/js/Timer.js');
1009:
1010: Yii::app()->clientScript->registerPackage('spectrum');
1011:
1012:
1013: $this->registerScriptFile($baseUrl.'/js/json2.js')
1014: ->registerScriptFile(
1015: $baseUrl.'/js/lib/lodash/lodash.js', self::POS_END)
1016: ->registerScriptFile($baseUrl.'/js/webtoolkit.sha256.js')
1017: ->registerScriptFile($baseUrl.'/js/main.js', CCLientScript::POS_HEAD)
1018: ->registerScriptFile($baseUrl.'/js/auxlib.js', CClientScript::POS_HEAD)
1019: ->registerScriptFile($baseUrl.'/js/IframeFixOverlay.js', CClientScript::POS_HEAD)
1020: ->registerScriptFile($baseUrl.'/js/LayoutManager.js')
1021:
1022: ->registerScriptFile($baseUrl.'/js/media.js')
1023: ->registerScript('formatCurrency-locales', $cldScript, CCLientScript::POS_HEAD)
1024: ->registerScriptFile($baseUrl.'/js/modernizr.custom.66175.js')
1025: ->registerScriptFile($baseUrl.'/js/widgets.js')
1026: ->registerScriptFile($baseUrl.'/js/qtip/jquery.qtip.js')
1027: ->registerScriptFile($baseUrl.'/js/ActionFrames.js')
1028: ->registerScriptFile($baseUrl.'/js/ColorPicker.js', CCLientScript::POS_END)
1029: ->registerScriptFile($baseUrl.'/js/PopupDropdownMenu.js', CCLientScript::POS_END)
1030: ->registerScriptFile($baseUrl.'/js/jQueryOverrides.js', CCLientScript::POS_END)
1031: ->registerScriptFile($baseUrl.'/js/checklistDropdown/jquery.multiselect.js');
1032:
1033: $this->registerTestingScripts ();
1034: $this->registerDebuggingScripts ();
1035:
1036: if(AuxLib::isIPad ()){
1037: $this->registerScriptFile($baseUrl.'/js/jquery.mobile.custom.js');
1038: }
1039: $this->registerInitScript ();
1040: $this->registerAuxLibTranslationsScript ();
1041:
1042: if(Yii::app()->session['translate'])
1043: $this->registerScriptFile($baseUrl.'/js/translator.js');
1044:
1045: $this->registerScriptFile($baseUrl.'/js/backgroundFade.js');
1046: $this->registerScript('datepickerLanguage', "
1047: $.datepicker.setDefaults($.datepicker.regional['']);
1048: ");
1049: $mmPath = Yii::getPathOfAlias('application.extensions.moneymask.assets');
1050: $aMmPath = Yii::app()->getAssetManager()->publish($mmPath);
1051: $this->registerScriptFile("$aMmPath/jquery.maskMoney.js");
1052: $this->registerCssFile($baseUrl.'/css/normalize.css', 'all')
1053: ->registerCssFile($themeUrl.'/css/print.css', 'print')
1054: ->registerCoreScript('cookie');
1055: $this->registerCombinedCss ();
1056: if(AuxLib::getLayoutType () !== 'responsive' && AuxLib::isAndroid ()) {
1057: $this->registerCssFile(
1058: $themeUrl.'/css/androidLayout.css', 'screen, projection');
1059: } elseif (AuxLib::isIPad ()) {
1060: $this->registerCssFile($themeUrl.'/css/ipadLayout.css', 'screen, projection');
1061: }
1062:
1063: $this->registerScript('fullscreenToggle', '
1064: window.enableFullWidth = '.(!Yii::app()->user->isGuest ?
1065: ($profile->enableFullWidth ? 'true' : 'false') : 'true').';
1066: window.fullscreen = '.($fullscreen ? 'true' : 'false').';
1067: ', CClientScript::POS_HEAD);
1068:
1069: if(is_object(Yii::app()->controller->module)){
1070: $this->registerScript('saveCurrModule', "
1071: x2.currModule = '".Yii::app()->controller->module->name."';
1072: ", CClientScript::POS_HEAD);
1073: }
1074:
1075: if(!$isGuest){
1076: $this->registerScript('notificationsParams', "
1077: x2.notifications = new x2.Notifs ({
1078: disablePopup: ".($profile->disableNotifPopup ? 'true' : 'false').",
1079: translations: {
1080: clearAll: '".addslashes(
1081: Yii::t('app', 'Permanently delete all notifications?'))."'
1082: }
1083: });
1084: ", CClientScript::POS_READY);
1085: $this->registerScriptFile($baseUrl.'/js/jstorage.min.js')
1086: ->registerScriptFile(
1087: $baseUrl.'/js/notifications.js', CClientScript::POS_BEGIN);
1088: }
1089:
1090: if(!$isGuest && ($profile->language == 'he' || $profile->language == 'fa'))
1091: $this->registerCss('rtl-language', 'body{text-align:right;}');
1092:
1093: $this->registerCoreScript('rating');
1094: }
1095:
1096: public function getAdmin() {
1097: if(!isset($this->_admin)) {
1098: $this->_admin = Yii::app()->settings;
1099: }
1100: return $this->_admin;
1101: }
1102:
1103: public function setAdmin(Admin $value) {
1104: $this->_admin = $value;
1105: }
1106:
1107: public function getBaseUrl(){
1108: if(!isset($this->_baseUrl)){
1109: $this->_baseUrl = Yii::app()->baseUrl;
1110: }
1111: return $this->_baseUrl;
1112: }
1113:
1114: public function setBaseUrl($value){
1115: $this->_baseUrl = $value;
1116: }
1117:
1118: public function getFullscreen() {
1119: if(!isset($this->_fullscreen)) {
1120: $this->_fullscreen = Yii::app()->user->isGuest || $this->profile->fullscreen;
1121: }
1122: return $this->_fullscreen;
1123: }
1124:
1125: public function setFullscreen($value) {
1126: $this->_fullscreen = $value;
1127: }
1128:
1129: public function getIsGuest() {
1130: if(!isset($this->_isGuest)) {
1131: $this->_isGuest = Yii::app()->user->isGuest;
1132: }
1133: return $this->_isGuest;
1134: }
1135: public function setIsGuest($value) {
1136: $this->_isGuest = $value;
1137: }
1138:
1139: public function getProfile() {
1140: if(!isset($this->_profile)) {
1141: $this->_profile = Yii::app()->params->profile;
1142: }
1143: return $this->_profile;
1144:
1145: }
1146:
1147: public function setProfile(Profile $value) {
1148: $this->_profile = $value;
1149: }
1150:
1151: public function getScriptUrl() {
1152: if(!isset($this->_scriptUrl)) {
1153: $this->_scriptUrl = Yii::app()->request->scriptUrl;
1154: }
1155: return $this->_scriptUrl;
1156: }
1157:
1158: public function setScriptUrl( $value) {
1159: $this->_scriptUrl = $value;
1160: }
1161:
1162: public function getThemeUrl() {
1163: if(!isset($this->_themeUrl)) {
1164: $this->_themeUrl = Yii::app()->theme->baseUrl;
1165: }
1166: return $this->_themeUrl;
1167: }
1168: public function setThemeUrl($value) {
1169: $this->_themeUrl = $value;
1170: }
1171:
1172: private function registerInitScript () {
1173: Yii::app()->clientScript->registerScript ('X2ClientScriptInitScript',"
1174: ;(function () {
1175: var actionFramesName = 'actionFrames';
1176: x2[actionFramesName] = new x2.ActionFrames ({
1177: instanceName: actionFramesName,
1178: deleteActionUrl: '".
1179: Yii::app()->controller->createUrl ('/actions/actions/delete')."'
1180: });
1181: }) ();
1182: ", CClientScript::POS_HEAD);
1183: }
1184:
1185: private function getJSPathname ($path) {
1186: if (preg_match ('/\.min\.js$/', $path)) return $path;
1187: $fileName = str_replace('/',DIRECTORY_SEPARATOR, str_replace(Yii::app()->baseUrl, '', $path));
1188: $altPath = Yii::getRootPath ().preg_replace ('/\.js(\?\d+)?$/', '.min.js', $fileName);
1189: if (!YII_DEBUG && file_exists ($altPath)) {
1190: return preg_replace ('/\.js(\?\d+)?$/', '.min.js\1', $path);
1191: } else {
1192: return $path;
1193: }
1194: }
1195:
1196: private function getCSSPathname ($path) {
1197: if (preg_match ('/\.min\.css$/', $path)) return $path;
1198: $fileName = str_replace('/',DIRECTORY_SEPARATOR, str_replace(Yii::app()->baseUrl, '', $path));
1199: $altPath = Yii::getRootPath ().preg_replace ('/\.css(\?\d+)?$/', '.min.css', $fileName);
1200: if (!YII_DEBUG && file_exists ($altPath)) {
1201: return preg_replace ('/\.css(\?\d+)?$/', '.min.css\1', $path);
1202: } else {
1203: return $path;
1204: }
1205: }
1206:
1207: }
1208: