/** * @Clips\Widgets\DataTable("admin_resource") * @Clips\Actions("admin/resource") */ public function index() { $data = $this->resource->getResourceTypes(); \Clips\add_init_js(<<<T_EXTENDS function datatable_render_resource_name(data, type, full, meta) { \tvar json = JSON.parse(data); \tconsole.info(json); \tvar ul = []; \tvar i = 0; \tfor(i = 0; i < json.length; i++) { \t\tul.push('<br />'+'<li style="list-style-type:none"><img src="'+Clips.staticUrl('application/static/img/' + json[i]['path'])+'" width=100 height=100></li>'); \t\tul.push(); \t} \treturn "<ul>" + ul.join("") + "</ul>"; } function datatable_render_resource_type(data, type, full, meta) { \t\tconsole.info(data); \t\tif(data==1) \t\t\treturn "<h1>资料下载</h1>"; } T_EXTENDS ); if ($this->permission()) { $a = new SimpleAction(array('children' => $this->data->navi)); return $this->render('admin/resource/index', array('actions' => $a->children())); } else { return $this->render('admin/error'); } }
protected function doInit() { // Added the clips object to JavaScript $router = \Clips\context('router'); if ($router) { \Clips\add_init_js(\Clips\clips_out('clips_js', array('base' => $router->staticUrl('/'), 'site' => $router->baseUrl('/')), false)); } }
public function filter_after($chain, $controller, $method, $args, $request, $controller_ret) { $init = \Clips\clips_context('jquery_init'); if ($init) { if (!is_array($init)) { $init = array($init); } $init[] = "if(typeof initialize === 'function') initialize();"; \Clips\add_init_js('jQuery(function($){' . implode("\n", $init) . '});'); } }
/** * @Clips\Form("admin/coupon_record") * @Clips\Widget({"grid", "bootstrap", "image","datatable","form", "datepicker", "yizhifushim"}) * @Clips\Widgets\DataTable("admin_coupon_record") * @Clips\Scss("admin/user/coupon_record") * @Clips\Js("application/static/js/user/coupon_record.js") * @Clips\Model("product") */ public function coupon_record() { $this->title('Checked Coupon Record Page', true); \Clips\add_init_js(<<<ACTION_JS function admin_coupon_record_datatable_action(data, type, row, col, meta){ var action_url = Clips.siteUrl(col.action) +row[col.refer]; var start_time = \$("#field_start_time").val(); var end_time = \$("#field_end_time").val(); if(start_time) action_url += "&start_time="+start_time; if(end_time) action_url += "&end_time="+end_time; return "<a href='"+ action_url +"'>"+ data +"</a>" } ACTION_JS ); //TODO $uid = $this->request->session('user_id'); $p = array('merchants.uid' => $uid); if ($this->post('group_purchase')) { $p['products.id'] = $this->post('group_purchase'); } if ($this->post('start_time')) { $p[] = new \Clips\Libraries\CommonOperator('user_coupons.timestamp', $this->post('start_time'), '>='); } if ($this->post('end_time')) { $p[] = new \Clips\Libraries\CommonOperator('user_coupons.timestamp', $this->post('end_time'), '<='); } $this->formData("admin/coupon_record", (object) $this->post()); $this->request->session('admin_coupon_record', $p); $products = $this->product->getProductsByUID($uid); $please_select = $this->bundle->message('-- All --'); return $this->render('admin/user/coupon_record', array('products' => $products, 'prepend' => array($please_select => ''))); }
function smarty_function_js($params, $template) { $tool = \Clips\get_clips_tool(); //Processing jquery init $init = \Clips\clips_context('jquery_init'); if ($init) { if (!is_array($init)) { $init = array($init); } $init[] = "if(typeof initialize === 'function') initialize();"; \Clips\add_init_js("//====================================\n// The jQuery initialize function \n//====================================\n\n" . 'jQuery(function($){' . "\n\t" . implode("\n\t", $init) . "\n" . '});'); } // Processing js $scripts = \Clips\context('js'); if ($scripts) { if (!is_array($scripts)) { $scripts = array($scripts); } $output = array(); $init = array(); foreach ($scripts as $item) { if (is_array($item)) { $js = explode("\n", $item['script']); $ret = array(); foreach ($js as $line) { $ret[] = "\t" . $line; } $init[] = implode("\n\t\t", $ret); } else { if (is_object($item)) { $js = explode("\n", $item->script); $ret = array(); foreach ($js as $line) { $ret[] = "\t" . trim($line); } $init[] = implode("\n\t\t", $ret); } else { $path = \Clips\safe_add_extension($item, 'js'); if (strpos($path, 'http:') === false) { $path = \Clips\static_url($path); } $output[] = '<script type="text/javascript" src="' . $path . '"></script>'; } } } $output[] = '<script type="text/javascript">' . "\n\t\t" . implode("\n\t\t", $init) . "\n\t\t" . '</script>'; // Added the jsx support for ReactJs $jsx = \Clips\context('jsx'); if ($jsx) { if (\Clips\config('babel')) { // TODO: This is a little bit ugly, needs refactor.... $babel = $tool->library('babel'); foreach ($jsx as $item) { $path = Clips\try_path(Clips\safe_add_extension($item, 'jsx')); if ($path) { $output[] = '<script type="text/javascript" src="' . Clips\static_url($babel->compile($path)) . '"></script>'; } } } else { foreach ($jsx as $item) { $output[] = '<script type="text/babel" src="' . Clips\static_url(Clips\safe_add_extension($item, 'jsx')) . '"></script>'; } } } $jsx = \Clips\context('jsx_script'); if ($jsx) { if (\Clips\config('babel')) { $babel = $tool->library('babel'); $cache = $tool->library('fileCache'); $c = \Clips\context('controller'); $cm = \Clips\context('controller_method'); $name = $c . '_' . $cm . '.jsx'; $cache_file = $cache->cacheDir() . '/js/cache/' . $c . '_' . $cm . '.js'; if (\Clips\try_path($cache_file) && !\Clips\config('debug_jsx')) { $output[] = '<script type="text/javascript" src="' . Clips\static_url($cache_file) . '"></script>'; } else { $cache->save($name, $jsx, \Clips\path_join($cache->cacheDir(), 'js')); $output[] = '<script type="text/javascript" src="' . Clips\static_url($babel->compile($cache->cacheDir() . '/js/' . $name)) . '"></script>'; } } else { $output[] = '<script type="text/babel">' . implode("\n\t\t", $jsx) . '</script>'; } } return implode("\n\t\t", $output); } else { return ''; } }