andre пре 4 година
родитељ
комит
3bb04fe065
1 измењених фајлова са 65 додато и 20 уклоњено
  1. 65 20
      app/UI/Vms/Buttons/ConsoleButton.php

+ 65 - 20
app/UI/Vms/Buttons/ConsoleButton.php

@@ -36,31 +36,76 @@ class ConsoleButton extends ButtonDataTableModalAction implements ClientArea
     {
         $this->initIds('consoleButton');
         $this->setDisableByColumnValue("vmid", 0);
+        $url ="clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=console&mg-action=novnc";
+//        $url ="clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=vm";
+        $this->setRawUrl($url)
+            ->setRedirectParams(['vm' => ':id']);
     }
 
     public function afterInitContent()
     {
-        $query = VmModel::select("id")
-        ->ofHostingId($this->getWhmcsParamByKey('serviceid'))
-        ->notTemplate()
-        ->getQuery();
-        $dataProv = new QueryDataProvider();
-        $dataProv->setData($query);
-        $vmid = $dataProv->getData()->getRecords()->first()->id;
-        $consoleUrl = isAdmin() ? BuildUrl::getUrl('console', 'novnc', ['vm'=> $vmid]) : 'clientarea.php?action=productdetails&id=' . $this->getWhmcsParamByKey('serviceid') . '&vm=' . $vmid . '&modop=custom&a=management&mg-page=console&mg-action=novnc';
-        $this->setConsoleUrl($consoleUrl);
-        logModuleCall(
-            'proxmoxCloud',
-            __FUNCTION__,
-            $this->actionButtons,
-            'Debug',
-            $dataProv->getData()->getRecords()
-        );
-}
-
-    public function setConsoleUrl($url)
+        $this->htmlAttributes['@click.middle'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
+        $this->htmlAttributes['@click'] = 'redirect($event, ' . $this->parseCustomParams() . ')';
+    }
+
+    public function setRawUrl($url)
+    {
+        $this->rawUrl = $url;
+
+        return $this;
+    }
+
+    protected function parseCustomParams()
+    {
+        if (count($this->redirectParams) === 0 && $this->rawUrl === null)
+        {
+            return '{}';
+        }
+
+        return $this->parseListTOJsString($this->redirectParams);
+    }
+
+    protected function parseListTOJsString($params)
+    {
+        $jsString = '{';
+
+        if ($this->rawUrl !== null)
+        {
+            $params['rawUrl'] = $this->rawUrl;
+        }
+
+        foreach ($params as $key => $value)
+        {
+            $jsString .= ' ' . str_replace('-', '__', $key) . ': ' . (is_array($value) ? ($this->parseListTOJsString($value) . ',') : ("'" . (string) $value) . "',");
+        }
+
+        $jsString = trim($jsString, ',') . ' } ';
+
+        return $jsString;
+    }
+
+    public function setRedirectParams($paramsList)
     {
-        $this->addHtmlAttribute('onclick', "window.open('{$url}', '', 'width=900,height=700'); return false;");
+        $this->redirectParams = $paramsList;
+
+        $this->updateHtmlAttributesByRedirectParams();
+
         return $this;
     }
+
+    protected function updateHtmlAttributesByRedirectParams()
+    {
+        foreach ($this->redirectParams as $key => $value)
+        {
+            $this->updateHtmlAttribute($key, $value);
+        }
+    }
+
+    protected function updateHtmlAttribute($key, $value)
+    {
+        if (strpos($value, ':') === 0)
+        {
+            $this->addHtmlAttribute(':data-' . $key , 'dataRow.' . trim($value, ':'));
+        }
+    }
 }