Пример #1
0
 public function deleteAction()
 {
     $id = $this->request->getPost("id");
     $widget = Widget::findfirst('id =' . $id);
     if (!$widget->delete()) {
         foreach ($widget->getMessages() as $message) {
             $this->flash->error($message);
         }
     } else {
         $this->flash->success("widget was deleted successfully");
     }
     $portlet = Portlet::findFirstById($widget->portlet_id);
     $dashboard = Dashboard::findFirstById($portlet->dashboard_id);
     return $this->response->redirect("/dashboards/" . $dashboard->type . "/edit/" . $dashboard->id);
 }
 public function deleteWidgetAction()
 {
     $id = $this->request->getPost("id");
     $widget = Widget::findfirst('id =' . $id);
     if (!$widget->delete()) {
         foreach ($widget->getMessages() as $message) {
             $this->flash->error($message);
         }
     } else {
         $this->flash->success("widget was deleted successfully");
     }
     return $this->dispatcher->forward(array("controller" => "dashboard", "action" => "edit", "params" => array('id' => $widget->dashboard_id)));
 }
Пример #3
0
    public function renderAction($id, $type)
    {
        if ($this->session->has("auth")) {
            //Retrieve its value
            $auth = $this->session->get("auth");
            $this->view->setViewsDir('../app/themes/' . $auth['theme'] . '/portlets/');
        }
        $portlet = Portlet::findFirstByid($id);
        $dashboard = Dashboard::findFirstByid($portlet->dashboard_id);
        $dashparm = json_decode($dashboard->parameters, true);
        $this->view->pick(strtolower($portlet->type . "/view"));
        $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
        $parameters = (array) json_decode($portlet->parameters, true);
        $this->view->setVar("parm", $parameters);
        $this->view->setVar("portlet", $portlet);
        $region = array();
        $widgets = Widget::find(array('portlet_id =' . $portlet->id, "order" => "column"));
        for ($i = 0; $i < 10; $i++) {
            $region[$i] = '<div id="portlet_' . $id . '_row_' . $i . '" data-portlet-id="' . $id . '" data-row="' . $i . '" class="dropzone-portlet grid-stack grid-stack-12">';
            $region[$i] .= '

                          </div>';
            echo '
  <script type="text/javascript">
        $(function () {
            var options = {
                float: false,
                cellHeight: 40,
                verticalMargin: 5
            };
            $("#portlet_' . $id . '_row_' . $i . '").gridstack(options);

            $("#portlet_' . $id . '_row_' . $i . '").each(function () {
                var grid = $(this).data("gridstack");


                
';
            foreach ($widgets as $widget) {
                if ($widget->row == $i) {
                    $x = 1;
                    $y = 1;
                    $height = 4;
                    $width = 6;
                    if (array_key_exists("layout", $dashparm)) {
                        foreach ($dashparm["layout"] as $layout) {
                            if ($layout["thisId"] == $widget->id && $layout["regionId"] == $i && $layout["thisType"] == "widget" && $layout["parentId"] == $id) {
                                $x = $layout["x"];
                                $y = $layout["y"];
                                $height = $layout["h"];
                                $width = $layout["w"];
                                continue;
                            }
                        }
                    }
                    echo 'var el = grid.add_widget($("<div><div class=\'grid-stack-item-content builder-widget\' data-type=\\"' . $widget->type . '\\" data-id=\\"' . $widget->id . '\\" ><div id=\'widget_temp_' . $widget->id . '\'></div></div></div>"),
                        ' . $x . ', ' . $y . ', ' . $width . ', ' . $height . ');
                    el.attr(\'data-this-id\', "' . $widget->id . '");
                    el.attr(\'data-parent-id\', "' . $id . '");
                    el.attr(\'data-region-id\', "' . $i . '");
                    el.attr(\'data-this-type\', "widget");
                 ';
                }
            }
            if ($type != "builder") {
                echo '

                    grid.movable(\'.grid-stack-item\', false);
                    grid.resizable(\'.grid-stack-item\', false);
                    ';
            }
            echo '
}, this);


            });



    </script> ';
        }
        $this->view->setVar("region", $region);
        foreach ($widgets as $widget) {
            echo '<script> 
            $.post("/widgets/' . $widget->type . '/render/' . $widget->id . '/' . $type . '", function(data) {';
            if ($type == "builder") {
                echo ' $("#widget_temp_' . $widget->id . '").replaceWith(data);';
                echo 'parent.update_dropzone(); 
                        parent.iframe_load();';
            } else {
                echo '
                $("#widget_temp_' . $widget->id . '").replaceWith(data);';
            }
            echo "}); </script>";
        }
    }