Author: remi
Date: 2009-06-27 13:59:10 +0200 (Sat, 27 Jun 2009)
New Revision: 4917

Modified:
   
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/js/common.js
   
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/xsl/gadgets.xsl
   
software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py
Log:
* added dynamic enabling/disabling of the buttons in the "gadgets" web page.

Modified: 
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/js/common.js
===================================================================
--- 
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/js/common.js
     2009-06-27 11:57:50 UTC (rev 4916)
+++ 
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/js/common.js
     2009-06-27 11:59:10 UTC (rev 4917)
@@ -406,3 +406,20 @@
     }
     window.open(url);
 }
+
+/**
+ *
+ */
+function clickMe(element)
+{
+    try
+    {
+        document.getElementById(element).click();
+    } catch(e)
+    {
+        var evt = document.createEvent("MouseEvents");
+        evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, 
false, false, false, 0, null);
+        var cb = document.getElementById(element);
+        cb.dispatchEvent(evt);
+    }
+}

Modified: 
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/xsl/gadgets.xsl
===================================================================
--- 
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/xsl/gadgets.xsl
  2009-06-27 11:57:50 UTC (rev 4916)
+++ 
software_suite_v3/smart-core/smart-server/trunk/data/web_interface/user_01/xsl/gadgets.xsl
  2009-06-27 11:59:10 UTC (rev 4917)
@@ -35,6 +35,8 @@
         <![CDATA[
             var knowedGadgetsFilter = "all";
             var knowedGadgetsDict = null;
+            var knowedPlayingGadgetUuid1 = "0";
+            var knowedPlayingGadgetUuid2 = "0";
             var lastUuidAction = "0";
             var translationStart = "";
             var translationStop = ""
@@ -46,8 +48,77 @@
                 translationStop = 
document.getElementById("translationStop").value;
                 translationDelete = 
document.getElementById("translationDelete").value;
                 fillGadgetRows("all");
+                updatePlayingGadgetUuid();
             }
 
+            function updatePlayingGadgetUuid()
+            {
+                var result = 
requestData("/robot_content_interactions/get_current_playing_gadgets",{});
+                if (result != null)
+                {
+                    if (!result.containsKey("uuid1"))
+                    {
+                        setTimeout("updatePlayingGadgetUuid()", 500);
+                        return;
+                    }
+                }
+                else
+                {
+                    setTimeout("updatePlayingGadgetUuid()", 500);
+                    return;
+                }
+                var uuid1 = result.get("uuid1");
+                var uuid2 = result.get("uuid2");
+                if ((uuid1 != knowedPlayingGadgetUuid1) || (uuid2 != 
knowedPlayingGadgetUuid2))
+                {
+                    knowedPlayingGadgetUuid1 = uuid1;
+                    knowedPlayingGadgetUuid2 = uuid2;
+                    if (knowedGadgetsDict != null)
+                    {
+                        var gadgets = knowedGadgetsDict;
+                        var gadgetsCount = 
parseInt(gadgets.get("data0").get("count"));
+                        for (i = 0; i < gadgetsCount; i++)
+                        {
+                            gUuid = gadgets.get("data0").get("gadget_" + i + 
"_uuid");
+                            ondemand = gadgets.get("data0").get("gadget_" + i 
+ "_ondemand");
+                            if (thisGadgetIsPlaying(gUuid))
+                            {
+                                if (ondemand == "true")
+                                {
+                                    setStartedGadgetButtons(gUuid);
+                                }
+                                else
+                                {
+                                    disableStartStopGadgetButtons(gUuid);
+                                }
+                                disableEditGadgetButtons(gUuid);
+                            }
+                            else
+                            {
+                                if (aGadgetIsPlaying())
+                                {
+                                    disableStartStopGadgetButtons(gUuid);
+                                    enableEditGadgetButtons(gUuid);
+                                }
+                                else
+                                {
+                                    if (ondemand == "true")
+                                    {
+                                        enableStartStopGadgetButtons(gUuid);
+                                    }
+                                    else
+                                    {
+                                        disableStartStopGadgetButtons(gUuid);
+                                    }
+                                    enableEditGadgetButtons(gUuid);
+                                }
+                            }
+                        }
+                    }
+                }
+                setTimeout("updatePlayingGadgetUuid()", 500);
+            }
+
             function fillGadgetRows(filter)
             {
                 var gadgets = 
requestData("/robot_content_interactions/get_gadgets_data",{'filter' : filter});
@@ -70,6 +141,8 @@
                     return;
                 }
                 knowedGadgetsDict = gadgets;
+                knowedPlayingGadgetUuid1 = "0";
+                knowedPlayingGadgetUuid2 = "0";
                 var htmlContent = "";
                 var gadgetsCount = parseInt(gadgets.get("data0").get("count"));
                 for (i = 0; i < gadgetsCount; i++)
@@ -130,7 +203,7 @@
                 htmlContent += '<div class="gadgetsVSpacer" 
style="width:8px;"></div>';
                 if (ondemand == 'true')
                 {
-                    htmlContent += '<a class="gadgetsBtnTitle 
gadgetsBtnStopEnable" id="stopId_' + uuid + '" 
onclick="javascript:stopGadget();return false;" href="#">' + translationStop + 
'</a>';
+                    htmlContent += '<a class="gadgetsBtnTitle 
gadgetsBtnStopEnable" id="stopId_' + uuid + '" 
onclick="javascript:stopGadget(\''+uuid+'\');return false;" href="#">' + 
translationStop + '</a>';
                 }
                 else
                 {
@@ -169,9 +242,15 @@
             function enableStartStopGadgetButtons(uuid)
             {
                 document.getElementById("startId_" + uuid).className = 
"gadgetsBtnTitle gadgetsBtnStartEnable";
-                document.getElementById("stopId_" + uuid).className = 
"gadgetsBtnTitle gadgetsBtnStopActivate";
+                document.getElementById("stopId_" + uuid).className = 
"gadgetsBtnTitle gadgetsBtnStopEnable";
             }
 
+            function setStartedGadgetButtons(uuid)
+            {
+                document.getElementById("startId_" + uuid).className = 
"gadgetsBtnTitle gadgetsBtnStartActivate";
+                document.getElementById("stopId_" + uuid).className = 
"gadgetsBtnTitle gadgetsBtnStopEnable";
+            }
+
             function disableEditGadgetButtons(uuid)
             {
                 document.getElementById("helpId_" + uuid).className = 
"gadgetsBtnNoTitle gadgetsBtnHelpDisable";
@@ -188,20 +267,69 @@
                 document.getElementById("deleteId_" + uuid).className = 
"gadgetsBtnTitle gadgetsBtnDelete";
             }
 
+            function thisGadgetIsPlaying(uuid)
+            {
+                if ((uuid == knowedPlayingGadgetUuid1) || (uuid == 
knowedPlayingGadgetUuid2))
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+
+            function aGadgetIsPlaying()
+            {
+                if ((knowedPlayingGadgetUuid1 != "0") || 
(knowedPlayingGadgetUuid2 != "0"))
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+
             function startGadget(uuid)
             {
+                if (aGadgetIsPlaying())
+                {
+                    return;
+                }
                 getRequest("/robot_content_interactions/start_gadget_by_uuid", 
{'uuid' : uuid});
             }
 
-            function stopGadget()
+            function stopGadget(uuid)
             {
+                if (aGadgetIsPlaying())
+                {
+                    if (!thisGadgetIsPlaying(uuid))
+                    {
+                        return;
+                    }
+                }
+                else
+                {
+                    return;
+                }
                 getRequest("/robot_content_interactions/stop_gadget", {});
             }
 
             function setUuidAction(uuid)
             {
                 var idx = uuid.indexOf("_", 0) + 1;
-                lastUuidAction = uuid.slice(idx, uuid.length);
+                uuid = uuid.slice(idx, uuid.length);
+                if (aGadgetIsPlaying())
+                {
+                    if (thisGadgetIsPlaying(uuid))
+                    {
+                        lastUuidAction = "0";
+                        clickMe("closeLightbox");
+                        return;
+                    }
+                }
+                lastUuidAction = uuid;
             }
 
             function duplicateUgc()
@@ -316,6 +444,7 @@
                 <xsl:element name="a">
                     <xsl:attribute name="class">popupBtn</xsl:attribute>
                     <xsl:attribute name="name">lbOff</xsl:attribute>
+                    <xsl:attribute name="id">closeLightbox</xsl:attribute>
                     <xsl:attribute name="rel">deactivate</xsl:attribute>
                     <xsl:attribute name="href">#</xsl:attribute><xsl:value-of 
select="root/translations/no"/>
                 </xsl:element>

Modified: 
software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py
      2009-06-27 11:57:50 UTC (rev 4916)
+++ 
software_suite_v3/smart-core/smart-server/trunk/resources/04_robot_content_interactions/00_resourceRobotContentInteractions.py
      2009-06-27 11:59:10 UTC (rev 4917)
@@ -440,6 +440,8 @@
         for i, ugcObj in enumerate(self.__onDemandList):
             if ugcObj.getDescription().getUuid() == uuid:
                 self.__onDemandIndex = i
+                self.computeOnDemandDictForThumbnailBar()
+                break
 
     def computeOnDemandDictForThumbnailBar(self):
         """
@@ -944,6 +946,23 @@
                 return
             ugc.start(ugc.getDefaultRunCommandName())
 
+    def getCurrentPlayingGadgets(self):
+        """
+        """
+        if not self.isStarted():
+            return "0", "0"
+        uuid1 = "0"
+        fc = self.getForegroundPguContext()
+        if fc != None:
+            if fc.executionIsStarted():
+                uuid1 = fc.getPguUuid()
+        uuid2 = "0"
+        bc = self.getBackgroundPguContext()
+        if bc != None:
+            if bc.executionIsStarted():
+                uuid2 = bc.getPguUuid()
+        return uuid1, uuid2
+
     def __contextLTPrevious(self, eventName, *args):
         """
         """
@@ -1344,6 +1363,30 @@
 
resourceRobotContentInteractions.addService(TDSServiceRobotContentInteractionsStartStopGadget)
 
 # 
------------------------------------------------------------------------------
+# Declaration of the service "get_current_playing_gadgets".
+# 
------------------------------------------------------------------------------
+class TDSServiceRobotContentInteractionsGetCurrentPlayingGadgets(TDSService):
+
+    def configure(self):
+        self.parametersDict = {}
+        self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+        self.exclusiveExecution = True
+        self.name = "get_current_playing_gadgets"
+        self.comment = "Get the current playing gadgets uuid."
+
+    def execute(self, id, parameters):
+        headersStruct = self.getDefaultHeadersStruct()
+        contentStruct = self.getDefaultContentStruct()
+        uuid1, uuid2 = 
resourceRobotContentInteractions.getPguContextsManager().getCurrentPlayingGadgets()
+        contentStruct['root']['uuid1'] = uuid1
+        contentStruct['root']['uuid2'] = uuid2
+        contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+        return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceRobotContentInteractions.addService(TDSServiceRobotContentInteractionsGetCurrentPlayingGadgets)
+
+# 
------------------------------------------------------------------------------
 # Declaration of the service "get_gadgets_data".
 # 
------------------------------------------------------------------------------
 class TDSServiceRobotContentInteractionsGetGadgetsData(TDSService):


------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to