CatalystX-CRUD-YUI
view release on metacpan or search on metacpan
lib/CatalystX/CRUD/YUI/TT/static/js/crud.js view on Meta::CPAN
// TODO reload grid, but need to wait till after all rows are removed?
grid.store.reload();
}
}
YAHOO.crud.handle_related_livegrid_click = function(args) {
if (!args.rec) {
Logger('no row passed on click');
return;
}
//Logger(args);
if (args.sm.checkBoxClicked == true) {
return;
}
else {
//var tab = YAHOO.crud.TABS[args.index];
//Logger(tab);
//Logger(args);
var uri = args.url + args.rec.id + '/' + args.action;
if (args.action == 'livegrid_edit_form') {
// if de-selecting the row, erase the form
if (!args.sm.isSelected(args.rec)) {
var formId = 'livegrid' + args.index + '-form';
YAHOO.util.Dom.get(formId).innerHTML = '';
return;
}
YAHOO.crud.livegrid_form({'index':args.index,'form':uri});
}
else {
window.location = uri;
}
}
}
YAHOO.crud.redirect_location = function(args) {
var pk_vals = [];
for(var i=0; i<args.pk_fields.length; i++) {
pk_vals[i] = args.r.get(args.pk_fields[i]);
}
var pk = pk_vals.join(';;');
var newurl = args.url + pk + '/' + args.action;
//Logger(newurl);
window.location = newurl;
}
YAHOO.crud.toggle_link = function(id_to_toggle, link_id) {
YAHOO.crud.toggle_class_hidden(id_to_toggle);
YAHOO.crud.toggle_class_hidden(link_id);
return false; // so the click is not followed on a href
}
YAHOO.crud.datetime_picker = function(id) {
YAHOO.crud.make_calendar_popup(id, true);
}
YAHOO.crud.date_picker = function(id) {
YAHOO.crud.make_calendar_popup(id);
}
YAHOO.crud.make_calendar_popup = function(id, set_time) {
var Dom = YAHOO.util.Dom;
// Create an Overlay instance to house the Calendar instance
var oCalendarMenu = new YAHOO.widget.Overlay("calendar_for_" + id, { zIndex: 99 });
/*
Create an empty body element for the Overlay instance in order
to reserve space to render the Calendar instance into.
*/
oCalendarMenu.setBody(" ");
oCalendarMenu.body.id = "calendarcontainer_" + id;
// Render the Overlay instance into the Button's parent element
oCalendarMenu.render(Dom.get(id + "_calendar_container"));
// Align the Overlay
oCalendarMenu.align();
/*
Create a Calendar instance and render it into the body
element of the Overlay.
*/
var oCalendar = new YAHOO.widget.Calendar(
"buttoncalendar_" + id,
oCalendarMenu.body.id,
{
close: true
});
oCalendar.render();
/*
we have a close button but we want to hide the Overlay,
not the calendar
*/
oCalendar.beforeHideEvent.subscribe(function() {
oCalendarMenu.hide();
return false; // prevent calendar from being hidden
});
/*
Subscribe to the Calendar instance's "changePage" event to
keep the Overlay visible when either the previous or next page
controls are clicked.
*/
oCalendar.changePageEvent.subscribe(function () {
window.setTimeout(function () {
oCalendarMenu.show();
}, 0);
});
/*
Subscribe to the Calendar instance's "select" event to
update the form field when the user
selects a date.
*/
oCalendar.selectEvent.subscribe(function (p_sType, p_aArgs) {
var aDate;
if (p_aArgs) {
YAHOO.crud.log(p_aArgs);
aDate = p_aArgs[0][0];
if (aDate[1] < 10)
aDate[1] = '0' + aDate[1];
if (aDate[2] < 10)
aDate[2] = '0' + aDate[2];
Dom.get(id).value = aDate.join('-');
if (set_time) {
Dom.get(id).value += ' 00:00:00';
}
}
// hide calendar once date selected
oCalendarMenu.hide();
});
}
// based on
// http://developer.yahoo.com/yui/examples/editor/switch_editor_clean.html
// similar to CatalystX::CMS
YAHOO.crud.wysiwygify = function( textareaId, textareaTitle ) {
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event;
// make a button and stick it above the textarea field
Logger('Create Button Control (#toggleEditor) ' + textareaId + ' ' + textareaTitle);
var toggleButton = document.createElement('button');
toggleButton.setAttribute('id', textareaId + '-toggle');
toggleButton.innerHTML = 'Toggle Editor';
var myTextarea = Dom.get( textareaId );
myTextarea.parentNode.insertBefore(toggleButton, myTextarea);
var _button = new YAHOO.widget.Button(toggleButton);
_button.addClass('toggleEditor');
var myConfig = {
height: '300px',
width: '600px',
animate: true,
dompath: true
};
var stripHTML = /<\S[^><]*>/g;
var state = 'on';
Logger('Set state to on..');
Logger('Create the Editor..');
var myEditor = new YAHOO.widget.Editor(textareaId, myConfig);
myEditor.on('toolbarLoaded', function() {
this.toolbar._titlebar.innerHTML = ''; // no titlebar
}, myEditor, true);
myEditor.render();
// make sure the 'save' button writes changes to textarea
YAHOO.crud.onFormSubmit.push(
function() {
myEditor.saveHTML(); // save gui content in screen to object
var editorText = myEditor.get('textarea').value;
var textareaText = Dom.get(textareaId).value;
//alert(textareaId + " textarea: " + editorText);
if (editorText != textareaText) {
alert("editor text mismatch: " + editorText + ' <> ' + textareaText);
}
//myEditor.saveHTML(); // do this first above.
if (editorText.length) {
myEditor.get('textarea').value = editorText.replace(/<br>/gi, '\n');
}
( run in 2.597 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )