Last active
December 20, 2015 18:59
-
-
Save cityzen/6180317 to your computer and use it in GitHub Desktop.
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
$('textarea').wysihtml5(); | |
$('.datepicker').datepicker(); | |
$.extend( $.fn.dataTableExt.oStdClasses, { | |
"sWrapper": "dataTables_wrapper form-inline" | |
} ); | |
$('#list-table').dataTable( { | |
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>" | |
} ); | |
$('.js_var_inline_edit').editable({ | |
type: 'text', | |
ajaxOptions: { | |
type: 'put' | |
}, | |
success: function(response, newValue) { | |
$('.var-' + $(this).data('pk')).editable('setValue', newValue); | |
} | |
}); | |
$('.js_title_inline_edit').editable({ | |
type: 'text', | |
ajaxOptions: { | |
type: 'put' | |
}, | |
success: function(response, newValue) { | |
$('.doc-' + $(this).data('pk')).editable('setValue', 'pleasework'); | |
} | |
}); | |
$('.cssSwitch').click(function (){ | |
var currentId = $(this).attr('id'); | |
// alert('/inc/css/app/doc/' + currentId + '.css'); | |
$('#cssSwitcher').attr('href','/inc/css/app/doc/' + currentId + '.css'); | |
}); | |
$('#enable').click(function() { | |
$('.editable').editable('toggleDisabled'); | |
}); | |
$(function() { | |
// $('#proposal_date').datepicker() | |
var snippet_buttons = '<div class="btn-group"><a class="btn delete-snippet" href="#"><i class="icon-remove"></i></a><a class="btn moveUp" href="#"><i class="icon-arrow-up"></i></a><a class="btn moveDown" href="#"><i class="icon-arrow-down"></i></a><a class="btn edit" data-toggle="modal" href="#myModal"><i class="icon-pencil"></i></a></div>'; | |
$( "#canvas" ).sortable({ | |
stop: function(){ | |
var ids = []; | |
$('.tempWrapper').each(function(){ | |
ids.push(this.id); | |
}); | |
var layoutIDs = ids.toString(); | |
$('input.layout').val(layoutIDs); | |
}, | |
axis: 'y', | |
cursorAt: { left: 5 } | |
}); | |
$(".moveUp").on('click', function() | |
{ | |
var row = $(this).parents('.tempWrapper:first'); | |
row.insertBefore(row.prev()); | |
}); | |
$(".moveDown").on('click', function() | |
{ | |
var row = $(this).parents('.tempWrapper:first'); | |
row.insertAfter(row.next()); | |
}); | |
$( "#canvas" ).disableSelection(); | |
/* | |
$('#redactor_content').redactor({ | |
focus: true, | |
// buttons: ['html', '|', 'formatting', '|', 'bold', 'italic'], | |
}); | |
*/ | |
$(".draggable").draggable(); | |
$('#snippet-picker').change(function() | |
{ | |
var snippet_val = $(this).val(); | |
$('#prop_instruction').remove(); | |
$.getJSON('/documents/json/' + snippet_val, function(data) | |
{ | |
if($('#intro').val() == 1) | |
{ | |
$('#canvas').append('<div class="tempWrapper" id="' + snippet_val + '"><h3>' + data['title'] + '</h3>' + data['snippet'] + '<br /><a href="#" class="delete-snippet">Delete ' + $('#snippet-picker').val() + '</a> <a href="#" class="moveUp">move up</a> <a href="#" class="moveDown">move down</a><hr></div>'); | |
} | |
else | |
{ | |
$('#canvas').append('<div class="tempWrapper" id="' + snippet_val + '">' + data['snippet'] + '<br /><a href="#" class="delete-snippet">Delete ' + $('#snippet-picker').val() + '</a> <a href="#" class="moveUp">move up</a> <a href="#" class="moveDown">move down</a><hr></div>'); | |
} | |
$('#prop_snippets').append('<li><a href="#' + snippet_val + '">' + data['title'] + '</a></li>'); | |
}); | |
var ids = []; | |
ids.push(snippet_val); | |
$('.tempWrapper').each(function(){ | |
ids.push(this.id); | |
}); | |
if(ids.length == 1) | |
{ | |
$('#prop_save').fadeIn('slow'); | |
} | |
var layoutIDs = ids.reverse().toString(); | |
$('input.layout').val(layoutIDs); | |
$("#snippet-picker option:selected").remove(); | |
$("html, body").animate({ scrollTop: $(document).height() }, "slow"); | |
return false; | |
}); | |
$('.delete-snippet').on('click', function() | |
{ | |
$(this).parents('.tempWrapper').fadeOut(500, function() { $(this).parents('.tempWrapper').remove(); }); | |
var ids = []; | |
$('.tempWrapper').each(function(){ | |
ids.push(this.id); | |
}); | |
var layoutIDs = ids.toString(); | |
$('input.layout').val(layoutIDs); | |
}); | |
$('.edit').on('click', function() | |
{ | |
entry_id = $(this).parents('.tempWrapper').attr('id'); | |
$.getJSON('/admin/get/' + $('#field').val() + '/' + entry_id, function(data) | |
{ | |
field_id = $('#field').val(); | |
$('input.modal_edit_title').val(data['title']); | |
$('#redactor_content').setCode(data['snippet']); | |
$('input.modal_edit_id').val(entry_id); | |
$('input.modal_edit_field').val(field_id); | |
}); | |
}); | |
$('.edit_save').on('click', function() | |
{ | |
$('#myModal').modal('hide'); | |
title = $('input.modal_edit_title').val(), | |
snippet = $('textarea.modal_edit_snippet').val(); | |
entry_id = $('input.modal_edit_id').val(); | |
field_id = $('input.modal_edit_field').val(); | |
action = $('#snippet_update').attr('action'); | |
$.post(action, {title: title, entry_id: entry_id, snippet: snippet, field_id: field_id}, | |
function(data) | |
{ | |
$.getJSON('/admin/get/' + field_id + '/' + entry_id + '/1', function(data) | |
{ | |
$('#' + entry_id).html('<h2>' + data['title'] + '</h2>' + data['snippet'] + '<br />' + snippet_buttons); | |
}); | |
$('input.modal_edit_title').val(''), | |
$('textarea.modal_edit_snippet').val(''); | |
$('input.modal_edit_id').val(''); | |
$('input.modal_edit_field').val(''); | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment