var _isDirtyDataset = false;
var _isDirtyProfile = false;
var _isFirstRefresh = true;
var _currentQuestion = false;
var _makeNewCopy = false;
$(document).ready(function() {
var file_data = null;
var file_codebook = null;
var file_protocol = null;
var file_report = null;
$(document).ready(function () {
//console.log("I'm a logged in editor");
//console.log("Do I use LawAtlas for these?");
//console.log(use_lawatlas_host);
//console.log("^ out of scope...poo");
console.log(monocle_host);
use_lawatlas_host = false;
if( $("#use_lawatlas").val() != '' && $("#use_lawatlas").val() == "true"){
use_lawatlas_host = true;
}
use_lawatlas_dataset = false;
if( $("#use_lawatlas_dataset").val() != '' && $("#use_lawatlas_dataset").val() == "true"){
use_lawatlas_dataset = true;
}
is_migrated_lawatlas_dataset = false;
if( $("#is_migrated_lawatlas_dataset").val() != '' && $("#is_migrated_lawatlas_dataset").val() == "true"){
use_lawatlas_dataset = true;
}
was_migrated = false;
if( $("#was_migrated").val() != '' && $("#was_migrated").val() == "true"){
was_migrated = true;
}
migrated_level_2 = false;
if( $("#migrated_level_2").val() != '' && $("#migrated_level_2").val() == "true"){
migrated_level_2 = true;
}
migrated_level_3 = false;
if( $("#migrated_level_3").val() != '' && $("#migrated_level_3").val() == "true"){
migrated_level_3 = true;
}
CKEDITOR.disableAutoInline = true;
/*
CKEDITOR.instances['description'].on('instanceReady', function (event) {
//CKEDITOR.instances['description'].focus();
$("#saveZPreview").removeClass("btn-success").addClass("btn-warning");
});*/
/*
CKEDITOR.inline( 'ptitle' );
CKEDITOR.instances['ptitle'].on('focus', function (event) {
//CKEDITOR.instances['description'].focus();
$("#saveZPreview").removeClass("hide").removeClass("btn-success").addClass("btn-warning");
$("#saveZDocuments").removeClass("hide");
});*/
in_edit_mode = sessionStorage.getItem('in_edit_mode');
if(in_edit_mode == "true"){
enableEditing();
} else {
disableEditing();
}
$("#editToggleClick").on("click", function(){
$('.site-loading').show();
if(!use_lawatlas_host || migrated_level_2){
console.log("Not in LawAtlas.");
setTimeout(checkEditing, 1000);
} else {
//alert("can't edit LawAtlas previews, must use LawAtlas");
//modal
$("#lawatlasMigration").modal("show");
}
});
//migration clicks
$(document).on('click', '#postponeMigration', function () {
LawAtlasMigration(-1);
});
$(document).on('click', '#migratePublications', function () {
$(".migration_working").removeClass("hide");
LawAtlasMigration(1);
});
$(document).on('click', '#migrateAll', function () {
$(".migration_working").removeClass("hide");
LawAtlasMigration(2);
});
//migrateLevel3, after a successful Leve 2
$(document).on('click', '#migrateLevel3', function () {
//$(".migration_working").removeClass("hide");
LawAtlasMigrationLevel3();
});
//just-close
$(document).on('click', '.just-close', function () {
LawAtlasMigration(-1);
});
//publish click
$(document).on('change', '#publishZPreview', function () {
console.log("publish changed");
});
//useZSlider
$(document).on('change', '#useZSlider', function () {
console.log("slider usage changed");
_makeNewCopy = true;
console.log("make new copy?");
console.log(_makeNewCopy);
});
//zStartYear
$(document).on('change', '#zStartYear', function () {
console.log("slider start year changed");
_makeNewCopy = true;
console.log("make new copy?");
console.log(_makeNewCopy);
});
//zEndYear
$(document).on('change', '#zEndYear', function () {
console.log("slider end year changed");
_makeNewCopy = true;
console.log("make new copy?");
console.log(_makeNewCopy);
});
$(document).on('change', '#zDataset_taxonomies', function () {
console.log("taxonomy changed");
_makeNewCopy = true;
console.log("make new copy?");
console.log(_makeNewCopy);
});
$("#getZQuestions").on("click", function(){
///{id}/50status/questions
preview_id = $('#preview_id').val();
if($('#preview_id').val() != ''){
zurl = monocle_host + "previewer/" + preview_id + "/50status/questions";
$.get( zurl, function( data ) {
console.log(data);
$("#questions_from_monqcle").html(data);
console.log("Questions are loaded and ready???");
});
}
});
$(document).on("click", ".hide-preview-question", function () {
//console.log("Remove Questions");
preview = $("#preview_id").val();
removePreviewQuestion(preview, $(this).data('id'), $(this).data('parent'));
//removePreviewFile(file, preview)
});
$("#saveZDocuments").on("click", function(){
//just to test
console.log(monocle_host);
preview_id = $('#preview_id').val();
//console.log ( $('#preview_id').val() );
dataset_id = $(".dataset_id").val();
display_id = $("#display_id").val();
if($('#preview_id').val() != ''){
zurl = monocle_host + "app_dev.php/previewer/" + preview_id + "/50status/uploads?email=" + email;
$.post( zurl, function( data ) {
$( "#zdocsajax" ).html( data );
$("#medias_wrapper").hide();
//global_monocle_url = 'http://api.monqcle.com';
var url = monocle_host + 'upload/add';
var uploadButton = $('')
.addClass('btn btn-primary')
.prop('disabled', true)
.text('Processing...')
.on('click', function () {
var $this = $(this),
data = $this.data();
$this
.off('click')
.text('Abort')
.on('click', function () {
$this.remove();
data.abort();
});
data.submit().always(function () {
$this.remove();
});
});
//new-media-add-file
$('#form_data_newfile_new').fileupload({
url: url,
formData: {preview: preview_id, email: email, dataset: dataset_id, display: display_id},
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|doc|docx|xsl|xslx|pdf|csv|txt|rtf|dat)$/i,
maxFileSize: 999000,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
data.context = $('
').appendTo('#data_newfile_files');
$.each(data.files, function (index, file) {
var node = $('')
.append($('').text(file.name));
if (!index) {
node
.append('
')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node
.prepend('
')
.prepend(file.preview);
}
if (file.error) {
node
.append('
')
.append($('').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button')
.text('Upload')
.prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
/*
$('#data_codebook_progress .progress-bar').css(
'width',
progress + '%'
).text(progress + '%');
*/
}).on('fileuploaddone', function (e, data) {
$.each(data.result.documents, function (index, file) {
if (file.url) {
var link = $('')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('').text(file.error);
$(data.context.children()[index])
.append('
')
.append(error);
}
getPreviewMediaBlockTemplate(file.id, file.filetype, file.name, 'data_newfile' );
/*
getPreviewMediaBlockTemplate(file.id, file.filetype, file.name, 'data_codebook' );
$(".btn-lawatlas-codebook").prop("href", monocle_host + "upload/" + file.id + "/download");
$(".btn-lawatlas-codebook").show();
_makeNewCopy = true;
*/
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('').text('File upload failed.');
$(data.context.children()[index])
.append('
')
.append(error);
});
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
$('#form_data_codebook_new').fileupload({
url: url,
formData: {preview: preview_id, email: email, dataset: dataset_id, display: display_id},
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|doc|docx|xsl|xslx|pdf|txt|rtf|dat)$/i,
maxFileSize: 999000,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
data.context = $('').appendTo('#data_codebook_files');
$.each(data.files, function (index, file) {
var node = $('')
.append($('').text(file.name));
if (!index) {
node
.append('
')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node
.prepend('
')
.prepend(file.preview);
}
if (file.error) {
node
.append('
')
.append($('').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button')
.text('Upload')
.prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#data_codebook_progress .progress-bar').css(
'width',
progress + '%'
).text(progress + '%');
}).on('fileuploaddone', function (e, data) {
$.each(data.result.documents, function (index, file) {
if (file.url) {
var link = $('')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('').text(file.error);
$(data.context.children()[index])
.append('
')
.append(error);
}
//refreshFileUploadsMediaBlock(id, filetype, filename, referenced)
//console.log(file);
getPreviewMediaBlockTemplate(file.id, file.filetype, file.name, 'data_codebook' );
$(".btn-lawatlas-codebook").prop("href", monocle_host + "upload/" + file.id + "/download");
$(".btn-lawatlas-codebook").show();
_makeNewCopy = true;
//refreshFileUploadsDisplay();
//console.log(file);
//{{ document.datacodebook }}
//$("#data_codebook_list").append(''+file.name+' ');
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('').text('File upload failed.');
$(data.context.children()[index])
.append('
')
.append(error);
});
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
$('#form_data_protocol_new').fileupload({
url: url,
formData: {preview: preview_id, email: email, dataset: dataset_id, display: display_id},
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|doc|docx|xsl|xslx|pdf|txt|rtf|dat)$/i,
maxFileSize: 999000,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
data.context = $('').appendTo('#data_protocol_files');
$.each(data.files, function (index, file) {
var node = $('')
.append($('').text(file.name));
if (!index) {
node
.append('
')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node
.prepend('
')
.prepend(file.preview);
}
if (file.error) {
node
.append('
')
.append($('').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button')
.text('Upload')
.prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#data_protocol_progress .progress-bar').css(
'width',
progress + '%'
).text(progress + '%');
}).on('fileuploaddone', function (e, data) {
$.each(data.result.documents, function (index, file) {
if (file.url) {
var link = $('')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('').text(file.error);
$(data.context.children()[index])
.append('
')
.append(error);
}
getPreviewMediaBlockTemplate(file.id, file.filetype, file.name, 'data_protocol' );
$(".btn-lawatlas-protocol").prop("href", monocle_host + "upload/" + file.id + "/download");
$(".btn-lawatlas-protocol").show();
_makeNewCopy = true;
//refreshFileUploadsDisplay();
//$("#data_protocol_list").append(''+file.name+' ');
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('').text('File upload failed.');
$(data.context.children()[index])
.append('
')
.append(error);
});
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
$('#form_data_data_new').fileupload({
url: url,
formData: {preview: preview_id, email: email, dataset: dataset_id, display: display_id},
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|doc|docx|xsl|xslx|pdf|txt|rtf|dat)$/i,
maxFileSize: 999000,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
data.context = $('').appendTo('#data_data_files');
$.each(data.files, function (index, file) {
var node = $('')
.append($('').text(file.name));
if (!index) {
node
.append('
')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node
.prepend('
')
.prepend(file.preview);
}
if (file.error) {
node
.append('
')
.append($('').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button')
.text('Upload')
.prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#data_data_progress .progress-bar').css(
'width',
progress + '%'
).text(progress + '%');
}).on('fileuploaddone', function (e, data) {
$.each(data.result.documents, function (index, file) {
if (file.url) {
var link = $('')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('').text(file.error);
$(data.context.children()[index])
.append('
')
.append(error);
}
getPreviewMediaBlockTemplate(file.id, file.filetype, file.name, 'data_data' );
$(".btn-lawatlas-data").prop("href", monocle_host + "upload/" + file.id + "/download");
$(".btn-lawatlas-data").show();
_makeNewCopy = true;
//refreshFileUploadsDisplay();
//$("#data_data_list").append(''+file.name+' ');
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('').text('File upload failed.');
$(data.context.children()[index])
.append('
')
.append(error);
});
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
$('#form_final_report_new').fileupload({
url: url,
formData: {preview: preview_id, email: email, dataset: dataset_id, display: display_id},
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|doc|docx|xsl|xslx|pdf|txt|rtf|dat)$/i,
maxFileSize: 999000,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
data.context = $('').appendTo('#final_report_files');
$.each(data.files, function (index, file) {
var node = $('')
.append($('').text(file.name));
if (!index) {
node
.append('
')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node
.prepend('
')
.prepend(file.preview);
}
if (file.error) {
node
.append('
')
.append($('').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button')
.text('Upload')
.prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#final_report_progress .progress-bar').css(
'width',
progress + '%'
).text(progress + '%');
}).on('fileuploaddone', function (e, data) {
$.each(data.result.documents, function (index, file) {
if (file.url) {
var link = $('')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('').text(file.error);
$(data.context.children()[index])
.append('
')
.append(error);
}
getPreviewMediaBlockTemplate(file.id, file.filetype, file.name, 'final_report' );
$(".btn-lawatlas-report").prop("href", monocle_host + "upload/" + file.id + "/download");
$(".btn-lawatlas-report").show();
_makeNewCopy = true;
//refreshFileUploadsDisplay();
//$("#final_report_list").append(''+file.name+' ');
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('').text('File upload failed.');
$(data.context.children()[index])
.append('
')
.append(error);
});
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
$('#form_learn_more_pdf_new').fileupload({
url: url,
formData: {preview: preview_id, email: email, dataset: dataset_id, display: display_id},
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|doc|docx|xsl|xslx|pdf|txt|rtf|dat)$/i,
maxFileSize: 999000,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
data.context = $('').appendTo('#learn_more_files');
$.each(data.files, function (index, file) {
var node = $('')
.append($('').text(file.name));
if (!index) {
node
.append('
')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node
.prepend('
')
.prepend(file.preview);
}
if (file.error) {
node
.append('
')
.append($('').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button')
.text('Upload')
.prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#learn_more_progress .progress-bar').css(
'width',
progress + '%'
).text(progress + '%');
}).on('fileuploaddone', function (e, data) {
$.each(data.result.documents, function (index, file) {
if (file.url) {
var link = $('')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('').text(file.error);
$(data.context.children()[index])
.append('
')
.append(error);
}
getPreviewMediaBlockTemplate(file.id, file.filetype, file.name, 'learn_more' );
_makeNewCopy = true;
//Learn more doesn't exist here yet
//$(".btn-lawatlas-codebook").prop("href", "{host}upload/" + file.id + "/download");
//and .show(), when it exists
//refreshFileUploadsDisplay();
//$("#learn_more_list").append(''+file.name+' ');
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('').text('File upload failed.');
$(data.context.children()[index])
.append('
')
.append(error);
});
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
} else {
alert("whoa, no preview?");
}
});
//files
document.getElementById('file_data').addEventListener('change', function(){
var file = this.files[0];
file_data = file;
// This code is only for demo ...
//console.log("name : " + file.name);
//console.log("size : " + file.size);
//console.log("type : " + file.type);
//console.log("date : " + file.lastModified);
}, false);
document.getElementById('file_codebook').addEventListener('change', function(){
var file = this.files[0];
file_codebook = file;
// This code is only for demo ...
//console.log("name : " + file.name);
//console.log("size : " + file.size);
//console.log("type : " + file.type);
//console.log("date : " + file.lastModified);
}, false);
document.getElementById('file_protocol').addEventListener('change', function(){
var file = this.files[0];
file_protocol = file;
// This code is only for demo ...
//console.log("name : " + file.name);
//console.log("size : " + file.size);
//console.log("type : " + file.type);
//console.log("date : " + file.lastModified);
}, false);
document.getElementById('file_report').addEventListener('change', function(){
var file = this.files[0];
file_report = file;
// This code is only for demo ...
//console.log("name : " + file.name);
//console.log("size : " + file.size);
//console.log("type : " + file.type);
//console.log("date : " + file.lastModified);
}, false);
});
});
function checkEditing(){
in_edit_mode = sessionStorage.getItem('in_edit_mode');
if(in_edit_mode == "true"){
enableEditing();
} else {
disableEditing();
}
//console.log("All toggled and stuff, enabled or disabled, etc...");
$('.site-loading').hide();
}
function enableEditing(){
CKEDITOR.config.customConfig = '/js/ckeditor/ckeditor_config.js';
CKEDITOR.plugins.addExternal( 'imagebrowser', '/js/ckeditor/plugins/imagebrowser/', 'plugin.js' );
CKEDITOR.plugins.addExternal( 'sourcedialog', '/js/ckeditor/plugins/sourcedialog/', 'plugin.js' );
CKEDITOR.stylesSet.add( 'my_styles', [
// Block-level styles.
{ name: 'Crimson Title', element: 'h2', styles: { color: '#971e3a' } },
{ name: 'Warning Title', element: 'h3', styles: { color: '#f4b400' } },
{ name: 'Caution Title', element: 'h3', styles: { color: 'Red' } },
// Inline styles.
{ name: 'Crimson', element: 'span', attributes: { 'class': 'crimson_13'} },
{ name: 'Crimson - Large', element: 'span', attributes: { 'class': 'crimson' } },
{ name: 'Crimson - Small', element: 'span', attributes: { 'class': 'crimson_what'} },
{ name: 'Marker: Yellow', element: 'span', styles: { 'background-color': 'Yellow' } }
]);
// For inline style definition.
CKEDITOR.config.stylesSet = 'my_styles';
// For a definition in an external file.
//CKEDITOR.config.stylesSet = 'my_styles:http://monqcle-cdn.50status.com/js/monqcle_ckeditor_style.js';
/*
CKEDITOR.config.filebrowserBrowseUrl: '/browser';
CKEDITOR.config.filebrowserUploadUrl: '/uploader';
CKEDITOR.config.extraPlugins: 'imagebrowser';
*/
if ( $( "#description" ).length ) {
$("#description").attr("contenteditable", true);
}
if ( $( "#sidebar" ).length ) {
$("#sidebar").attr("contenteditable", true);
}
if ( $( "#curator" ).length ) {
$("#curator").attr("contenteditable", true);
}
if ( $( "#description" ).length ) {
CKEDITOR.inline( 'description' , {
//uiColor: '#9AB8F3',
//removePlugins: 'document, forms, font, colors, tools',
//customConfig: '/js/ckeditor/ckeditor_config.js'
//filebrowserBrowseUrl: '/browser',
//filebrowserUploadUrl: '/uploader',
//extraPlugins: 'imagebrowser',
//imageBrowser_listUrl : "http://mark.monqcle.com/app_dev.php/upload/50status/images?email=" + email
});
CKEDITOR.instances['description'].on('focus', function (event) {
});
}
if ( $( "#sidebar" ).length ) {
CKEDITOR.inline( 'sidebar' );
CKEDITOR.instances['sidebar'].on('focus', function (event) {
});
}
if ( $( "#curator" ).length ) {
CKEDITOR.inline( 'curator' );
CKEDITOR.instances['curator'].on('focus', function (event) {
});
}
$("#saveZPreview").removeClass("hide").removeClass("btn-success").addClass("btn-warning");
$("#is_editor_toolbar").removeClass("hide");
getTopicsDropDown();
//$(".show_on_editor").removeClass("hide");
}
function disableEditing(){
$("#description").removeAttr("contenteditable");
$("#sidebar").removeAttr("contenteditable");
$("#curator").removeAttr("contenteditable");
if( "description" in CKEDITOR.instances){
CKEDITOR.instances['description'].destroy();
}
if( "sidebar" in CKEDITOR.instances){
CKEDITOR.instances['sidebar'].destroy();
}
if( "curator" in CKEDITOR.instances){
CKEDITOR.instances['curator'].destroy();
}
/*
$("#saveZPreview").addClass("hide");
$("#saveZDocuments").addClass("hide");
$("#getZQuestions").addClass("hide");
$("#publishBlock").addClass("hide");
*/
$("#getZTopics").addClass("hide");
$("#is_editor_toolbar").addClass("hide");
//$(".show_on_editor").addClass("hide");
}
function LawAtlasMigrationLevel3(){
you_wanna_migrate = confirm("This will complete the migration to MonQcle. Are you sure?");
if(you_wanna_migrate){
migrated_id = $("#migrated_id").val();
console.log(migrated_id);
url = monocle_host + 'app_dev.php/previewer/' + migrated_id + '/50status/migrate3';
$.when(
$.ajax({
url: url,
//data: params ,
//async: false,
type: "GET",
//dataType: "json"
})
)
.then(function( data, textStatus, jqXHR ) {
//console.log( data ); // Alerts 200
zdata = JSON.parse(data);
console.log(zdata);
if(zdata.success){
console.log("A fab success");
location.reload();
} else {
console.log("A horrid failure");
console.log(zdata.msg);
$(".bad-migration").removeClass("hide");
}
});
}
}
function LawAtlasMigration(level){
if(level == -1){
you_wanna_migrate = false;
} else if(level == 1 || level == 2){
you_wanna_migrate = true;
}
//you_wanna_migrate = confirm("This Dataset topic does not exist in MonQcle. Would you like to migrate this record to the MonQcle?");
if(you_wanna_migrate){
//do migration
display_title = encodeURIComponent($("#display_title").val());
display_id = $("#display_id").val();
dataset = $("#dataset_slug").val();
url = "/dataset_migration?level=" + level + "&display_title=" + display_title + "&display_id=" + display_id + "&dataset=" + dataset;
console.log("migrate at level " + level);
$.when(
$.ajax({
url: url,
//data: params ,
//async: false,
type: "GET",
//dataType: "json"
})
)
.then(function( data, textStatus, jqXHR ) {
//console.log( data ); // Alerts 200
zdata = data; //JSON.parse(data);
console.log(zdata);
if(zdata.success){
if(zdata.conflicting_slug){
alert("found an existing dataset with the same name, so we need to fix some stuff");
location.href = "/datasets/" + zdata.new_dataset_slug;
} else {
console.log("A fab success");
location.reload();
}
} else {
console.log("A horrid failure");
$(".bad-migration").removeClass("hide");
}
});
//set up edit
setTimeout(checkEditing, 1000);
} else {
console.log("do not migrate");
editModeToggle("off");
$("#editModeText").html("Editing disabled ");
$("#editModeWrapper").removeClass("text-primary").removeClass("text-warning").addClass("text-muted");
//console.log("can't edit LawAtlas previews, must use LawAtlas");
$("#editModeWrapper").attr("title", "LawAtlas previews must be editied in LawAtlas");
$("#editModeWrapper").tooltip({placement:"bottom"});
$('.site-loading').hide();
}
}
function saveQuestionsSorted(){
console.log("michief managed");
///{id}/50status/save
title = $("#title_dont_care").html();
console.log("if I was a title");
console.log(title);
//deets
created_by = $("#created_by").html();
maintained_by = $("#maintained_by").html();
valid_from = $("#valid_from").html();
updated_through = $("#updated_through").html();
//taxonomy
taxonomies_selected = [];
$( "#zDataset_taxonomies option:selected" ).each(function() {
//str += $( this ).text() + " ";
taxonomies_selected.push($(this).val());
});
console.log("Selected Taxonomies");
console.log(taxonomies_selected);
//published
if($("#publishZPreview").prop("checked") == true){
published = true;
} else {
published = '';
}
//useZSlider
if($("#useZSlider").prop("checked") == true){
use_slider = true;
start_year = $("#zStartYear").val();
end_year = $("#zEndYear").val();
} else {
use_slider = '';
start_year = '';
end_year = '';
}
//editors
if ( $( "#description" ).length ) {
description = CKEDITOR.instances['description'].getData();
} else {
description = '';
}
if ( $( "#sidebar" ).length ) {
sidebar = CKEDITOR.instances['sidebar'].getData();
} else {
sidebar = '';
}
if ( $( "#curator" ).length ) {
curator = CKEDITOR.instances['curator'].getData();
} else {
curator = '';
}
mydata = {title: title, description: description, sidebar: sidebar, curator: curator,
created_by: created_by, maintained_by: maintained_by, valid_from: valid_from, updated_through: updated_through,
published: published, taxonomies: taxonomies_selected, use_slider: use_slider, start_year: start_year, end_year: end_year};
//preview_id
preview = $("#preview_id").val();
url = monocle_host + 'app_dev.php/previewer/' + preview + '/50status/save';
$.when(
$.ajax({
method: "POST",
url: url,
data: mydata,
})
).done(
function( result ) {
//console.log(result);
updated = JSON.parse(result);
if(updated.success){
$("#saveZQuestionsSorted").removeClass("btn-warning").addClass("btn-success");
//reload
location.reload();
} else {
$("#saveZQuestionsSorted").removeClass("btn-warning").addClass("btn-danger");
}
});
}
function savePreview(is_new){
//console.log("save z preview, before z germans get here...");
//console.log(use_lawatlas_host);
if(_makeNewCopy){
saveQuestionsSorted();
}
if(typeof is_new != 'undefined'){
console.log("Make a new one!");
return false;
}
form_id = $("#form_id").val();
dataset = $("#dataset_id").val();
title = $("#title_dont_care").html();
console.log("if I was a title");
console.log(title);
//deets
created_by = $("#created_by").html();
maintained_by = $("#maintained_by").html();
valid_from = $("#valid_from").html();
updated_through = $("#updated_through").html();
//taxonomy
taxonomies_selected = [];
$( "#zDataset_taxonomies option:selected" ).each(function() {
//str += $( this ).text() + " ";
taxonomies_selected.push($(this).val());
});
console.log("Selected Taxonomies");
console.log(taxonomies_selected);
//published
if($("#publishZPreview").prop("checked") == true){
published = true;
} else {
published = '';
}
//useZSlider
if($("#useZSlider").prop("checked") == true){
use_slider = true;
start_year = $("#zStartYear").val();
end_year = $("#zEndYear").val();
} else {
use_slider = '';
start_year = '';
end_year = '';
}
if ( $( "#description" ).length ) {
description = CKEDITOR.instances['description'].getData();
} else {
description = '';
}
if ( $( "#sidebar" ).length ) {
sidebar = CKEDITOR.instances['sidebar'].getData();
} else {
sidebar = '';
}
if ( $( "#curator" ).length ) {
curator = CKEDITOR.instances['curator'].getData();
} else {
curator = '';
}
url = monocle_host + "app_dev.php/previewer/" + form_id + "/50status/update";
mydata = {dataset: dataset, title: title, description: description, sidebar: sidebar, curator: curator,
created_by: created_by, maintained_by: maintained_by, valid_from: valid_from, updated_through: updated_through,
published: published, taxonomies: taxonomies_selected, use_slider: use_slider, start_year: start_year, end_year: end_year};
//console.log(mydata);
$.when(
$.ajax({
method: "POST",
url: url,
data: mydata,
})
).done(
function( result ) {
//console.log(result);
updated = JSON.parse(result);
if(updated.success){
$("#saveZPreview").removeClass("btn-warning").addClass("btn-success");
} else {
$("#saveZPreview").removeClass("btn-warning").addClass("btn-danger");
}
});
}
function removeQuestion(question){
}
function removePreviewQuestion(id, question, parent)
{
if(confirm("Are you sure you want to remove this questions?")){
url = monocle_host + 'previewer/' + id + '/remove-question/' + question;
$.when(
$.ajax({
method: "POST",
url: url,
data: { parent: parent },
dataType: "json",
}) ).done(
function( removed ) {
console.log("It worked!");
console.log(removed);
_makeNewCopy = true;
saveQuestionsSorted();
//getPermissionUsers($("#dataset_id").val());
//getPermissionGroups($("#dataset_id").val());
});
}
}
function savePreviewDocuments(){
/*
alert("save z preview documents, before z germans get here...");
if(use_lawatlas_host){
console.log(use_lawatlas_host);
}
if(file_data){
console.log(file_data.name);
}
if(file_codebook){
console.log(file_codebook.name);
}
if(file_protocol){
console.log(file_protocol.name);
}
if(file_report){
console.log(file_report.name);
}
console.log(monocle_host);
*/
$("#saveZPreviewDocuments").removeClass("btn-warning").addClass("btn-success");
saveQuestionsSorted();
}
function getPreviewMediaBlockTemplate(id, filetype, filename, referenced){
preview = $("#preview_id").val();
url = monocle_host + 'upload/' + id + '/media-block?filetype=' + filetype + '&filename=' + filename + '&referenced=' + referenced;
// /upload/55c0d7efc30474780e334873/media-block?filetype=something&filename=something&referenced=something
$.when(
$.ajax({
method: "POST",
url: url,
//data: data, // + "&_pill=1", // { _pill: 1 },
//dataType: "json",
}) ).done(
function( mediablock ) {
//console.log(mediablock);
$("#" + referenced + "_list").append('' + mediablock + '');
return mediablock;
});
}
function getPreviewQuestionBlock(id, filetype, filename, referenced){
preview = $("#preview_id").val();
url = monocle_host + 'upload/' + id + '/media-block?filetype=' + filetype + '&filename=' + filename + '&referenced=' + referenced;
// /upload/55c0d7efc30474780e334873/media-block?filetype=something&filename=something&referenced=something
$.when(
$.ajax({
method: "POST",
url: url,
//data: data, // + "&_pill=1", // { _pill: 1 },
//dataType: "json",
}) ).done(
function( mediablock ) {
//console.log(mediablock);
$("#" + referenced + "_list").append('' + mediablock + '');
return mediablock;
});
}
function uploadFile(file){
var url = monocle_host + 'upload/add';
var xhr = new XMLHttpRequest();
var fd = new FormData();
xhr.open("POST", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// Every thing ok, file uploaded
alert(xhr.responseText); // handle response.
}
};
fd.append("upload_file", file);
xhr.send(fd);
}