Last active
December 20, 2015 19:49
-
-
Save herooutoftime/6186046 to your computer and use it in GitHub Desktop.
A MODx plugin to hook into the 'fileadd' event of the file-upload-dialog and render a window with a form to fill out.
Please use carefully!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$event = $modx->event->name; | |
switch($event) { | |
case 'OnManagerPageInit': | |
$id = 'ext-comp-1107'; | |
$js =<<<JS | |
<script type="text/javascript"> | |
function find_dialog() { | |
Ext.onReady(function() { | |
// var dialog = Ext.getCmp('modx-upload-window'); | |
// console.log(dialog); | |
var updialog = Ext.getCmp('$id'); | |
// console.log(updialog); | |
if(updialog) | |
window.clearInterval(interval); | |
if(!updialog) | |
return; | |
function add_window(filename, path) { | |
var medialib_form = new Ext.FormPanel({ | |
url: MODx.config.base_url + 'assets/save-form.php', | |
frame:true, | |
defaultType: 'textfield', | |
items: [{ | |
xtype: 'hidden', | |
name: 'path', | |
value: path, | |
},{ | |
xtype: 'hidden', | |
name: 'filename', | |
value: filename, | |
},{ | |
fieldLabel: 'Titel', | |
name: 'title', | |
anchor: '100%', | |
allowBlank:false | |
},{ | |
xtype: 'textarea', | |
fieldLabel: 'Copyright', | |
name: 'copyright', | |
anchor: '100%', | |
allowBlank:false | |
},{ | |
xtype: 'textarea', | |
fieldLabel: 'Beschreibung', | |
name: 'description', | |
anchor: '100%', | |
} | |
], | |
buttons: [{ | |
text: 'Speichern', | |
handler: function(button, e){ | |
// medialib_form.getForm().submit(); | |
var form = medialib_form.getForm(); | |
if (form.isValid()) { | |
form.submit({ | |
success: function(form, action) { | |
win.close(); | |
}, | |
failure: function(form, action) { | |
Ext.Msg.alert('Fehler', action.result ? action.result.message : 'Keine Antwort'); | |
} | |
}); | |
} else { | |
Ext.Msg.alert( "Fehler!", "Bitte füllen Sie das Formular korrekt aus!" ); | |
} | |
} | |
},{ | |
text: 'Abbrechen', | |
handler: function(button, e) { | |
win.close(); | |
} | |
}] | |
}); | |
var win = new Ext.Window({ | |
id: 'my_window' | |
, title : "Medienbibliothek" | |
, width : 500 | |
, height: 500 | |
, layout: "fit" | |
,items: medialib_form | |
}); | |
win.show(); | |
} | |
Ext.getCmp('$id').on('fileadd', function(dialog, filename) { | |
var ext = filename.split('.').pop(); | |
var allowed = ['jpg', 'jpeg', 'gif', 'png']; | |
if(allowed.indexOf(ext) == -1) | |
return; | |
add_window( filename, dialog.base_params.path); | |
}); | |
}); | |
} | |
var interval = window.setInterval(function(){find_dialog();}, 1000); | |
</script> | |
JS; | |
$modx->regClientStartupScript($js); | |
break; | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment