From e194ff0dc81f1e0fddf1ad4f0bd0529ed5c6ae98 Mon Sep 17 00:00:00 2001
From: James <james@james-HP-Pavilion-g6-Notebook-PC>
Date: Mon, 19 Mar 2012 16:08:23 -0400
Subject: [PATCH] CC-3469: Stream settings: Connection URLs are not generated
 correctly

- done
---
 .../controllers/PreferenceController.php      |  1 +
 .../forms/LiveStreamingPreferences.php        | 31 +++++++++++++++++++
 .../js/airtime/preferences/streamsetting.js   | 17 +++++++---
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php
index 607592217..f78d31858 100644
--- a/airtime_mvc/application/controllers/PreferenceController.php
+++ b/airtime_mvc/application/controllers/PreferenceController.php
@@ -231,6 +231,7 @@ class PreferenceController extends Zend_Controller_Action
                 Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
                 $this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
             }
+            $live_stream_subform->updateConnectionURLs();
         }
         
         $this->view->confirm_pypo_restart_text = "Updating settings will temporarily interrupt any currently playing shows. Click \'OK\' to continue.";
diff --git a/airtime_mvc/application/forms/LiveStreamingPreferences.php b/airtime_mvc/application/forms/LiveStreamingPreferences.php
index 235d75786..3a73ed166 100644
--- a/airtime_mvc/application/forms/LiveStreamingPreferences.php
+++ b/airtime_mvc/application/forms/LiveStreamingPreferences.php
@@ -70,8 +70,39 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
         $master_dj_connection_url = ($master_dj_connection_url == "")?("http://".$_SERVER['SERVER_NAME'].":".$m_port."/".$m_mount):$master_dj_connection_url;
         $live_dj_connection_url = ($live_dj_connection_url == "")?"http://".$_SERVER['SERVER_NAME'].":".$l_port."/".$l_mount:$live_dj_connection_url;
         
+        if($m_port=="" || $m_mount==""){
+            $master_dj_connection_url = "N/A";
+        }
+        if($l_port=="" || $l_mount==""){
+            $live_dj_connection_url = "N/A";
+        }
+        
         $this->setDecorators(array(
             array('ViewScript', array('viewScript' => 'form/preferences_livestream.phtml', 'master_dj_connection_url'=>$master_dj_connection_url, 'live_dj_connection_url'=>$live_dj_connection_url,))
         ));
     }
+    
+    public function updateConnectionURLs(){
+        $m_port = Application_Model_StreamSetting::GetMasterLiveSteamPort();
+        $m_mount = Application_Model_StreamSetting::GetMasterLiveSteamMountPoint();
+        $l_port = Application_Model_StreamSetting::GetDJLiveSteamPort();
+        $l_mount = Application_Model_StreamSetting::GetDJLiveSteamMountPoint();
+        
+        $master_dj_connection_url = Application_Model_Preference::GetMasterDJSourceConnectionURL();
+        $live_dj_connection_url = Application_Model_Preference::GetLiveDJSourceConnectionURL();
+        
+        $master_dj_connection_url = ($master_dj_connection_url == "")?("http://".$_SERVER['SERVER_NAME'].":".$m_port."/".$m_mount):$master_dj_connection_url;
+        $live_dj_connection_url = ($live_dj_connection_url == "")?"http://".$_SERVER['SERVER_NAME'].":".$l_port."/".$l_mount:$live_dj_connection_url;
+        
+        if($m_port=="" || $m_mount==""){
+            $master_dj_connection_url = "N/A";
+        }
+        if($l_port=="" || $l_mount==""){
+            $live_dj_connection_url = "N/A";
+        }
+        
+        $this->setDecorators(array(
+        array('ViewScript', array('viewScript' => 'form/preferences_livestream.phtml', 'master_dj_connection_url'=>$master_dj_connection_url, 'live_dj_connection_url'=>$live_dj_connection_url,))
+        ));
+    }
 }
\ No newline at end of file
diff --git a/airtime_mvc/public/js/airtime/preferences/streamsetting.js b/airtime_mvc/public/js/airtime/preferences/streamsetting.js
index 4dcb8476e..747a7525b 100644
--- a/airtime_mvc/public/js/airtime/preferences/streamsetting.js
+++ b/airtime_mvc/public/js/airtime/preferences/streamsetting.js
@@ -107,10 +107,11 @@ function checkLiquidsoapStatus(){
 }
 
 function setLiveSourceConnectionOverrideListener(){
-    $("[id=connection_url_override]").click(function(){
+    $("[id=connection_url_override]").click(function(event){
         var div_ele = $(this).parent().find("div[id$='_dj_connection_url_tb']")
         div_ele.find(":input").val("")
         div_ele.show()
+        event.preventDefault()
     })
     
     // set action for "OK" and "X"
@@ -119,36 +120,42 @@ function setLiveSourceConnectionOverrideListener(){
     var master_dj_input = $("#master_dj_connection_url_tb")
     var master_dj_label = master_dj_input.parent().find("span")
     
-    live_dj_input.find("#ok").click(function(){
+    live_dj_input.find("#ok").click(function(event){
+    	event.preventDefault()
         var url = $(this).parent().find(":input").val()
         live_dj_label.html(url)
         live_dj_input.hide()
         $.get("/Preference/set-source-connection-url/", {format: "json", type: "livedj", url:encodeURIComponent(url)});
+    	event.preventDefault()
     })
     
-    live_dj_input.find("#reset").click(function(){
+    live_dj_input.find("#reset").click(function(event){
+    	event.preventDefault()
         var port = $("#dj_harbor_input_port").val()
         var mount = $("#dj_harbor_input_mount_point").val()
         var url = "http://"+location.hostname+":"+port+"/"+mount
         live_dj_label.html(url)
         live_dj_input.hide()
         $.get("/Preference/set-source-connection-url", {format: "json", type: "livedj", url:encodeURIComponent(url)});
+    	event.preventDefault()
     })
     
-    master_dj_input.find("#ok").click(function(){
+    master_dj_input.find("#ok").click(function(event){
         var url = $(this).parent().find(":input").val()
         master_dj_label.html(url)
         master_dj_input.hide()
         $.get("/Preference/set-source-connection-url", {format: "json", type: "masterdj", url:encodeURIComponent(url)})
+        event.preventDefault()
     })
     
-    master_dj_input.find("#reset").click(function(){
+    master_dj_input.find("#reset").click(function(event){
         var port = $("#master_harbor_input_port").val()
         var mount = $("#master_harbor_input_mount_point").val()
         var url = "http://"+location.hostname+":"+port+"/"+mount
         master_dj_label.html(url)
         master_dj_input.hide()
         $.get("/Preference/set-source-connection-url", {format: "json", type: "masterdj", url:encodeURIComponent(url)})
+        event.preventDefault()
     })
 }