Skip to content

Instantly share code, notes, and snippets.

@fontamel
Created April 4, 2022 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fontamel/51c919a530a5b1bafd2ac91ee54fc87c to your computer and use it in GitHub Desktop.
Save fontamel/51c919a530a5b1bafd2ac91ee54fc87c to your computer and use it in GitHub Desktop.
Articles
//--- FIELDS ----
$g->table = "articles";
$col = array();
$col["title"] = "Id"; // caption of column
$col["name"] = "id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["hidden"] = true;
$col["width"] = "1";
$col["export"] = false;
$col["search"] = false; // this column is not searchable
$col["sortable"] = false; // this column is not sortable
$col["editable"] = false; // this column is not editable
$col["formoptions"] = array("rowpos"=>"1", "colpos"=>"1");
$cols[] = $col;
$col = array();
$col["title"] = "Date"; // caption of column
$col["name"] = "date"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "25";
$col["export"] = false;
$col["hidden"] = true;
$col["formatter"] = "date"; // format as date
# opts array can have these options: http://api.jqueryui.com/datepicker/
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d.m.Y', "opts" => array("changeYear" => true,
"dayNamesMin" => [ "Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa" ],"monthNamesShort" => [ "Jan", "Fév", "Mar", "Avr", "Mai", "Juin", "Juil", "Aoüt", "Sep", "Oct", "Nov", "Déc" ],"currentText"=> 'Maintenant',"closeText"=>'Fermer'));
$col["align"] = "center"; // this column is not editable
$col["editable"] = true; // this column is not editable
$col["search"] = true; // this column is not searchable
$col["sortable"] = true; // this column is not sortable
$col["editrules"] = array("required"=>true);
$col["formoptions"] = array("rowpos"=>"2", "colpos"=>"1");
$col["show"] = array("list"=>false,"edit"=>true,"add"=>true); // only show in add/edit dialog
$cols[] = $col;
$col = array();
$col["title"] = "Sujet";
$col["name"] = "sujets";
$col["width"] = "30";
$col["export"] = false;
$col["hidden"] = true;
$col["search"] = true; // this column is not searchable
$col["editable"] = true; // this column is not editable
$col["sortable"] = false; // this column is not sortable
$col["editrules"] = array("required"=>true);
$col["formoptions"] = array("rowpos"=>"3", "colpos"=>"1");
$col["show"] = array("list"=>false,"edit"=>true,"add"=>true); // only show in add/edit dialog
$cols[] = $col;
$col = array();
$col["title"] = "Auteur";
$col["name"] = "auteurs";
$col["width"] = "30";
$col["export"] = false;
$col["hidden"] = true;
$col["search"] = true; // this column is not searchable
$col["editable"] = true; // this column is not editable
$col["sortable"] = true; // this column is not sortable
$col["editrules"] = array("required"=>true);
$col["formoptions"] = array("rowpos"=>"4", "colpos"=>"1");
$col["show"] = array("list"=>false,"edit"=>true,"add"=>true); // only show in add/edit dialog
$cols[] = $col;
$col = array();
$col["title"] = "Articles - Saison 2022";
$col["name"] = "articles";
$col["width"] = "300";
$col["export"] = false;
$col["hidden"] = true;
$col["search"] = true;
$col["sortable"] = false;
$col["editable"] = true;
$col["edittype"] = "textarea";
$col["editrules"] = array("edithidden"=>true);
$col["editrules"] = array("required"=>true);
$col["formoptions"] = array("rowpos"=>"5", "colpos"=>"1");
$col["formatter"] = "html";
$col["editoptions"]["dataInit"] = "function(el){ setTimeout(function(){ link_ckeditor(el); },20); }";
$col["show"] = array("list"=>false,"edit"=>true,"add"=>true);
$cols[] = $col;
$col = array();
$col["title"] = "Articles - Saison 2022";
$col["name"] = "articles2022";
$col["width"] = "650";
$col["template"] = "<b>Date :</b> {date}<br><b>Sujet :</b> {sujets}<br><b>Auteur :</b> {auteurs}<hr class='hr'>{articles}";
$col["dbname"] = "concat(date,' ',sujets,' ',auteurs,' ',articles)";
$cols[] = $col;
// pass the cooked columns to grid
$g->set_columns($cols);
//----------- SCRIPT --------------
<script type="text/javascript">
function link_ckeditor(el)
{
// Full Set
CKEDITOR.config.toolbar = [
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates' ] },
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
{ name: 'forms', items: [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
'/',
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language' ] },
{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
{ name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe' ] },
'/',
{ name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{ name: 'tools', items: [ 'Maximize', 'ShowBlocks' ] },
{ name: 'others', items: [ '-' ] },
{ name: 'about', items: [ 'About' ] }
];
// remove nbsp; from start of textarea
if(el.previousSibling) el.parentNode.removeChild(el.previousSibling);
$(el).parent().css('padding-left','6px');
var editor = CKEDITOR.replace( el, {
extraPlugins: 'colorbutton,colordialog',
on: {
change: function(){ jQuery(el).val(editor.getData()); }
}
});
//------ YOUR SCRIPT
/* var editor = CKEDITOR.replace( el, {
extraPlugins: 'uploadimage',
uploadUrl:'uploader/upload.php',
on: {
change: function(){ jQuery(el).val(editor.getData()); }
}
});
*/
//-------- MY SCRIPT WORKING BUT CANNOT ADD & EDIT
var editor = CKEDITOR.replace( el, {
extraPlugins: 'uploadimage',
// Configure your file manager integration. This example uses CKFinder 3 for PHP.
filebrowserBrowseUrl: '/ckfinder/3.4.5/ckfinder.html',
filebrowserImageBrowseUrl: '/ckfinder/3.4.5/ckfinder.html?type=Images',
filebrowserUploadUrl: '/ckfinder/3.4.5/core/connector/php/connector.php?command=QuickUpload&type=Files',
filebrowserImageUploadUrl: '/ckfinder/3.4.5/core/connector/php/connector.php?command=QuickUpload&type=Images',
// Upload dropped or pasted images to the CKFinder connector (note that the response type is set to JSON).
uploadUrl: '/ckfinder/3.4.5/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json',
// Reduce the list of block elements listed in the Format drop-down to the most commonly used.
format_tags: 'p;h1;h2;h3;pre',
// Simplify the Image and Link dialog windows. The "Advanced" tab is not needed in most cases.
removeDialogTabs: 'image:advanced;link:advanced',
//height: 450,
//removeButtons: 'PasteFromWord'
on: {
change: function(){ jQuery(el).val(editor.getData()); }
}
});
// unblock typing in ckeditor dialog - events tracked with firebug > script > global pause > stack
jQuery(document).unbind('keypress').unbind('keydown').unbind('mousedown');
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment