Date.patterns = {
ISO8601Long:"Y-m-d H:i:s",
ISO8601Short:"Y-m-d",
ShortDate: "n/j/Y",
LongDate: "l, F d, Y",
FullDateTime: "l, F d, Y g:i:s A",
MonthDay: "F d",
ShortTime: "g:i A",
LongTime: "g:i:s A",
SortableDateTime: "Y-m-d\\TH:i:s",
UniversalSortableDateTime: "Y-m-d H:i:sO",
YearMonth: "F, Y"
};
/*SHADOWS DISABLE*/
Ext.form.ComboBox.prototype.shadow = false;
Ext.Panel.prototype.shadow = false;
Ext.menu.Menu.prototype.shadow = false;
/* PRINT METHOD */
Ext.override(Ext.Element, {
/**
* @cfg {string} printCSS The file path of a CSS file for printout.
*/
printCSS: '/ext/app/window.print.css'
/**
* @cfg {Boolean} printStyle Copy the style attribute of this element to the print iframe.
*/
,printStyle: false
/**
* @property {string} printTitle Page Title for printout.
*/
,printTitle: document.title
/**
* Prints this element.
*
* @param config {object} (optional)
*/
,print: function(config) {
Ext.apply(this, config);
//console.log(this.id+'-data');
var el = Ext.get(this.id+'-data').dom;
var c = document.getElementById('printcontainer');
var iFrame = document.getElementById('printframe');
var strTemplate = '
{0}{1}
{4}
';
var strLinkTpl = '';
var strAttr = '';
var strFormat;
var strHTML;
//Get rid of the old crap so we don't copy it
//to our iframe
if (iFrame != null) {c.removeChild(iFrame)};
if (c != null) {el.removeChild(c)};
//Copy attributes from this element.
for (var i = 0; i < el.attributes.length; i++) {
if (Ext.isEmpty(el.attributes[i].value) || el.attributes[i].value.toLowerCase() != 'null') {
strFormat = Ext.isEmpty(el.attributes[i].value)? '{0}="true" ': '{0}="{1}" ';
if (this.printStyle? this.printStyle: el.attributes[i].name.toLowerCase() != 'style')
strAttr += String.format(strFormat, el.attributes[i].name, el.attributes[i].value);
}
}
var strLink ='';
if(this.printCSS){
if(!Ext.isArray(this.printCSS))
this.printCSS = [this.printCSS];
for(var i=0; i',
'
{value}
',
''
);
/* UPLOAD */
Ext.form.FileUploadField = Ext.extend(Ext.form.TextField, {
/**
* @cfg {String} buttonText The button text to display on the upload button (defaults to
* 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
* value will be used instead if available.
*/
buttonText: 'Browse...',
/**
* @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
* text field (defaults to false). If true, all inherited TextField members will still be available.
*/
buttonOnly: false,
/**
* @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
* (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
*/
buttonOffset: 3,
/**
* @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
*/
// private
readOnly: true,
/**
* @hide
* @method autoSize
*/
autoSize: Ext.emptyFn,
// private
initComponent: function(){
Ext.form.FileUploadField.superclass.initComponent.call(this);
this.addEvents(
/**
* @event fileselected
* Fires when the underlying file input field's value has changed from the user
* selecting a new file from the system file selection dialog.
* @param {Ext.form.FileUploadField} this
* @param {String} value The file value returned by the underlying file input field
*/
'fileselected'
);
},
// private
onRender : function(ct, position){
Ext.form.FileUploadField.superclass.onRender.call(this, ct, position);
this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
this.el.addClass('x-form-file-text');
this.el.dom.removeAttribute('name');
this.fileInput = this.wrap.createChild({
id: this.getFileInputId(),
name: this.name||this.getId(),
cls: 'x-form-file',
tag: 'input',
type: 'file',
size: 1
});
var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
text: this.buttonText
});
this.button = new Ext.Button(Ext.apply(btnCfg, {
renderTo: this.wrap,
cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
}));
if(this.buttonOnly){
this.el.hide();
this.wrap.setWidth(this.button.getEl().getWidth());
}
this.fileInput.on('change', function(){
var v = this.fileInput.dom.value;
this.setValue(v);
this.fireEvent('fileselected', this, v);
}, this);
},
// private
getFileInputId: function(){
return this.id+'-file';
},
// private
onResize : function(w, h){
Ext.form.FileUploadField.superclass.onResize.call(this, w, h);
this.wrap.setWidth(w);
if(!this.buttonOnly){
var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
this.el.setWidth(w);
}
},
// private
preFocus : Ext.emptyFn,
// private
getResizeEl : function(){
return this.wrap;
},
// private
getPositionEl : function(){
return this.wrap;
},
// private
alignErrorIcon : function(){
this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
}
});
Ext.reg('fileuploadfield', Ext.form.FileUploadField);
/* NEW NAMESPACES */
Ext.ns('App', 'App.vw', 'App.ds', 'App.fn');
App.ds.reservations = new Ext.data.JsonStore({
totalProperty:'total'
,root:'result'
,url:'/user/reservations'
,remoteSort: true
,fields:[
{name:'RESERVATION_ID'}
,{name:'DATE_', type:'date', dateFormat:'d-M-y'}
,{name:'ARRIVAL', type:'date', dateFormat:'d-M-y'}
,{name:'DEPARTURE', type:'date', dateFormat:'d-M-y'}
,{name:'SHORTNAME'}
,{name:'FIRSTNAME'}
,{name:'LASTNAME'}
,{name:'EMAIL'}
,{name:'PHONE'}
,{name:'ADULTS'}
,{name:'CHILDREN'}
,{name:'ROOM'}
,{name:'NIGHTS'}
,{name:'PACKET'}
,{name:'SUM'}
,{name:'STATUS'}
,{name:'COMMENT_'}
,{name:'datetime', type:'date', dateFormat:'Y-m-d H:i:s'}
]
});
App.GridAgencyReservations = Ext.extend(Ext.grid.GridPanel, {
initComponent:function() {
Ext.apply(this, {
store:App.ds.reservations
,view:App.vw.reservations
,autoExpandColumn:'grid-reservations-sum'
,sm: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: {
rowselect: function(sm, row, rec) {
//if (Ext.getCmp('window-reservations-form')) Ext.getCmp('window-reservations-form').close();
//win_reservation_edit();
}
}
})
,columns:[{
id:'id'
,header:"ID"
,sortable:false
,dataIndex:'RESERVATION_ID'
,width: 75
,hidden:false
},{
header:"Statusas"
,sortable:true
,dataIndex:'STATUS'
,width: 65
,renderer:App.fn.format_company_reservation_status
},{
header:"Sukūr. data"
,sortable:true
,renderer:Ext.util.Format.dateRenderer('Y-m-d')
,dataIndex:'DATE_'
,width: 65
},{
header:"Atvyksta"
,sortable:true
,renderer:Ext.util.Format.dateRenderer('Y-m-d')
,dataIndex:'ARRIVAL'
,width: 65
},{
header:"Atvyksta"
,sortable:true
,renderer:Ext.util.Format.dateRenderer('Y-m-d')
,dataIndex:'DEPARTURE'
,width: 65
,hidden:true
},{
header:"Nakv."
,sortable:true
,dataIndex:'NIGHTS'
,width: 41
},{
header:"Suaug."
,sortable:true
,width:41
,dataIndex:'ADULTS'
},{
header:"Vaik."
,sortable:true
,width:41
,dataIndex:'CHILDREN'
},{
header:"Kamb."
,sortable:true
,width:45
,dataIndex:'ROOM'
},{
header:"Paslauga"
,sortable:true
,width:55
,dataIndex:'PACKET'
}/*,{
header:"Suma"
,sortable:true
,width: 80
,dataIndex:'SUM'
,renderer:App.fn.format_currency
}*/,{
header:"Email"
,sortable:true
,width:55
,dataIndex:'EMAIL'
,hidden:true
},{
header:"Phone"
,sortable:true
,width:55
,dataIndex:'PHONE'
,hidden:true
},{
header:"Vardas"
,sortable:true
,dataIndex:'SHORTNAME'
,id:'grid-reservations-sum'
}]
/*
,plugins:[new Ext.ux.grid.Search({
iconCls:'icon-zoom'
,searchText:'Paieška'
,checkIndexes:['RESERVATION_ID','SHORTNAME','EMAIL']
,disableIndexes:['STATUS','ARRIVAL','DEPARTURE','NIGHTS','ADULTS','CHILDREN','ROOM','PACKET','PHONE']
,minChars:2
,autoFocus:true
}) ]
*/
,tbar:[
/*{
text:'Sukurti naują'
,tooltip:'Sukurti naują rezervaciją'
,iconCls:'x-icon-add'
,handler:function() {
if (Ext.getCmp('window-reservations-form')) Ext.getCmp('window-reservations-form').close();
App.fn.win_reservation_add();
}
},' ',*/{
text:'Peržiūrėti'
,tooltip:'Peržiūrėti rezervaciją'
,iconCls:'x-icon-information'
,handler:function() {
if (Ext.getCmp('window-agency-reservations-form')) Ext.getCmp('window-agency-reservations-form').close();
App.fn.win_agency_reservation_view();
}
},' ',{
text:'Anuliuoti'
,tooltip:'Anuliuoti'
,iconCls:'x-icon-cancel'
,handler:function() {
if (Ext.getCmp('window-agency-reservations-form')) Ext.getCmp('window-agency-reservations-form').close();
Ext.MessageBox.confirm('ISPĖJIMAS','Ar tikrai norite anuliuoti šią rezervaciją?', do_request);
function do_request (btn) {
if (btn != 'yes') return;
var data = Ext.getCmp('grid-agency-reservations').getSelectionModel().getSelected().data;
var encoded_array = Ext.encode(data);
//console.log(data);
Ext.Ajax.request({
waitMsg: 'Prašome palaukti',
url: '/user/cancelreservation',
params: {id: data.RESERVATION_ID},
success: function(response){
if (response) {
obj = Ext.util.JSON.decode(response.responseText);
if (obj.errors) reason=obj.errors.reason;
else reason='Klaida';
if (obj.success) {
new Ext.ux.Notification({
iconCls: 'x-icon-information',
title: 'Veiksmas atliktas',
html: reason,
autoDestroy: true,
hideDelay: 10000
}).show(document);
}
else {
new Ext.ux.Notification({
iconCls: 'x-icon-error',
title: 'Klaida',
html: reason,
autoDestroy: true,
hideDelay: 10000
}).show(document);
}
if (obj.reload) {
Ext.getCmp('grid-agency-reservations').store.reload();
}
} else reason='Klaida';
}
,failure: function(a,b) {
if (b) {
if (b.result) {
if (b.result.errors) {
if (b.result.errors.reason) reason=b.result.errors.reason;
else reason='Klaida nenurodyta.';
} else reason='Klaida #3.';
} else reason='Klaida #2.';
} else reason='Klaida #1.';
new Ext.ux.Notification({
iconCls: 'x-icon-error',
title: 'Klaida',
html: reason,
autoDestroy: true,
hideDelay: 10000
}).show(document);
}
});
}
}
},' '
]
}); // eo apply
this.bbar = new Ext.PagingToolbar({
store:this.store
,displayInfo:true
,pageSize:20
,beforePageText : 'Puslapis'
,afterPageText : 'iš {0}'
,displayMsg: 'Rezervacijos {0} - {1} iš {2}'
,emptyMsg: "Irašų nerasta"
});
App.GridAgencyReservations.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
App.GridAgencyReservations.superclass.onRender.apply(this, arguments);
this.store.load({params:{start:0, limit:20}});
this.on('rowdblclick', function(n) {
if (Ext.getCmp('window-agency-reservations-form')) Ext.getCmp('window-agency-reservations-form').close();
App.fn.win_agency_reservation_view();
});
}
});
Ext.reg('grid-agencyreservations', App.GridAgencyReservations);
App.FormAgencyReservation = Ext.extend(Ext.form.FormPanel, {
layout :'column',
border :false,
initComponent:function() {
Ext.apply(this, {
defaults:{
layout :'form'
,labelWidth :80
,hideLabels :true
,border :false
,bodyStyle :'padding:4px'
}
,items:[{ // columns
columnWidth:0.5
,defaults:{xtype:'fieldset', layout:'form', anchor:'100%', autoHeight:true}
,items:
[{
defaultType:'textfield',
border: false,
defaults:{anchor:'0'},
items:[{
fieldLabel:'ID'
,name:'RESERVATION_ID'
},{
fieldLabel:'Sukurta'
,name:'DATE_'
,xtype:'datefield'
,format: 'Y-m-d'
},{
fieldLabel:'Paslauga'
,name:'PACKET'
},{
fieldLabel:'Kambarys'
,name:'ROOM'
},{
fieldLabel:'Nakvynių'
,name:'NIGHTS'
},{
fieldLabel:'Atvykimas'
,name:'ARRIVAL'
,xtype:'datefield'
,format: 'Y-m-d'
},{
fieldLabel:'Išvykimas'
,name:'DEPARTURE'
,xtype:'datefield'
,format: 'Y-m-d'
},{
fieldLabel:'Suaugusių'
,name:'ADULTS'
},{
fieldLabel:'Vaikų'
,name:'CHILDREN'
},{
fieldLabel:'Statusas'
,name:'STATUS'
}
]
}]
},{
// these are applied to fieldsets
columnWidth:0.5
,labelWidth:80
,defaults:{xtype:'fieldset', layout:'form', anchor:'100%', autoHeight:true}
// fieldsets
,items:[{
defaultType:'textfield',
border: false,
// these are applied to fields
defaults:{anchor:'0', allowBlank:true},
items:[{
fieldLabel:'Vardas'
,name:'FIRSTNAME'
},{
fieldLabel:'Pavardė'
,name:'LASTNAME'
},{
fieldLabel:'Email'
,name:'EMAIL'
},{
fieldLabel:'Telefonas'
,name:'phone'
},{
fieldLabel:'Komentaras'
,name:'COMMENT_'
,xtype:'textarea'
}
]
}]
}]
}); // eo apply
App.FormAgencyReservation.superclass.initComponent.apply(this, arguments);
}
})
Ext.reg('form-agencyreservation', App.FormAgencyReservation);
App.fn.win_agency_reservation_view = function () {
if (Ext.getCmp('window-agency-reservations-form')) Ext.getCmp('window-agency-reservations-form').close();
var rec = Ext.getCmp('grid-agency-reservations').getSelectionModel().getSelected();
if (!rec) {
new Ext.ux.Notification({
iconCls: 'x-icon-error',
title: 'Klaida',
html: 'Pasirinkite norimą įrašą',
autoDestroy: true,
hideDelay: 5000
}).show(document);
return;
}
var win;
win = new Ext.Window({
layout :'fit',
width :600,
height :400,
closeAction :'close',
plain :false,
modal :true,
buttonAlign :'left',
title :'Rezervacija',
id:'window-agency-reservations-form',
items :[{
xtype:'form-agencyreservation',
id:'form-agencyreservation-1'
}],
buttons: [{
text: 'Uždaryti'
,iconCls:'x-icon-cancel'
,handler : function(){
win.close();
}
}]
});
win.on('show', function() {
this.loadMask = new Ext.LoadMask(this.body, {
msg:'Kraunama. Prašome palaukti.'
});
var rec = Ext.getCmp('grid-agency-reservations').getSelectionModel().getSelected();
Ext.getCmp("form-agencyreservation-1").getForm().loadRecord(rec);
});
win.show();
}
App.fn.format_company_reservation_status = function (val) {
if (val==0) val = '-';
else if (val==1) val = 'Rezervuota';
else if (val==2) val = 'Atvyko';
else if (val==3) val = 'Neatvyko';
else if (val==4) val = 'Anuliuota';
else if (val==5) val = 'Išvykes';
return val;
}
App.fn.format_currency = function (val) {
val = number_format(val,2,'.',',') + ' Lt';
return val;
}
function number_format( number, decimals, dec_point, thousands_sep ) {
// http://kevin.vanzonneveld.net
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfix by: Michael White (http://getsprink.com)
// + bugfix by: Benjamin Lupton
// + bugfix by: Allan Jensen (http://www.winternet.no)
// + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + bugfix by: Howard Yeend
// + revised by: Luke Smith (http://lucassmith.name)
// + bugfix by: Diogo Resende
// + bugfix by: Rival
// % note 1: For 1000.55 result with precision 1 in FF/Opera is 1,000.5, but in IE is 1,000.6
// * example 1: number_format(1234.56);
// * returns 1: '1,235'
// * example 2: number_format(1234.56, 2, ',', ' ');
// * returns 2: '1 234,56'
// * example 3: number_format(1234.5678, 2, '.', '');
// * returns 3: '1234.57'
// * example 4: number_format(67, 2, ',', '.');
// * returns 4: '67,00'
// * example 5: number_format(1000);
// * returns 5: '1,000'
// * example 6: number_format(67.311, 2);
// * returns 6: '67.31'
var n = number, prec = decimals;
n = !isFinite(+n) ? 0 : +n;
prec = !isFinite(+prec) ? 0 : Math.abs(prec);
var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
var abs = Math.abs(n).toFixed(prec);
var _, i;
if (abs >= 1000) {
_ = abs.split(/\D/);
i = _[0].length % 3 || 3;
_[0] = s.slice(0,i + (n < 0)) +
_[0].slice(i).replace(/(\d{3})/g, sep+'$1');
s = _.join(dec);
} else {
s = s.replace('.', dec);
}
return s;
}