public function init() { if(Y::isGuest()) $this->redirect(Admin::url('login')); if(!Y::checkAccess('moderator')) Y::end($this->render('accessDenied')); parent::init(); $folder = Y::asset('admin.assets'); Y::clientScript() ->registerCoreScript('jquery') ->registerCoreScript('jquery.ui'); Y::clientScript()->ajaxExclude(array( 'jquery.js', 'jquery-ui.min.js', 'jquery-ui.css', //treeview 'jquery.treeview.js', 'jquery.cookie.js', 'jquery.treeview.edit.js', 'jquery.treeview.async.js', )); }
public function actionUpdate($dir, $fileName) { if (isset($_POST['fileContent'])) { FileSystem::write('./'.$dir.'/'.$fileName, $_POST['fileContent'], 'w'); Y::end(); } $content = ''; $info = FileSystem::getInfo('./'.$dir.'/'.$fileName, array('name', 'ext')); if (in_array($info['ext'], array('js', 'css'))) { if (substr($dir, 0, 2) == 'js' || substr($dir, 0, 3) == 'css') { $content = FileSystem::read('./'.$dir.'/'.$fileName); } } $output = $this->renderPartial('fileDetails', array( 'fileName' => $fileName, 'content' => $content, 'type' => $info['ext'] == 'css' ? 'css' : 'javascript', 'filePath' => './'.$dir.'/'.$fileName ), true); Y::tab('Содержимое файла', $output); $output = Y::getTabs('cssFileForm', true); Y::clientScript()->render($output); echo CHtml::tag('div', array(), $output); }
public function init() { parent::init(); $this->setImport(array( 'admin.models.*', 'admin.components.*', )); Y::clientScript()->registerScriptFile($this->scriptPath.'/js/cms/asc.js'); }
public function registerScritps() { $options = empty($this->options) ? '' : CJavaScript::encode($this->options); Y::clientScript() ->registerScript($this->getId().'-form-submit', " $(document).ready(function(){ $('#{$this->getId()}').tabs({$options}); }); ") ->registerScriptFile(''); }
public function ajaxExclude($names) { if (Y::isAjaxRequest()) { $files = array(); foreach ((array)$names as $name) $files[$name] = false; Y::clientScript()->scriptMap = CMap::mergeArray( Y::clientScript()->scriptMap, $files ); } }
public function init() { Y::clientScript()-> registerCoreScript('jquery')-> registerCssFile(Yii::app()->baseUrl.'/css/style.css'); if (Yii::app()->request->isAjaxRequest) { Y::clientScript()->scriptMap = array( 'jquery.js' => false, 'style.css' => false, ); } parent::init(); }
public function init() { Y::clientScript()->registerScriptFile('/js/plugins/jquery.form.js'); $options = CJavaScript::encode($this->options); Y::clientScript()->registerScript('save-button', " $(document).ready(function() { //form submit $('#$this->id').closest('form').bind('submit', function(e) { e.preventDefault(); // <-- important $(this).ajaxSubmit($options); }); }); "); parent::init(); }
public function run() { $id=$this->getId(); if (isset($this->htmlOptions['id'])) $id = $this->htmlOptions['id']; else $this->htmlOptions['id']=$id; echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n"; $tabsOut = ""; $contentOut = ""; $tabCount = 0; foreach($this->tabs as $title=>$content) { $tabId = (is_array($content) && isset($content['id']))?$content['id']:$id.'_tab_'.$tabCount++; if (!is_array($content)) { $tabsOut .= strtr($this->headerTemplate, array('{title}'=>$title, '{url}'=>'#'.$tabId, '{id}'=>'#' . $tabId))."\n"; $contentOut .= strtr($this->contentTemplate, array('{content}'=>$content,'{id}'=>$tabId))."\n"; } elseif (isset($content['ajax'])) { $tabsOut .= strtr($this->headerTemplate, array('{title}'=>$title, '{url}'=>CHtml::normalizeUrl($content['ajax']), '{id}'=>'#' . $tabId))."\n"; } else { $tabsOut .= strtr($this->headerTemplate, array('{title}'=>$title, '{url}'=>'#'.$tabId))."\n"; if(isset($content['content'])) $contentOut .= strtr($this->contentTemplate, array('{content}'=>$content['content'],'{id}'=>$tabId))."\n"; } } echo "<ul>\n" . $tabsOut . "</ul>\n"; echo $contentOut; echo CHtml::closeTag($this->tagName)."\n"; $options=empty($this->options) ? '' : CJavaScript::encode($this->options); Y::clientScript()->registerScript($id.'-form-submit', " $(document).ready(function(){ $('#{$id}').tabs({$options}); }); "); }
public function registerScripts() { $id = $this->grid->id; $url = Y::curUrl(); $js =<<< EOM $('#$id').delegate('.checkbox-column input', 'change', function() { $.get( '$url', { model_id:$(this).val(), published:true, val:$(this).is(':checked') } ); }); EOM; Y::clientScript()->registerScript(__CLASS__.'#'.$this->id, $js); }
public function registerScripts() { $id = $this->grid->id; $class = $this->htmlOptions["class"]; $url = Y::curUrl(); $js =<<< EOM $('#$id').delegate('.$class div', 'click', function() { $(this).toggleClass('yes'); $.get( '$url', { model_id : parseInt($(this).attr('id').replace(/published-button-/ig, "")), published : true, val : $(this).attr('class') == "yes" ? true : false } ); return false; }); EOM; Y::clientScript()->registerScript(__CLASS__.'#'.$this->id, $js); }
public function run() { if (!in_array($this->type, array('text/html', 'css', 'javascript', 'xml'))) { throw new CException("type принемает значения: 'text/html', 'css', 'javascript', 'xml'"); } if ($this->content === null) { if (!($this->id && $this->form && $this->model && $this->attr)) throw new CException("Обязательные поля для CodeMirror: id, form, model, attr"); } $folder = Y::asset('admin.assets'); Y::clientScript() ->registerScriptFile($folder.'/js/CodeMirror/lib/codemirror.js') ->registerCssFile($folder.'/js/CodeMirror/lib/codemirror.css') ->registerCssFile($folder.'/js/CodeMirror/theme/default.css') ->registerScriptFile($folder.'/js/CodeMirror/mode/javascript/javascript.js') ->registerCssFile($folder.'/js/CodeMirror/mode/javascript/javascript.css') ->registerScriptFile($folder.'/js/CodeMirror/mode/css/css.js') ->registerCssFile($folder.'/js/CodeMirror/mode/css/css.css') ->registerScriptFile($folder.'/js/CodeMirror/mode/xml/xml.js') ->registerCssFile($folder.'/js/CodeMirror/mode/xml/xml.css') ->registerScriptFile($folder.'/js/CodeMirror/mode/htmlmixed/htmlmixed.js') ->registerScriptFile($folder.'/js/CodeMirror/lib/overlay.js') ->registerScript('autocomplete_'.$this->id, ' $(document).ready(function() { // autocomplite function stopEvent() { if (this.preventDefault) {this.preventDefault(); this.stopPropagation();} else {this.returnValue = false; this.cancelBubble = true;} } function addStop(event) { if (!event.stop) event.stop = stopEvent; return event; } function connect(node, type, handler) { function wrapHandler(event) {handler(addStop(event || window.event));} if (typeof node.addEventListener == "function") node.addEventListener(type, wrapHandler, false); else node.attachEvent("on" + type, wrapHandler); } function forEach(arr, f) { for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]); } var startComplete = function () { // We want a single cursor position. if ('.$this->id.'_CM_editor.somethingSelected()) return; // Find the token at the cursor var cur = '.$this->id.'_CM_editor.getCursor(false), token = '.$this->id.'_CM_editor.getTokenAt(cur), tprop = token; if (!/^[\w$_]*$/.test(token.string)) { token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state, className: token.string == "." ? "js-property" : null}; } // If it is a property, find out what it is a property of. while (tprop.className == "js-property") { tprop = '.$this->id.'_CM_editor.getTokenAt({line: cur.line, ch: tprop.start}); if (tprop.string != ".") return; tprop = '.$this->id.'_CM_editor.getTokenAt({line: cur.line, ch: tprop.start}); if (!context) var context = []; context.push(tprop); } var completions = getCompletions(token, context); if (!completions.length) return; function insert(str) { '.$this->id.'_CM_editor.replaceRange(str, {line: cur.line, ch: token.start}, {line: cur.line, ch: token.end}); } // When there is only one completion, use it directly. if (completions.length == 2) {insert(completions[0]); return true;} // Build the select widget var complete = document.createElement("div"); complete.className = "completions"; var sel = complete.appendChild(document.createElement("select")); sel.multiple = true; for (var i = 0; i < completions.length; ++i) { var opt = sel.appendChild(document.createElement("option")); opt.appendChild(document.createTextNode(completions[i])); } sel.firstChild.selected = true; sel.size = Math.min(10, completions.length); var pos = '.$this->id.'_CM_editor.cursorCoords(); complete.style.left = pos.x + "px"; complete.style.top = pos.yBot + "px"; document.body.appendChild(complete); // Hack to hide the scrollbar. if (completions.length <= 10) complete.style.width = (sel.clientWidth - 2) + "px"; var done = false; function close() { if (done) return; done = true; complete.parentNode.removeChild(complete); } function pick() { insert(sel.options[sel.selectedIndex].value); close(); setTimeout(function(){'.$this->id.'_CM_editor.focus();}, 50); } connect(sel, "blur", close); connect(sel, "keydown", function(event) { var code = event.keyCode; // Enter and space if (code == 13 || code == 32) {event.stop(); pick();} // Escape else if (code == 27) {event.stop(); close(); '.$this->id.'_CM_editor.focus();} else if (code != 38 && code != 40) {close(); '.$this->id.'_CM_editor.focus(); setTimeout(startComplete, 50);} }); connect(sel, "dblclick", pick); sel.focus(); // Opera sometimes ignores focusing a freshly created node if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100); return true; } var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " + "toUpperCase toLowerCase split concat match replace search").split(" "); var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " + "lastIndexOf every some filter forEach map reduce reduceRight ").split(" "); var funcProps = "prototype apply call bind".split(" "); var keywords = ("break case catch continue debugger default delete do else false finally for function " + "if in instanceof new null return switch throw true try typeof var void while with").split(" "); function getCompletions(token, context) { var found = [], start = token.string; function maybeAdd(str) { if (str.indexOf(start) == 0) found.push(str); } function gatherCompletions(obj) { if (typeof obj == "string") forEach(stringProps, maybeAdd); else if (obj instanceof Array) forEach(arrayProps, maybeAdd); else if (obj instanceof Function) forEach(funcProps, maybeAdd); for (var name in obj) maybeAdd(name); } if (context) { // If this is a property, see if it belongs to some object we can // find in the current environment. var obj = context.pop(), base; if (obj.className == "js-variable") base = window[obj.string]; else if (obj.className == "js-string") base = ""; else if (obj.className == "js-atom") base = 2; while (base != null && context.length) base = base[context.pop().string]; if (base != null) gatherCompletions(base); } else { // If not, just look in the window object and any local scope // (reading into JS mode internals to get at the local variables) for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name); gatherCompletions(window); forEach(keywords, maybeAdd); } return found; } var myTextArea = document.getElementById("'.$this->id.'"); '.$this->id.'_CM_editor = CodeMirror.fromTextArea(myTextArea,{ mode: "'.$this->type.'", lineNumbers: true, tabMode: "indent", undoDepth: 500, onKeyEvent: function(i, e) { // Hook into ctrl-space if (e.keyCode == 32 && (e.ctrlKey || e.metaKey) && !e.altKey) { e.stop(); return startComplete(); } } }); });'); if ($this->content !== null) echo CHtml::textArea($this->name, $this->content, array('id'=>$this->id)); else echo $this->form->textArea($this->model,$this->attr,array('id'=>$this->id)); }
/** * Register Script */ public function registerScript() { $basePath=Yii::getPathOfAlias('application.modules.users.views.asset'); $baseUrl=Yii::app()->getAssetManager()->publish($basePath); $cs = Y::clientScript()->registerCoreScript('jquery') ->registerCssFile($baseUrl.'/css/redmond/jquery-ui.css') ->registerCssFile($baseUrl.'/css/style.css') ->registerScriptFile($baseUrl.'/js/jquery-ui.min.js') ->registerScriptFile($baseUrl.'/js/form.js') ->registerScriptFile($baseUrl.'/js/jquery.json.js'); $widgets = self::getWidgets(); $wgByTypes = ProfileField::itemAlias('field_type'); foreach ($wgByTypes as $k=>$v) { $wgByTypes[$k] = array(); } foreach ($widgets[1] as $widget) { if (isset($widget['fieldType'])&&count($widget['fieldType'])) { foreach($widget['fieldType'] as $type) { array_push($wgByTypes[$type],$widget['name']); } } } //echo '<pre>'; print_r($components[2]); die(); $js = " var name = $('#name'), value = $('#value'), allFields = $([]).add(name).add(value), tips = $('.validateTips'); var listWidgets = jQuery.parseJSON('".str_replace("'","\'",CJavaScript::jsonEncode($widgets[0]))."'); var components = jQuery.parseJSON('".str_replace("'","\'",CJavaScript::jsonEncode($widgets[1]))."'); var wgByType = jQuery.parseJSON('".str_replace("'","\'",CJavaScript::jsonEncode($wgByTypes))."'); var fieldType = { 'INTEGER':{ 'hide':['match','other_validator','widgetparams'], 'val':{ 'field_size':10, 'default':'0', 'range':'', 'widgetparams':'' } }, 'VARCHAR':{ 'hide':['widgetparams'], 'val':{ 'field_size':255, 'default':'', 'range':'', 'widgetparams':'' } }, 'TEXT':{ 'hide':['field_size','range','widgetparams'], 'val':{ 'field_size':0, 'default':'', 'range':'', 'widgetparams':'' } }, 'DATE':{ 'hide':['field_size','field_size_min','match','range','widgetparams'], 'val':{ 'field_size':0, 'default':'0000-00-00', 'range':'', 'widgetparams':'' } }, 'FLOAT':{ 'hide':['match','other_validator','widgetparams'], 'val':{ 'field_size':'10,2', 'default':'0.00', 'range':'', 'widgetparams':'' } }, 'BOOL':{ 'hide':['field_size','field_size_min','match','widgetparams'], 'val':{ 'field_size':0, 'default':0, 'range':'2==".Users::t('Yes').";0==".Users::t('No')."', 'widgetparams':'' } }, 'BLOB':{ 'hide':['field_size','field_size_min','match','widgetparams'], 'val':{ 'field_size':0, 'default':'', 'range':'', 'widgetparams':'' } }, 'BINARY':{ 'hide':['field_size','field_size_min','match','widgetparams'], 'val':{ 'field_size':0, 'default':'', 'range':'', 'widgetparams':'' } } }; function showWidgetList(type) { $('div.widget select').empty(); $('div.widget select').append('<option value=\"\">".Users::t('No')."</option>'); if (wgByType[type]) { for (var k in wgByType[type]) { $('div.widget select').append('<option value=\"'+wgByType[type][k]+'\">'+components[wgByType[type][k]]['label']+'</option>'); } } } function setFields(type) { if (fieldType[type]) { if (".((isset($_GET['id']))?0:1).") { showWidgetList(type); $('#widgetlist option:first').attr('selected', 'selected'); } $('div.row').addClass('toshow').removeClass('tohide'); if (fieldType[type].hide.length) $('div.'+fieldType[type].hide.join(', div.')).addClass('tohide').removeClass('toshow'); if ($('div.widget select').val()) { $('div.widgetparams').removeClass('tohide'); } $('div.toshow').show(500); $('div.tohide').hide(500); ".((!isset($_GET['id']))?" for (var k in fieldType[type].val) { $('div.'+k+' input').val(fieldType[type].val[k]); }":'')." } } function isArray(obj) { if (obj.constructor.toString().indexOf('Array') == -2) return false; else return true; } $('#dialog-form').dialog({ autoOpen: false, height: 400, width: 400, modal: true, buttons: { '".Users::t('Save')."': function() { var wparam = {}; var fparam = {}; $('#dialog-form fieldset .wparam').each(function(){ if ($(this).val()) wparam[$(this).attr('name')] = $(this).val(); }); var tab = $('#tabs ul li.ui-tabs-selected').text(); fparam[tab] = {}; $('#dialog-form fieldset .tab-'+tab).each(function(){ if ($(this).val()) fparam[tab][$(this).attr('name')] = $(this).val(); }); if ($.JSON.encode(wparam)!='{}') $('div.widgetparams input').val($.JSON.encode(wparam)); if ($.JSON.encode(fparam[tab])!='{}') $('div.other_validator input').val($.JSON.encode(fparam)); $(this).dialog('close'); }, '".Users::t('Cancel')."': function() { $(this).dialog('close'); } }, close: function() { } }); $('#widgetparams').focus(function() { var widget = components[$('#widgetlist').val()]; var html = ''; var wparam = ($('div.widgetparams input').val())?$.JSON.decode($('div.widgetparams input').val()):{}; var fparam = ($('div.other_validator input').val())?$.JSON.decode($('div.other_validator input').val()):{}; // Class params for (var k in widget.params) { html += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>'; html += '<input type=\"text\" name=\"'+k+'\" id=\"widget_'+k+'\" class=\"text wparam ui-widget-content ui-corner-all\" value=\"'+((wparam[k])?wparam[k]:widget.params[k])+'\" />'; } // Validator params if (widget.other_validator) { var tabs = ''; var li = ''; for (var t in widget.other_validator) { tabs += '<div id=\"tab-'+t+'\" class=\"tab\">'; li += '<li'+((fparam[t])?' class=\"ui-tabs-selected\"':'')+'><a href=\"#tab-'+t+'\">'+t+'</a></li>'; for (var k in widget.other_validator[t]) { tabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>'; if (isArray(widget.other_validator[t][k])) { tabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">'; for (var i in widget.other_validator[t][k]) { tabs += '<option value=\"'+widget.other_validator[t][k][i]+'\"'+((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+widget.other_validator[t][k][i]+'</option>'; } tabs += '</select>'; } else { tabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+((fparam[t]&&fparam[t][k])?fparam[t][k]:widget.other_validator[t][k])+'\" />'; } } tabs += '</div>'; } html += '<div id=\"tabs\"><ul>'+li+'</ul>'+tabs+'</div>'; } $('#dialog-form fieldset').html(html); $('#tabs').tabs(); // Show form $('#dialog-form').dialog('open'); }); $('#field_type').change(function() { setFields($(this).val()); }); $('#widgetlist').change(function() { if ($(this).val()) { $('div.widgetparams').show(500); } else { $('div.widgetparams').hide(500); } }); // show all function $('div.form p.note').append('<br/><a href=\"#\" id=\"showAll\">".Users::t('Show all')."</a>'); $('#showAll').click(function(){ $('div.row').show(500); return false; }); // init setFields($('#field_type').val()); "; $cs->registerScript(__CLASS__.'#dialog', $js); }
/** * Runs the widget. * This registers the necessary javascript code and renders the form close tag. */ public function run() { echo CHtml::endForm(); if(!$this->enableAjaxValidation || empty($this->_attributes)) return; $options=$this->clientOptions; if(isset($this->clientOptions['validationUrl']) && is_array($this->clientOptions['validationUrl'])) $options['validationUrl']=CHtml::normalizeUrl($this->clientOptions['validationUrl']); $options['attributes']=array(); foreach ($this->_attributes as $attr=>$item) { if (in_array($attr,$this->disableAjaxValidationAttributes)===false) { array_push($options['attributes'],$item); } } if($this->_summary!==null) $options['summaryID']=$this->_summary; $options=CJavaScript::encode($options); Y::clientScript()->registerCoreScript('yiiactiveform'); $id=$this->id; Y::clientScript()->registerScript(__CLASS__.'#'.$id,"\$('#$id').yiiactiveform($options);"); }
public function renderTableFooter() { Y::clientScript()->registerScript("pageSize"," $('#".$this->getId()."').delegate('.pageSizer','change',function() { $.fn.yiiGridView.update('".$this->getId()."',{data:{pageSize: $(this).val()}}); }); "); $options['pageSize'] = CHtml::dropDownList('pageSize', $this->dataProvider->pagination->pageSize, array(10=>10, 25=>25, 50=>50, 100=>100, 500=>500, 1000=>1000), array('class'=>'pageSizer')); echo "<tfoot>\n"; echo "<tr>\n"; echo "<td>\n"; foreach ($options as $item) echo $item; echo "</td>\n"; echo "</tr>\n"; echo "</tfoot>\n"; }