Пример #1
0
    public function render()
    {
        $key = \Frame\Key::get();
        $user_id = \Work\Models\User::where('session', '=', $_SESSION['frame_key'])->pluck('user_id');
        if (is_null($user_id)) {
            $user_id = 0;
        }
        $target_id = \Work\Models\Target::where('target', '=', $this->target)->pluck('target_id');
        $id = \Work\Models\Navigation::where('user_id', '=', $user_id)->where('type', '=', 'target')->where('navigation', '=', $target_id)->orderBy('navigation_id', 'desc')->pluck('key');
        $attributes = array('type' => 'button', 'id' => $key, 'value' => $this->text);
        $controller_id = \Work\Models\Controller::where('controller', '=', $this->controller)->pluck('controller_id');
        \Work\Models\Navigation::create(array('user_id' => $user_id, 'key' => $key, 'type' => 'controller', 'navigation' => $controller_id));
        $button = $this->build('input', '', $attributes);
        $js = <<<JS
\$('#{$key}').bind('click', function(event) {
    event.preventDefault();
    var ids = [];
    \$('body [id]').each(function() {
        ids.push(\$(this).attr('id'));
    });
    \$.ajax({url: '', type: 'post', dataType: 'json', data: {key: '{$key}', clean: ids, target: '{$id}'}}).success(function(json) {
        if (!json.status || !json.html || json.status != 'COMPLETE') {
            var message = json.message || 'System error, check logs';
            alert(message);
            return false;
        }
        \$('#{$id}').html(json.html);
    });
});
JS;
        $script = $this->build('script', $js);
        //$script = $this->build('script', '$("#'.$key.'").unbind("click").bind("click", function() {$("#'.$id.'").load("?key='.$key.'");})');
        return $button . $script;
    }
Пример #2
0
 public function __construct($rows)
 {
     foreach ($rows as $row) {
         $line = array();
         foreach ($row as $target => $detail) {
             if (is_numeric($target)) {
                 $attributes = array();
                 $targ = null;
             } else {
                 $user_id = \Work\Models\User::where('session', '=', $_SESSION['frame_key'])->pluck('user_id');
                 if (is_null($user_id)) {
                     $user_id = 0;
                 }
                 $target_id = \Work\Models\Target::where('target', '=', $target)->pluck('target_id');
                 $key = \Work\Models\Navigation::where('user_id', '=', $user_id)->where('type', '=', 'target')->where('navigation', '=', $target_id)->pluck('key');
                 if (is_null($key)) {
                     $key = \Frame\Key::get();
                     \Work\Models\Navigation::create(array('user_id' => $user_id, 'key' => $key, 'type' => 'target', 'navigation' => $target_id));
                 }
                 $attributes = array('id' => $key);
                 $targ = $target;
             }
             $line[] = array('target' => $targ, 'detail' => $detail, 'attributes' => $attributes);
         }
         $this->rows[] = $line;
     }
 }
Пример #3
0
    public function render()
    {
        $columns = array();
        $user_id = \Work\Models\User::where('session', '=', $_SESSION['frame_key'])->pluck('user_id');
        if (is_null($user_id)) {
            $user_id = 0;
        }
        foreach ($this->inputs as $input) {
            $id = \Frame\Key::get();
            if ($input['type'] == 'hidden') {
                if ($user_id) {
                    $store = \Work\Models\Store::where('user_id', '=', $user_id)->where('key', '=', $input['value'])->pluck('store_id');
                } else {
                    $store = \Work\Models\Store::where('key', '=', $input['value'])->pluck('store_id');
                }
                if (is_null($store)) {
                    $hidden = \Frame\Key::get();
                    \Work\Models\Store::create(array('user_id' => $user_id, 'key' => $hidden, 'value' => $input['value']));
                    $input['value'] = $hidden;
                }
            }
            $columns[] = array($input['label'], $this->build('input', '', array('id' => $id, 'name' => $id, 'type' => $input['type'], 'value' => $input['value'])));
            if (is_null($input['input'])) {
                continue;
            }
            $input_id = \Work\Models\Input::where('input', '=', $input['input'])->pluck('input_id');
            \Work\Models\Navigation::create(array('user_id' => $user_id, 'key' => $id, 'type' => 'input', 'navigation' => $input_id));
        }
        $layout = new \Frame\Views\Layout($columns);
        $key = \Frame\Key::get();
        $target_id = \Work\Models\Target::where('target', '=', $this->target)->pluck('target_id');
        if ($target_id) {
            $target = \Work\Models\Navigation::where('user_id', '=', $user_id)->where('type', '=', 'target')->where('navigation', '=', $target_id)->orderBy('navigation_id', 'desc')->pluck('key');
        } else {
            $navigation_id = \Work\Models\Navigation::where('type', '=', 'target')->where('key', '=', $this->target)->pluck('navigation_id');
            if ($navigation_id) {
                $target = $this->target;
            } else {
                $target = null;
            }
        }
        if (is_null($target)) {
            $id = $target = 'body';
        } else {
            $id = "#{$target}";
        }
        $form = $this->build('form', $layout->render(), array('id' => $key));
        $js = <<<JS
\$('#{$key}').submit(function(event) {
    event.preventDefault();
    var hidden = [];
    \$('{$id} [id]').each(function() {
        hidden.push(\$(this).attr('id'));
    });
    console.log(hidden);
    var ids = [];
    \$('body [id]').each(function() {
        if (\$.inArray(\$(this).attr('id'), hidden) >= 0) return true;
        ids.push(\$(this).attr('id'));
    });
    console.log(ids);
    \$.ajax({url: '', type: 'post', dataType: 'json', data: {key: '{$key}', form: \$(this).serializeArray(), target: '{$target}', clean: ids}}).success(function(json) {
        if (!json.status || json.status != 'COMPLETE' || !json.html) {
            var message = json.message || 'System error, check logs';
            alert(message);
            return false;
        }
        \$('{$id}').html(json.html);
    });
});
JS;
        $controller_id = \Work\Models\Controller::where('controller', '=', $this->controller)->pluck('controller_id');
        if (is_null($controller_id)) {
            throw new \Exception("{$this->controller} not found in controller table}");
        }
        \Work\Models\Navigation::create(array('user_id' => $user_id, 'key' => $key, 'type' => 'controller', 'navigation' => $controller_id));
        $script = $this->build('script', $js);
        return $form . $script;
    }