fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [9197] api: add wrapper


From: Sigurd Nes
Subject: [Fmsystem-commits] [9197] api: add wrapper
Date: Sat, 21 Apr 2012 19:39:24 +0000

Revision: 9197
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9197
Author:   sigurdne
Date:     2012-04-21 19:39:22 +0000 (Sat, 21 Apr 2012)
Log Message:
-----------
api: add wrapper

Modified Paths:
--------------
    trunk/phpgwapi/inc/class.jqcal.inc.php

Added Paths:
-----------
    trunk/phpgwapi/inc/class.jquery.inc.php

Modified: trunk/phpgwapi/inc/class.jqcal.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.jqcal.inc.php      2012-04-21 18:28:15 UTC (rev 
9196)
+++ trunk/phpgwapi/inc/class.jqcal.inc.php      2012-04-21 19:39:22 UTC (rev 
9197)
@@ -11,6 +11,12 @@
        */
 
        /**
+       * Import the jQuery class
+       */
+       phpgw::import_class('phpgwapi.jquery');
+
+
+       /**
        * jQuery datepicker wrapper-class
        *
        * @package phpgwapi
@@ -25,11 +31,9 @@
 
                function __construct()
                {
+                       phpgwapi_jquery::load_widget('datepicker');
+
                        $theme = 'ui-lightness';
-                       $GLOBALS['phpgw']->js->validate_file( 'jquery', 
'js/jquery-1.7.2.min', 'phpgwapi' );
-                       $GLOBALS['phpgw']->js->validate_file( 'jquery', 
'js/jquery-ui-1.8.19.custom.min', 'phpgwapi' );
-                       $GLOBALS['phpgw']->js->validate_file( 'jquery', 
'js/jquery-ui-1.8.19.custom.min', 'phpgwapi' );
-                       $GLOBALS['phpgw']->js->validate_file( 'jquery', 
"development-bundle/ui/i18n/jquery.ui.datepicker-{$GLOBALS['phpgw_info']['user']['preferences']['common']['lang']}",
 'phpgwapi' );
                        
$GLOBALS['phpgw']->css->add_external_file("phpgwapi/js/jquery/css/{$theme}/jquery-ui-1.8.19.custom.css");
                        $this->img_cal = 
$GLOBALS['phpgw']->common->image('phpgwapi','cal');
                        $this->dateformat = str_ireplace(array('d', 'm', 'y'), 
array('dd', 'mm', 
'yy'),$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);

Added: trunk/phpgwapi/inc/class.jquery.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.jquery.inc.php                             (rev 0)
+++ trunk/phpgwapi/inc/class.jquery.inc.php     2012-04-21 19:39:22 UTC (rev 
9197)
@@ -0,0 +1,87 @@
+<?php
+       /**
+        * phpGroupWare jQuery wrapper class
+        *
+        * @author Sigurd Nes
+        * @copyright Copyright (C) 2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+        * @license http://www.fsf.org/licenses/gpl.html GNU General Public 
License
+        * @package phpgroupware
+        * @subpackage phpgwapi
+        * @version $Id: class.yui.inc.php 7951 2011-10-26 13:48:40Z sigurdne $
+        */
+
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU General Public License as published by
+          the Free Software Foundation, either version 2 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU General Public License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
+       /**
+        * phpGroupWare jQuery wrapper class
+        *
+        * @package phpgroupware
+        * @subpackage phpgwapi
+        * @category gui
+        */
+
+
+       class phpgwapi_jquery
+       {
+               /**
+               * @var int $counter the widget id counter
+               */
+               private static $counter = 0;
+
+               /**
+               * Load all the dependencies for a YUI widget
+               *
+               * @param string $widget the name of the widget to load, such as 
autocomplete
+               *
+               * @return string yahoo namespace for widget - empty string on 
failure
+               *
+               * @internal this does not render the widget it only includes 
the header js files
+               */
+               public static function load_widget($widget)
+               {
+                       $_type = '.min';        // save some download
+
+                       $load = array();
+                       switch ( $widget )
+                       {
+                               case 'core':
+                                       $load = 
array("js/jquery-1.7.2{$_type}");
+                                       break;
+                               
+                               case 'datepicker':
+                                       $load = 
array("js/jquery-1.7.2{$_type}", "js/jquery-ui-1.8.19.custom{$_type}", 
"development-bundle/ui/i18n/jquery.ui.datepicker-{$GLOBALS['phpgw_info']['user']['preferences']['common']['lang']}");
+                                       break;
+
+                               default:
+                                       $err = "Unsupported YUI widget '%1' 
supplied to phpgwapi_yui::load_widget()";
+                                       trigger_error(lang($err, $widget), 
E_USER_WARNING);
+                                       return '';
+                       }
+
+                       foreach ( $load as $script )
+                       {
+                               $test = 
$GLOBALS['phpgw']->js->validate_file('jquery', $script);
+
+                               if ( !$test )
+                               {
+                                       $err = "Unable to load jQuery script 
'%1' when attempting to load widget: '%2'";
+                                       trigger_error(lang($err, $script, 
$widget), E_USER_WARNING);
+                                       return '';
+                               }
+                       }
+                       return "phpgroupware.{$widget}" . ++self::$counter;
+               }
+       }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]