2012-09-12 10:36:43 -04:00
|
|
|
/**
|
|
|
|
* Extends kis-js to allow centering of absolutely-positioned containers
|
|
|
|
*/
|
|
|
|
$_.ext('center', function (sel){
|
|
|
|
sel = this.el;
|
|
|
|
|
|
|
|
if (typeof sel === "undefined") return;
|
|
|
|
|
|
|
|
var contHeight,
|
|
|
|
contWidth,
|
|
|
|
inH,
|
|
|
|
inW,
|
|
|
|
top,
|
|
|
|
left;
|
|
|
|
|
2012-09-13 19:16:51 -04:00
|
|
|
contHeight = sel.offsetHeight;
|
|
|
|
contWidth = sel.offsetWidth;
|
2012-09-12 10:36:43 -04:00
|
|
|
|
2012-09-13 19:16:51 -04:00
|
|
|
inH = window.innerHeight;
|
|
|
|
inW = window.innerWidth;
|
2012-09-12 10:36:43 -04:00
|
|
|
|
|
|
|
sel.style.position = "fixed";
|
|
|
|
top = (inH - contHeight) / 2;
|
2012-09-13 19:16:51 -04:00
|
|
|
left = (inW - contWidth) / 2;
|
2012-09-12 10:36:43 -04:00
|
|
|
|
2012-09-13 19:16:51 -04:00
|
|
|
sel.style.top = top + "px";
|
2012-09-12 10:36:43 -04:00
|
|
|
sel.style.left = left + "px";
|
|
|
|
});
|
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
(function(w, $_) {
|
2012-06-13 13:49:10 -04:00
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
"use strict";
|
2012-06-13 13:49:10 -04:00
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
var TINY = w.TINY || {};
|
|
|
|
var $_ = w.$_ || {};
|
|
|
|
|
|
|
|
var parent_map = {
|
|
|
|
"data":"section",
|
|
|
|
"section":"category",
|
|
|
|
"category":"genre",
|
|
|
|
"genre":"genre"
|
|
|
|
};
|
2012-09-12 10:36:43 -04:00
|
|
|
|
2012-09-10 11:45:39 -04:00
|
|
|
// ! Show/hide forms based on use
|
2012-08-31 16:18:23 -04:00
|
|
|
$_("fieldset dl").dom.hide();
|
|
|
|
$_("fieldset legend").event.add('click', function(e){
|
2015-06-04 14:30:42 -04:00
|
|
|
($_("fieldset dl").dom.css('display').trim() == 'none')
|
|
|
|
? $_("fieldset dl").dom.show()
|
|
|
|
: $_("fieldset dl").dom.hide();
|
2012-08-31 16:18:23 -04:00
|
|
|
});
|
2012-06-13 13:49:10 -04:00
|
|
|
|
2012-09-10 11:45:39 -04:00
|
|
|
var meta = {};
|
2015-06-04 14:30:42 -04:00
|
|
|
w.meta = meta;
|
2015-06-04 16:25:47 -04:00
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
/**
|
|
|
|
* Create the WYSIWYG editor box
|
|
|
|
*/
|
|
|
|
meta.initTINY = function(id) {
|
|
|
|
// WYSIWYG
|
|
|
|
new TINY.editor.edit('edit_wysiwyg',
|
|
|
|
{
|
|
|
|
id:id,
|
|
|
|
width:450,
|
|
|
|
height:175,
|
|
|
|
cssclass:'te',
|
|
|
|
controlclass:'tecontrol',
|
|
|
|
rowclass:'teheader',
|
|
|
|
dividerclass:'tedivider',
|
|
|
|
controls:['bold','italic','underline','strikethrough','|','subscript','superscript','|',
|
|
|
|
'orderedlist','unorderedlist','|','leftalign',
|
|
|
|
'centeralign','rightalign','blockjustify','|','unformat','n','undo','redo','|',
|
|
|
|
'image','hr','link','unlink','|'],
|
|
|
|
footer:true,
|
|
|
|
fonts:['Verdana','Arial','Georgia','Trebuchet MS'],
|
|
|
|
xhtml:true,
|
|
|
|
cssfile:ASSET_URL+'css.php/g/css',
|
|
|
|
bodyid:'editor',
|
|
|
|
footerclass:'tefooter',
|
|
|
|
toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'},
|
|
|
|
resize:{cssclass:'resize'}
|
|
|
|
});
|
|
|
|
},
|
2012-09-12 10:36:43 -04:00
|
|
|
|
2012-09-10 11:45:39 -04:00
|
|
|
/**
|
|
|
|
* Deletes a genre/category/section/data item
|
|
|
|
* based on the current page context
|
|
|
|
*/
|
|
|
|
meta.delete_item = function(e) {
|
2015-06-04 14:30:42 -04:00
|
|
|
var id, type, parent_id;
|
2012-09-12 10:36:43 -04:00
|
|
|
|
2012-09-10 11:45:39 -04:00
|
|
|
// Get the type/id of the item
|
2015-06-04 14:30:42 -04:00
|
|
|
id = this.parentNode.dataset['id'];
|
|
|
|
type = this.parentNode.dataset.type;
|
|
|
|
parent_id = this.parentNode.dataset.parent;
|
2012-09-10 11:45:39 -04:00
|
|
|
|
|
|
|
// Confirm deletion
|
|
|
|
var confirm_string = "Are you sure you want to delete this "+type+"? Deleting this item will delete all items under it. There is no undo.";
|
|
|
|
|
|
|
|
var do_delete = confirm(confirm_string);
|
|
|
|
|
2012-09-12 10:36:43 -04:00
|
|
|
var status = false;
|
2012-09-10 11:45:39 -04:00
|
|
|
|
2012-09-12 10:36:43 -04:00
|
|
|
if (do_delete)
|
|
|
|
{
|
2015-06-04 14:30:42 -04:00
|
|
|
$_.post(APP_URL+'delete', {'id':id, 'type':type}, function(res){
|
|
|
|
if (res == 1)
|
|
|
|
{
|
|
|
|
// Redirect to previous page
|
|
|
|
var redir_url = APP_URL+parent_map[type]+'/detail/'+parent_id;
|
|
|
|
w.location = (type !== 'genre')
|
|
|
|
? redir_url
|
|
|
|
: APP_URL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$_.get(APP_URL+'message', {
|
|
|
|
type: 'error',
|
|
|
|
message: 'There was an error deleting that item'
|
|
|
|
}, function(h) {
|
|
|
|
$_('body').dom.prepend(h);
|
2012-09-13 11:07:31 -04:00
|
|
|
});
|
2015-06-04 14:30:42 -04:00
|
|
|
}
|
|
|
|
});
|
2012-09-12 10:36:43 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the edit form and displays the overlay for the item
|
|
|
|
* being edited
|
|
|
|
*/
|
|
|
|
meta.get_edit_form = function(e) {
|
2015-06-04 14:30:42 -04:00
|
|
|
var id, type;
|
2012-09-12 10:36:43 -04:00
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
id = this.parentNode.dataset['id'];
|
|
|
|
type = this.parentNode.dataset.type;
|
2012-09-12 10:36:43 -04:00
|
|
|
|
|
|
|
$_('#overlay_bg, #overlay').dom.show();
|
|
|
|
|
|
|
|
//Get the form for the current item
|
|
|
|
$_.get(APP_URL+'edit', {'id':id, 'type':type}, function(res){
|
|
|
|
$_('#overlay').dom.html(res);
|
|
|
|
|
|
|
|
// Center the form
|
|
|
|
$_('#overlay').center();
|
2012-09-12 12:57:41 -04:00
|
|
|
|
|
|
|
if (type == 'data')
|
|
|
|
{
|
2015-06-04 14:30:42 -04:00
|
|
|
meta.initTINY('val');
|
2012-09-13 19:16:51 -04:00
|
|
|
|
|
|
|
//Do it again, so it's correct this time!
|
|
|
|
$_('#overlay').center();
|
2012-09-12 12:57:41 -04:00
|
|
|
}
|
2012-09-12 10:36:43 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit the update form via javascript
|
|
|
|
*/
|
|
|
|
meta.update_item = function(e) {
|
|
|
|
var id, type, name, val, txt, data={};
|
|
|
|
|
2012-09-12 12:57:41 -04:00
|
|
|
// Update textarea from WYSIWYG
|
|
|
|
if (window.edit_wysiwyg)
|
|
|
|
{
|
|
|
|
window.edit_wysiwyg.toggle();
|
|
|
|
}
|
2012-09-12 10:36:43 -04:00
|
|
|
|
|
|
|
// Get the form values
|
|
|
|
data.id = $_.$('#id').value;
|
|
|
|
data.type = $_.$('#type').value;
|
|
|
|
data.name = $_.$('#name').value;
|
|
|
|
txt = document.getElementById('val');
|
|
|
|
if (txt)
|
|
|
|
{
|
|
|
|
data.val = txt.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submit the form
|
|
|
|
$_.post(APP_URL+'update', data, function(res) {
|
|
|
|
|
|
|
|
// Hide the overlay and form
|
|
|
|
$_('#overlay_bg').dom.css('display', '');
|
|
|
|
$_('#overlay').dom.html('');
|
|
|
|
$_('#overlay').dom.hide();
|
|
|
|
|
|
|
|
// Show the appropriate status message
|
|
|
|
if (res == 1)
|
|
|
|
{
|
2012-09-12 12:57:41 -04:00
|
|
|
// Reload the page
|
2015-06-04 14:30:42 -04:00
|
|
|
w.location = w.location;
|
2012-09-12 10:36:43 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$_.get(APP_URL+'message', {
|
|
|
|
type: 'error',
|
|
|
|
message: 'There was an error updating that item.'
|
|
|
|
}, function(h) {
|
|
|
|
$_('body').dom.prepend(h);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2012-09-10 11:45:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------
|
|
|
|
// ! Event binding
|
|
|
|
// -------------------------------------------------
|
|
|
|
|
|
|
|
// Delete Button functionality
|
|
|
|
$_("button.delete").event.add('click', meta.delete_item);
|
|
|
|
|
2012-09-12 10:36:43 -04:00
|
|
|
// Edit Button functionality
|
|
|
|
$_("button.edit").event.add('click', meta.get_edit_form);
|
|
|
|
|
|
|
|
// Overlay close
|
|
|
|
$_("#overlay_bg").event.add('click', function(e) {
|
2015-06-04 14:30:42 -04:00
|
|
|
$_('#overlay_bg').dom.css('display', 'none');
|
2012-09-12 10:36:43 -04:00
|
|
|
$_('#overlay').dom.html('');
|
|
|
|
$_('#overlay').dom.hide();
|
2012-09-10 11:45:39 -04:00
|
|
|
});
|
|
|
|
|
2012-09-12 10:36:43 -04:00
|
|
|
// Edit form submission
|
|
|
|
$_.event.live('#edit_form', 'submit', meta.update_item);
|
2015-06-04 16:25:47 -04:00
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
// WYSIWYG on section/data pages
|
2015-06-04 16:25:47 -04:00
|
|
|
if (document.getElementsByTagName('textarea') != null)
|
2015-06-04 14:30:42 -04:00
|
|
|
{
|
2015-06-04 16:25:47 -04:00
|
|
|
meta.initTINY('val');
|
2015-06-04 14:30:42 -04:00
|
|
|
}
|
|
|
|
}(window, $_));
|