fine upload validation set - javascript

I´m using the Fine Upload-Plugin.
I want to upload .docx-files to my application ... only .docx-files.
Surely this is easy to handle with a query, like
if (extension == "docx")
upload something
But I saw a field in which you can specify a data type like "All types" or "All images".
Where can i add/manipulate this validation?
I tried the acceptFiles-options, but this only prevent uploads.
I want to give the user the possibility to show .docx-files only.
HTML-Code:
<div id="manual-fine-uploader"></div>
<div id="triggerUpload" class="btn btn-primary" style="margin-top: 10px;display:none">
<i class="icon-upload icon-white"></i> Datei einfügen
</div>
<div id="uploadNewFile"></div>
JS-Code
$("#uploadNewFile").fineUploader({
element: document.getElementById('manual-fine-uploader'),
request: {
endpoint: 'Upload.aspx'
},
autoUpload: true,
//Part, that may be important
///MEME-Type: docx
acceptFiles: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
allowedExtensions: ["docx"],
//Endpart
maxConnections: 1,
multiple: false,
chunking: {
enabled: true
},
resume: {
enabled: true
},
text: {
uploadButton: 'Datei hochladen'
}
});
EDIT:
Maybe the Question isnt clear enough:
I need a specific filter within the select-file-dialog.
Like the standard "images only" or "all types" etc..
How to add these kind of filter?
Here you see the select

Your allowedExtensions and acceptFiles options are not in the correct place. Your code should look like this:
$("#uploadNewFile").fineUploader({
element: document.getElementById('manual-fine-uploader'),
request: {
endpoint: 'Upload.aspx'
},
validation: {
acceptFiles: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
allowedExtensions: ["docx"]
},
maxConnections: 1,
multiple: false,
chunking: {
enabled: true
},
resume: {
enabled: true
},
text: {
uploadButton: 'Datei hochladen'
}
});
Please see the validation option in the documentation for more details, along with the validation feature page.
Also, if you are using Fine Uploader 4.x, the text.uploadButton option was removed as part of the templating redesign. In 4.x and newer, you can specify the button name, among other things, in a template you declare in your markup.
Finally, I removed the autoUpload option from your configuration, as you were setting it to the default value. No need to declare it in that case.

Related

How to Hide "Filter By Name" search box under filterByColumn in vuejs?

I'm following a tutorial, but I would like to hide or remove this search box.
I've looked through the Internet and seems I haven't found a solution yet.
I want to get rid of these two search boxes:
My Code is like this:
Vue.use(VueTables.client, {
compileTemplates: true,
filterByColumn: true,
sortable: false,
texts: {
filter: "Search:"
},
datepickerOptions: {
showDropdowns: true
},
---
});
Is there any filterByColumn option to hide these two boxes?
Full code is here: https://jsfiddle.net/e0uLphvk/
Here is an updated jsfiddle.
Basically, you need to add the columns you want to filter to options.filterable array in your Vue data.
new Vue({
// ..
data: {
// ..
options: {
//...
filterable: ['manufacturer', 'birth_date'],
}
}
})

How to deny the drop event?

Before version 2016.3.914, it was possible to cancel a drop event by calling e.setStatusClass("k-denied");
$("#treeview").kendoTreeView({
dragAndDrop: true,
dataSource: [
{ text: "foo", items: [
{ text: "bar" }
] }
],
drag: function(e) {
e.setStatusClass("k-denied");
}
});
However, starting from version 2016.3.914, the pre-defined status classe k-denied doesn't work anymore. The documentation says that k-i- should be added as class prefix but k-i-denied doesn't work as the cancel icon doesn't appear and the drop is still allowed.
Please note that from version 2016.3.914 the naming convention for pre-defined status classes is k-i-className.
Note that status classes are returned without the k- prefix by
e.statusClass, but this prefix is required when setting a predefined
status class via e.setStatusClass. A prefix is not required if setting
a custom status CSS class.
The documentation was right about one thing. We do have to use the k-i- prefix. However, what the documentation doesn't tell you is the fact that kendo has changed the pre-defined status classes from k-denied to k-i-cancel
$("#treeview").kendoTreeView({
dragAndDrop: true,
dataSource: [
{ text: "foo", items: [
{ text: "bar" }
] }
],
drag: function(e) {
e.setStatusClass("k-i-cancel");
}
});

Check if datatables is empty after table is fully loaded jQuery

After doing some research on this issue trying to find a solution (unfortunately to no avail) I decided that it might be best to post my problem. I currently have a Datatable containing asset information on a view and I'm trying to prevent a user from continuing change an option on a select field until an asset is added to the asset table.
Listed below is my assets datatable code in my .js file under the document.ready function
assets = $('#assets').dataTable({
sAjaxSource: "http://" + window.location.hostname + "/request/get-request-assets/?id=" + $('#id').val(),
fnDrawCallback: function (oSettings) {
setIncompleteTD();
enableRequestStatus();
},
scrollY: '185px',
scrollCollapse: true,
paging: false,
aaSorting: [[1, 'asc']],
bPaginate: false,
bFilter: false,
bLengthChange: false,
bAutoWidth: false,
bInfo: false,
aoColumns: [
{sWidth: '35px', bSortable: false},
{sWidth: '40px'},
{},
{},
{},
{},
{},
{sWidth: '80px'}
],
language: {
sLoadingRecords: '',
sEmptyTable: 'This request has no asset records.',
sInfoEmpty: ''
}
I've found table.fnSettings().aoData.length===0 as a means to check if a table is empty. However, after stepping through the code (via Chrome debugger) it seems Datatables (at least in my case) calls the function before the table is fully generated...
I have this code below
assetPresent = (assets.fnSettings().aoData.length===0) ? false : true;
console.log(assetPresent);
in my document.ready function after $('#assets').dataTable() function (if this matters). AssetPresent will be used as a flag to toggle the status select box. Unfortunately before I can utilize that...
console.log(assetPresent);
Seems to always be set to false even if there are clearly records in the table, and...
assetPresent = (assets.fnSettings().aoData.length===0) ? false : true;
Tends to be ignored...
I'm curious to see if table.fnSettings().aoData.length===0 might not be the best option. Thank you in advance.
Have you tried, table.data().length yet?
you can try this
var table = $('#assets').DataTable();
if ( ! table.data().any() ) {
alert( 'Empty table' );
}

Codemirror autocomplete and auto closing brackets doesnt trigger change event

I have the following problem. I've written a server and client scripts for node js that work as live collaboration code editing. 2 or more people can code in the same instance of CodeMirror editor. Until i have enabled autocomplete feature and auto closing brackets it was working perfect, but after i did it messed up the work. When you use autocomplete list or when bracket or tag will be closed by module not by you manually it will not be recognized as change. I have inspected an object that CodeMirror instance is returning and it doesnt contain change that have been done automatically. its not even strictly problem for node js beacuse if you want lets say, send changes to server via ajax and save in a file, it wont happen beacuse its not present in change object. Anyone had similiar problem and can help?
client code:
var appCM = CodeMirror.fromTextArea(document.getElementById('app-cm'), {
mode: 'text/html',
theme: "monokai",
styleActiveLine: true,
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
indentWithTabs: true,
autoCloseTags: true,
autoCloseBrackets: true,
matchTags: false,
extraKeys: {
"Ctrl-Space": "autocomplete",
"Ctrl-Q": function(appCM) {
appCM.foldCode(appCM.getCursor());
}
},
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
readOnly: access
});
appCM.on('change', function(i, op) {
socket.emit('change', op);
});
socket.on('change', function(data) {
appCM.replaceRange(data.text, data.from, data.to);
});
server code:
socket.on('change', function(op) {
if(op.origin === '+input' || op.origin === 'paste' || op.origin === '+delete') {
clients.forEach(function(client) {
if(client !== socket)
client.emit('change', op);
});
};
});
You are explicitly filtering out changes whose origin isn't one of input/paste/delete. Why are you doing that? You'll need to propagate all changes if you want peers to stay in sync.

Kendo UI custom grid popup editor window only opens once

I would like to use a custom window as popup editor of a Kendo UI Grid. Its content will be complex with search fields and a grid to display search results. To do that, I don't want to use the Kendo template mechanism but a real popup window.
While doing tests with custom editor I faced an issue. Even with a very basic and simple scenario (just the create command), I'm only able to open the editor once. The second time I get an error, the editor doesn't show up anymore and the grid becomes empty.
Here is my HTML code :
<div id="main-content">
<div id="custom-window">
</div>
<table id="my-table-grid">
</table>
</div>
The JavaScript part :
function openCustomWindow(e) {
e.preventDefault();
myWindow.center().open();
}
function editorWindowClosed(e) {
myGrid.cancelRow();
}
var myWindow = $("#custom-window").kendoWindow({
modal: true,
resizable: false,
title: "Test",
visible: false,
close: editorWindowClosed
}).data("kendoWindow");
var dummyDataSource = new kendo.data.DataSource(
{
schema : {
model : {
id: "id",
fields: {
postion: { type: "number"},
name: { type: "string"},
}
}
}
});
dummyDataSource.add({postion: 1, name: "gswin"});
var myGrid = $("#my-table-grid").kendoGrid({
dataSource: dummyDataSource,
toolbar: [ {
name: "create",
text: "Create"
} ],
editable: {
mode: "popup",
window: {
animation: false,
open: openCustomWindow,
}
},
columns: [
{
field: "postion",
title: "Postion"
},
{
field: "name",
title: "Name"
}
]
}).data("kendoGrid");
The error message in the JavaScript console :
Uncaught TypeError: Cannot read property 'uid' of
undefinedut.ui.DataBoundWidget.extend.cancelRow #
kendo.all.min.js:29ut.ui.DataBoundWidget.extend.addRow #
kendo.all.min.js:29(anonymous function) #
kendo.all.min.js:29jQuery.event.dispatch #
jquery-2.1.3.js:4430jQuery.event.add.elemData.handle #
jquery-2.1.3.js:4116
And finally a jsfiddle link to show what I'm doing. (The popup is empty because I just want to fix the open / close mechanism before going any further)
I don't understand why I get this error, I expected to be able to open / close the popup as many time as I wanted. The default editor popup is working fine.
One of my colleague found the solution (thanks to him).
Actually this piece of code
editable: {
mode: "popup",
window: {
animation: false,
open: openCustomWindow,
}
}
is designed to configure the default popup...
The right way to use a custom popup is the following :
editable :true,
edit: openCustomWindow,
With this approach it's also better to use
function editorWindowClosed(e) {
myGrid.cancelChanges();
}
Instead of
function editorWindowClosed(e) {
myGrid.cancelRow();
}
Working jsfiddle link
Actually the approach in my previous answer solved my issue but is causing another issue. The grid becomes editable but in the default mode (which is "inline").
Doing this
editable: "popup",
edit: openCustomWindow
has fixed this other issue but is now displaying 2 popups.
I finally succeeded to hide the default popup and only show my custom popup but it ended with the orginal issue described in initial question...
Considering all those informations I arrived to the conclusion that working with a custom popup window is definitely not an option. I'll start working with teamplates instead.
Another solution would have been to use a template to override the toolbar with a custom "Add" button and use a custom command for edition. But at this point I consider that too "tricky".
To prevent Kendo UI custom grid popup editor window, define the editable property:
editable:
{
mode: "popup",
window: {
animation: false,
open: updateRowEventHandler
}
} // skip edit property
Then paste preventDefault() at the beginning of the handler:
function updateRowEventHandler(e) {
e.preventDefault(); //

Categories

Resources