CatalystX-CRUD-YUI
view release on metacpan or search on metacpan
lib/CatalystX/CRUD/YUI/TT/static/js/crud.js view on Meta::CPAN
YAHOO.util.Event.on(cancelButton, 'click',
function(e) { Dom.get(formId).innerHTML = '' });
//Logger("set Cancel button");
}
newForm.onsubmit = function(e) {
//Logger("form submitted");
//Logger(e);
YAHOO.util.Event.stopEvent(e); // so submit_form() isn't called
// TODO call validate_form() here explicitly
return false;
};
//Logger("set form");
var respHandler = {
success: function(o) {
// clear the selection so that the form is not re-loaded
tab.grid.panel.getSelectionModel().clearSelections();
// reload the grid
tab.grid.panel.store.reload();
// delete the form
Dom.get(formId).innerHTML = '';
//Logger('submit OK');
},
failure: function(o) {
//YAHOO.crud.handleXHRFailure(o);
alert("Error! Check that the value is not already set for this record.");
}
};
// hijack the save button so we don't actually leave this page.
YAHOO.util.Event.on(saveButton, 'click', function(e) {
var uri = newForm.action + '?cxc-fmt=json';
//alert("uri = " + uri);
// make the form submit without leaving the page
var ret = YAHOO.util.Connect.setForm(newForm);
//Logger(ret);
YAHOO.util.Connect.asyncRequest('POST', uri, respHandler);
});
}
else {
alert("unknown server error");
}
},
failure: function(o) {
YAHOO.crud.handleXHRFailure(o);
}
}
);
}
Ext.namespace('Ext.ux'); // livegrid js requires
if (typeof USE_LIVEGRID_FILTERS != 'undefined') {
// grid filter icons
Ext.menu.RangeMenu.prototype.icons = {
gt: 'img/greater_then.png',
lt: 'img/less_then.png',
eq: 'img/equals.png'
};
Ext.grid.filter.StringFilter.prototype.icon = 'img/find.png';
}
/* extend the CheckboxSelectionModel to determine if the click action
was on the checkbox or elsewhere in the row
*/
YAHOO.crud.livegrid_selection_model = Ext.extend(Ext.grid.CheckboxSelectionModel, {
initEvents : function(){
this.grid.on("cellmousedown", this.handleMouseDown, this);
this.grid.getGridEl().on(Ext.isIE || Ext.isSafari3 ? "keydown" : "keypress", this.handleKeyDown, this);
},
checkBoxClicked : false,
handleMouseDown : function(g, row, cell, e){
if(e.button !== 0 || this.isLocked()){
return;
};
this.select(row,cell);
e.stopEvent();
},
select : function(row,cell) {
//Logger("select row, cell");
//Logger(row, cell);
if (cell === 0) {
this.checkBoxClicked = true;
}
else {
this.checkBoxClicked = false;
}
//Logger(this.checkBoxClicked);
if (this.isSelected(row)){
this.deselectRow(row);
}
else {
this.selectRow(row, true);
}
},
handleKeyDown : function(e){
if(!e.isNavKeyPress()){
return;
}
var g = this.grid, s = this.selection;
if(!s){
e.stopEvent();
var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
if(cell){
this.select(cell[0], cell[1]);
}
return;
}
var sm = this;
var walk = function(row, col, step){
lib/CatalystX/CRUD/YUI/TT/static/js/crud.js view on Meta::CPAN
//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');
}
//alert("textarea: " + myEditor.get('textarea').value );
( run in 1.212 second using v1.01-cache-2.11-cpan-39bf76dae61 )