
/************ chunk video upload ***************/
var baseUrl = jQuery('#base_url').val();

/************ Story Video ************/
var datafile_story = new plupload.Uploader({
    runtimes: 'html5,flash,silverlight,html4',
    browse_button: 'uploadFile_story', // you can pass in id...
    container: document.getElementById('container_story'), // ... or DOM Element itself
    chunk_size: '1mb',
    url: baseUrl + '/admin/SaveChunkstory',
    max_file_count: 1,
    unique_names: true,
    send_file_name: true,
    multi_selection: false,
    filters: {
        mime_types: [
            { title: "Content files", extensions: "mp4" },
        ],
        prevent_duplicates: true
    },
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    init: {
        PostInit: function () {
            document.getElementById('filelist_story').innerHTML = '';
            document.getElementById('upload_story').onclick = function () {
                datafile_story.start();
                return false;
            };
        },
        FilesAdded: function (up, files) {

            while (up.files.length > 1) {
                up.removeFile(up.files[0]);
                document.getElementById('filelist_story').innerHTML = '';
            }

            plupload.each(files, function (file) {
                document.getElementById('filelist_story').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
            });
        },
        UploadProgress: function (up, file) {
            document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
            if (file.percent > 60) {
                // jQuery('#mp3_file_name1').val(file.name);
            }
        },
        FileUploaded: function (up, file, info) {
            var response = JSON.parse(info.response);
            if (response.result) {
                jQuery('#mp3_file_name_story').val(response.result);
            } else if (file.target_name) {
                jQuery('#mp3_file_name_story').val(file.target_name);
            }
        },
        Error: function (up, err) {
            document.getElementById('console1').innerHTML += "\nError #" + err.code + ": " + err.message;
        }
    }
});
datafile_story.init();
/***********************************************/
