Tinymce v6 dropzone config options - file

I've created a custom dialog with a dropzone in order to upload files and images to our server. By default the dropzone renders with 'Drop an image here' / 'Browse for an image'.
As part of the tinymce editor options file_picker_type allows setting of the default dropzone and I wondered how to access these options for a stand-alone dropzone?
My tinymce options include:
tinymce.init({
file_picker_types: 'file image'
});
My upload dialog config looks something like this:
const upload_config = {
title: 'Upload files',
size: 'medium',
body: {
type: 'panel',
{
type: 'dropzone',
name: 'file_drop',
types: 'file image' //// <----- something like this???
}
]
},
buttons: [
{
type: 'cancel',
name: 'closeButton',
text: 'Cancel',
},
{
type: 'submit',
name: 'submitButton',
text: 'Upload',
buttonType: 'primary'
}
],
onSubmit: (api) => {
// handle upload here
}
};
Anybody managed to fathom this? The tinymce docs are in no way comprehensive as they simply say "A dropzone is a composite component that catches drag and drops items or lets the user browse that can send a list of files for processing and receive the result." but give no details on how to actually do that with a stand alone dropzone.
I've managed to make it all work, but this is the last hurdle.
Thanks in advance

Are you trying to override the default image/file upload dialog with the custom one? I'm asking because I see the file_picker_types config option. To do so, you will need to use the file_picker_callback.
If it's something else and you are not trying to override the default dialog, use this interactive example as a base. You will need to:
a) Register the custom button with a setup function:
setup: function (editor) {
editor.ui.registry.addButton('custom-upload', {
icon: 'upload',
onAction: function () {
editor.windowManager.open(upload_config)
}
})
},
b) Add this button to the toolbar via toolbar: 'custom-upload'. This way, pressing the button will open the dialog based on the upload_config variable.
c) You've made a mistake in the panel config. I guess, you forgot to create the items array at the beginning. Instead of
type: 'panel',
{
type: 'dropzone',
name: 'file_drop',
types: 'file image' //// <----- something like this???
}
]
There should be:
type: 'panel',
items: [
{
type: 'dropzone',
name: 'file_drop',
label: 'Dropzone',
}
]
I've created this fiddle as a quick demo: https://fiddle.tiny.cloud/3iiaab
P.S. The dropzone component does not support file types. But you can check the file types after they are uploaded.

Related

Duplicate reference when maximizing/restoring dialog

When maximizing/restoring a dialog that contains some form fields with names, like:
Ext.create('Ext.Dialog', {
maximizable: true,
items: {
xtype: 'textfield',
name: 'id',
bind: '{record.id}'
},
buttons: [{
text: 'Save',
bind: {
disabled: '{!record.valid}'
}
}]
}).show();
we're getting an error:
Ext.mixin.Container.attachNameRef(): Duplicate name: "id" on ext-viewport between ext-textfield-1 and ext-textfield-5
Two found workarounds :
Disable animation
Ext.define('Override.Dialog', {
override: 'Ext.Dialog',
config: {
maximizeAnimation: false,
restoreAnimation: false
}
});
Make the proxy used for animation have no items (nor buttons since button disable state may not reflect the bounded value
Ext.define('Override.Dialog', {
override: 'Ext.Dialog',
config: {
maximizeProxy: {
items: null,
buttons: null
}
}
});
Background Information
During maximize and minimize ExtJS creates a shadow clone.
This will create a clone of the window, while you still have the original item.
Using an ID means, there can only be one identical one at any given time.
The clone tries to create the your textfield with the same ID, which does not work.
Typically you want to
for forms you usually do not need to grab each item as you can work with validator and getValues on the form
otherwise you might want to work with references in the view and lookupReference in the controller.
not use animation (because that does not create a clone)
write your own maximize animation and do the animation part yourself (write your own maximize function)

Blur/Click on Formpanel ExtJS 4 does not access form fields correctly

I have an ExtJS Formpanel and I have written a listener on a click for the form ( not on any fields of a form ) which is working fine.
Even after setting the Ext.FocusManager.Enable() to true, I am not able to get the even 'blur' working. What am I missing?
I am not able to access form fields from the event handlers for formpanel click event. When I do - this.up.('form').get.(fielname).value [which works fine in the event handlers on the form fields.] It says the element is undefined. How can I access the form elements here?
Adding the code snippet -
// Call it Object A
Ext.create.('Ext.form.Panel', {
id : xyz,
items: [
{
xtype : 'textfield',
name : 'test',
fieldLabel : 'Name'
}
listeners : { // listener on the formPanel; not on any of its element
click : {
console.log("this works" );
},
focus : {
console.log('this does not work');
}
}
]
}
I am doing this so that I can access a value of another object, say B.field.
Onload I am able to fetch the value of B.field. But when the user changes the value of B.field which is on a different tab, I am not able to fetch the changed value of B.field in A. I am just finding ways to avoid an Ajax call to the database, if possible.
Thanks in advance for your time.
Without any sample from your code to reference, it's hard to determine what you are trying to do.
It could be that you just need to fix how you are querying for the form elements. For example, elements in a toolbar are not children of the form, so up/down doesn't work.
I don't think you can listen for the events focus, blur, or click on a form. Even if you could, I am not sure you would want to do. Instead, it's more common to listen for focus on a field or click on a button.
Example 1 form with field using focus and button using click
http://codepen.io/anon/pen/qEPRge?editors=001
;(function(Ext) {
Ext.onReady(function() {
console.log("Ext.onReady")
var form = new Ext.create("Ext.form.Panel", {
title: "person"
,items: [
{itemId: "fld-id", fieldLabel: "id", name: "id", value: "1", xtype: "textfield", labelAlign: "top", labelSeparator: ""}
,{itemId: "fld-name", fieldLabel: "name", name: "name", value: "Emily", xtype: "textfield", labelAlign: "top", labelSeparator: ""}
,{itemId: "btn-submit", text: "submit", xtype: "button"}
]
})
form.on("afterrender", function(component) {
console.log("form.afterrender")
})
form.render(Ext.getBody())
form.queryById("fld-id").on("focus", function(component) {
console.log("fld-id.focus")
})
form.queryById("fld-name").on("focus", function(component) {
console.log("fld-name.focus")
})
form.queryById("btn-submit").on("click", function(component) {
console.log("btn-submit.click")
console.log("fld-id.value:")
console.log(component.up("form").queryById("fld-id").getValue())
console.log("fld-name.value:")
console.log(component.up("form").queryById("fld-name").getValue())
})
})
})(Ext)

extjs - Change setting in property grid and save it to the server

I have a property grid Ext.grid.property.grid. I want to use it to allow the user to change his account settings. I achieved to display custom editors, but I'm stuck to get the new value saved to the server.
Ext.define('Mb.view.Settings', {
extend: 'Ext.grid.property.Grid',
alias: 'widget.settings',
requires: ['Ext.tab.Panel'],
title: Lang._('Options'),
source: {
username: Mb.user.name,
email: Mb.settings.email
},
sourceConfig:{
username: {
displayName: Lang._('Nom d\'utilisateur'),
editor: 'displayfield'
},
email: {
displayName: Lang._('Adresse email'),
editor: {
xtype: 'textfield',
vtype: 'email'
}
}
}
});
I look for an event that allows me to trigger an Ajax call to the server to save the new setting, but I cannot find what I'm looking for in the documentation.
You are looking in the wrong place: it is the record that changes, meaning you have to look in the attached store: look at the store's datachanged event and then use store.getModifiedRecords().

How to restrict file type using xtype filefield(extjs 4.1.0)?

I am trying to implement file upload feature using extjs 4.1.0. Whereas I want to restrict users to select only image files(jpg,png,gif). Is there any filter which can be applied so that users will only be able to see and then select the types of the files mentioned above?
You could stuff like this as well :
{
xtype: 'filefield',
buttonText: '....',
listeners:{
afterrender:function(cmp){
cmp.fileInputEl.set({
accept:'image/*' // or w/e type
});
}
}
}
See http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.VTypes VAlidation types for an example of a custom type. You could use a regexp to specify alphaMask as well.
{
xtype: 'fileuploadfield',
name: 'file',
fieldLabel: 'Photo',
labelWidth: 50,
allowBlank: false,
buttonText: 'SelectPhoto',
anchor: '100%',
reset: function () {
var me = this,
clear = me.clearOnSubmit;
if (me.rendered) {
me.button.reset(clear);
me.fileInputEl = me.button.fileInputEl;
me.fileInputEl.set({
accept: 'image/*'
});
if (clear) {
me.inputEl.dom.value = '';
}
me.callParent();
}},
listeners:{
change: 'fileInputChange',
afterrender:function(cmp){
cmp.fileInputEl.set({
accept:'image/*'
});
}
},
regex: /(.)+((\.png)|(\.jpg)|(\.jpeg)(\w)?)$/i,
regexText: 'Only PNG and JPEG image formats are accepted'
}
regex adds client side validation, to which a form bind can be put on whatever form or action you are planning on doing.

Ext.Direct Form Integration

I am using Ext.direct.RemotingProvider . At the server side I make some validation checks. The Respond is send back in JSON format.
If i find any errors when making validation checks, the field success = false, and errors will contain the error.
I am trying to figure out, how do i reflect errors i found in the server side in the form (client side).
In the link below there is an example of what i want to achieve. When the client press on "submit" an error message will occur in the form, how does it work ?
Example
In the code i post in the bottom the following happens:
in the browser there are 2 fields (Name,Email) and 2 buttons.
the fields are irrelevant for now. they are used as dummies.
Each time the user press on "Add" button, a new action is added into callBuffer of Ext.direct.RemotingProvider
When the user press on "Apply" button, all the actions are being sent to the router (MVC model) and from there to a specific controller. (the function sfw.Direct.getProvider('sfwProvider').combineAndSend() is triggered).
As for now, i intentionally fails the respond and create an error field, just like the example link i added in the beginning of the Thread.
i put in the errors field {email="Already exists"}.
but i see not effect in the form..
what am i doing wrong ?
Code:
appWiki.main_panel = new Ext.FormPanel({
renderTo: 'extjs_panels_container'
, id: 'appWiki_main_panel'
, name: 'appWiki_main_panel'
, defaultType: 'textfield'
, items: [
{
fieldLabel: 'Name',
name: 'name'
}
,{
fieldLabel: 'Email',
msgTarget: 'side',
name: 'email'
}]
,buttons:[
{xtype: 'sfw.Button'
, text: 'Add'
, handler: function(){sfw.rule.store.api.readByRowId({data: {_ROWID_: 1}});}
}
,{text: 'Submit'
, handler: function(){
appWiki.main_panel.getForm().submit({
});
}
}]
,api: {
// The server-side must mark the submit handler as a 'formHandler'
submit: sumbitAllRequests
}
, load: function()
{
setTimeout("hide_loading_mask()",2000);
}
});
In the JSON response you need the following structure
{ "result" : { "success": false, "errors": { "name of field" : "validation message" } }
Where "name of field" is the name config option in your field, and "validation message" is the message you want to display to the user.
When you send a response like that ExtJS will take care of the rest.
EDIT: You may also need to enable QuickTips:
Ext.QuickTips.init();
Add that line before you declare your form
EDIT 2: Also, make sure you're using the submit() method found on the BasicForm:
buttons:[{
text: 'Submit',
handler: function(){
basicInfo.getForm().submit({
params: {
foo: 'bar',
uid: 34
}
});
}
}],

Resources