Commit 430d18fa by Uros Spasojevic

added dialogs

finished grid
yolo
parent 392f9e31
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Ext.define('Evoksi.view.evoksi.EvoksiController', { Ext.define("Evoksi.view.evoksi.EvoksiController", {
extend: 'Ext.app.ViewController', extend: "Ext.app.ViewController",
alias: 'controller.evoksi', alias: "controller.evoksi",
requires: [ requires: [
'Ext.container.Container', "Ext.container.Container",
'Ext.layout.container.Border', "Ext.layout.container.Border",
'Ext.layout.container.Fit', "Ext.layout.container.Fit",
'Ext.ux.GMapPanel', "Ext.ux.GMapPanel",
'Ext.ux.IFrame', "Ext.ux.IFrame",
'Ext.window.Window' "Ext.window.Window"
], ],
config: { config: {
listen: { listen: {
component: { component: {
'evoksi': { evoksi: {
markerClick: function (marker) { markerClick: function(marker) {
var store = this.getView().getViewModel().getStore('myStore'); var store = this.getView()
.getViewModel()
.getStore("myStore");
var first = true; var first = true;
if (marker.performers) { if (marker.performers) {
store.loadData(marker.performers); store.loadData(marker.performers);
}; }
var win = Ext.create('Ext.window.Window', { var win = Ext.create("Ext.window.Window", {
title: marker.title == "" ? "New event" : marker.title, // Marker title title:
marker.title == "" ? "New event" : marker.title, // Marker title
height: 600, height: 600,
width: '70%', width: "70%",
modal: true, modal: true,
layout: 'border', layout: "border",
maximizable: false, maximizable: false,
resizable: false, resizable: false,
cls: 'evoksi-window', cls: "evoksi-window",
items: [{ items: [
xtype: 'gmappanel', {
region: 'west', xtype: "gmappanel",
region: "west",
split: true, split: true,
splitterResize: false, splitterResize: false,
width: 300, width: 300,
...@@ -40,103 +43,194 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -40,103 +43,194 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
lat: marker.lat, // Marker latitude lat: marker.lat, // Marker latitude
lng: marker.lng // Marker longitude lng: marker.lng // Marker longitude
}, },
markers: [{ markers: [
{
lat: marker.lat, lat: marker.lat,
lng: marker.lng, lng: marker.lng,
animation: google.maps.Animation.BOUNCE animation:
}], google.maps.Animation.BOUNCE
}
],
mapOptions: { mapOptions: {
mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeId:
google.maps.MapTypeId.ROADMAP,
zoom: 15 zoom: 15
} }
}, },
{ {
xtype: 'panel', xtype: "panel",
cls: 'evoksi-panel-body', cls: "evoksi-panel-body",
region: 'center', region: "center",
layout: 'vbox', layout: "vbox",
items: [{ items: [
xtype: 'textfield', {
fieldLabel: 'Title', xtype: "textfield",
reference: 'titleField', fieldLabel: "Title",
reference: "titleField",
value: marker.title, value: marker.title,
width: '90%' width: "90%"
}, },
{ {
xtype: 'textarea', xtype: "textarea",
fieldLabel: 'Description', fieldLabel: "Description",
reference: 'descriptionArea', reference: "descriptionArea",
value: marker.description, value: marker.description,
width: '90%' width: "90%"
}, },
{ {
xtype: 'grid', xtype: "grid",
reference: 'myGrid', reference: "myGrid",
title: 'Performers', title: "Performers",
height: 300, height: 300,
width: '90%', width: "90%",
store: store, store: store,
columns: [{ columns: [
text: 'Name', {
dataIndex: 'name' text: "Name",
dataIndex: "name"
}, },
{ {
text: 'Date', text: "Date",
dataIndex: 'date', dataIndex: "date",
flex: 1 flex: 1
}, },
{ {
text: 'Time', text: "Time",
dataIndex: 'time', dataIndex: "time",
flex: 1 flex: 1
}
],
listeners: {
select: function(obj,item,index) {
var record = store.getAt(index);
var popup = Ext.create(
"Ext.panel.Panel",
{
floating: true,
centered: true,
cls: "evoksi-add-performer",
title: "Edit performer",
modal: true,
width: 300,
height: 400,
draggable: false,
maximizable: false,
items: [
{
xtype: "textfield",
fieldLabel: "Name",
reference: "name",
value: record.get("name")
},
{
xtype: "textfield",
fieldLabel: "Date",
reference: "date",
value: record.get("date")
},
{
xtype: "textfield",
fieldLabel: "Time",
reference: "time",
value: record.get("time")
}
],
buttons: [
{
text: "Save",
formBind: true,
listeners: {
click: function() {
record.beginEdit();
record.set("name", popup.items.items[0].value);
record.set("date", popup.items.items[1].value);
record.set("time", popup.items.items[2].value);
record.endEdit();
popup.hide();
}
}
},
{
text: "Cancel",
handler: function() {
popup.hide();
}
},
{
text: "Delete",
handler: function() {
function deleteStuff(btn) {
if (btn == "yes") {
store.removeAt(index);
popup.hide();
}
}
Ext.Msg.show(
{
title: "Delete performer",
msg: "Are you sure?",
buttons:Ext.Msg.YESNO,
icon: Ext.Msg.WARNING,
fn: deleteStuff
}
);
}
} }
] ]
} }
).show();
}
}
}
], ],
buttons: [{ buttons: [
text: 'Add', {
handler: function () { text: "Add",
var popup = Ext.create('Ext.panel.Panel', { handler: function() {
var popup = Ext.create(
"Ext.panel.Panel",
{
floating: true, floating: true,
centered: true, centered: true,
cls: 'evoksi-add-performer', cls: "evoksi-add-performer",
title: 'Add performer', title: "Add performer",
modal: true, modal: true,
width: 300, width: 300,
height: 400, height: 400,
draggable: false, draggable: false,
maximizable: false, maximizable: false,
items: [{ items: [
xtype: 'textfield', {
fieldLabel: 'Name', xtype: "textfield",
reference: 'name' fieldLabel: "Name",
reference: "name"
}, },
{ {
xtype: 'textfield', xtype: "textfield",
fieldLabel: 'Date', fieldLabel: "Date",
reference: 'date' reference: "date"
}, },
{ {
xtype: 'textfield', xtype: "textfield",
fieldLabel: 'Time', fieldLabel: "Time",
reference: 'time' reference: "time"
} }
], ],
buttons: [{ buttons: [
text: 'Save', {
text: "Save",
formBind: true, formBind: true,
listeners: { listeners: {
click: function () { click: function() {
if (first) { if (first) {
store.each(function (item) { store.each(function(item) {
var dat = { var dat = {
name: item.data.name, name: item.data.name,
date: item.data.date, date: item.data.date,
time: item.data.time time: item.data.time
}; };
store.insert(0, dat); store.insert(0,dat);
}); });
first = false; first = false;
} }
...@@ -144,28 +238,29 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -144,28 +238,29 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
name: popup.items.items[0].value, name: popup.items.items[0].value,
date: popup.items.items[1].value, date: popup.items.items[1].value,
time: popup.items.items[2].value time: popup.items.items[2].value
} };
store.insert(0, newPerformer); store.insert(0, newPerformer);
popup.hide(); popup.hide();
} }
} }
}, },
{ {
text: 'Cancel', text: "Cancel",
handler: function () { handler: function() {
popup.hide(); popup.hide();
} }
} }
] ]
}).show(); }
).show();
} }
}, },
{ {
text: 'Update', text: "Update",
handler: function () { handler: function() {
var perf = []; var perf = [];
store.each(function (rec) { store.each(function(rec) {
perf.push(rec.data); perf.push(rec.data);
}); });
...@@ -178,15 +273,15 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -178,15 +273,15 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
animation: google.maps.Animation.DROP animation: google.maps.Animation.DROP
}; };
if ((marker.saved != undefined) && (marker.saved == false)) { if (marker.saved != undefined && marker.saved == false) {
newMarker.access = dbref.ref().child('data').push().key newMarker.access = dbref.ref().child("data").push().key;
} else { } else {
newMarker.access = marker.access; newMarker.access = marker.access;
} }
var updates = {}; var updates = {};
updates['/data/' + newMarker.access] = newMarker; updates["/data/" + newMarker.access] = newMarker;
dbref.ref().update(updates); dbref.ref().update(updates);
...@@ -194,8 +289,10 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -194,8 +289,10 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
} }
}, },
{ {
text: 'Delete', text: "Delete",
handler: function () { handler: function() {
function deleteStuff(btn) {
if (btn == "yes") {
var i = markers.length; var i = markers.length;
var newMarkers = []; var newMarkers = [];
while (i) { while (i) {
...@@ -209,19 +306,29 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -209,19 +306,29 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
markers = newMarkers; markers = newMarkers;
dbref.ref('/data/' + marker.access).remove(); dbref.ref("/data/" + marker.access).remove();
win.close(); win.close();
} }
} }
Ext.Msg.show({
title: "Delete event",
msg: "Are you sure?",
fn: deleteStuff,
buttons: Ext.Msg.YESNO,
icon: Ext.Msg.WARNING
});
}
}
] ]
} }
] ]
}).show(); }).show();
}, },
click: function (evt) { click: function(evt) {
var me = this, var me = this,
map = me.getView(), map = me.getView(),
key = dbref.ref().child('data').push().key, key = dbref.ref().child("data").push().key,
marker = { marker = {
access: key, access: key,
lat: evt.latLng.lat(), lat: evt.latLng.lat(),
...@@ -235,57 +342,66 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -235,57 +342,66 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
markers.push(map.addMarker(marker)); markers.push(map.addMarker(marker));
}, },
mapready: function () { mapready: function() {
var me = this; var me = this;
var map = me.getView(); var map = me.getView();
google.maps.event.addListener(map.gmap, 'click', function (e) { google.maps.event.addListener(
map.fireEvent('click', e); map.gmap,
}); "click",
function(e) {
map.fireEvent("click", e);
}
);
} }
} }
} }
} }
}, },
showLogin: function () { showLogin: function() {
var me = this, var me = this,
map = me.getView(); map = me.getView();
var loginWindow = Ext.create('Ext.panel.Panel', { var loginWindow = Ext.create("Ext.panel.Panel", {
floating: true, floating: true,
centered: true, centered: true,
cls: 'evoksi-view-login', cls: "evoksi-view-login",
title: 'Login', title: "Login",
modal: true, modal: true,
width: 300, width: 300,
height: 400, height: 400,
draggable: false, draggable: false,
maximizable: false, maximizable: false,
items: [{ items: [
xtype: 'textfield', {
fieldLabel: 'Username' xtype: "textfield",
fieldLabel: "Username"
}, },
{ {
xtype: 'textfield', xtype: "textfield",
inputType: 'password', inputType: "password",
fieldLabel: 'Password' fieldLabel: "Password"
} }
], ],
buttons: [{ buttons: [
text: 'Login', {
text: "Login",
formBind: true, formBind: true,
handler: function () { handler: function() {
var username = loginWindow.items.items[0].value; var username = loginWindow.items.items[0].value;
var password = loginWindow.items.items[1].value; var password = loginWindow.items.items[1].value;
if (username == 'admin' && password == 'cpAdmin01') { if (username == "admin" && password == "cpAdmin01") {
Ext.Ajax.request({ Ext.Ajax.request({
url: dataURL, url: dataURL,
scope: this, scope: this,
success: function (data) { success: function(data) {
var info = Ext.decode(data.responseText); var info = Ext.decode(data.responseText);
if (info != null) { if (info != null) {
Ext.Object.each(info, function (obj, index) { Ext.Object.each(info, function(
obj,
index
) {
markers.push(map.addMarker(index)); markers.push(map.addMarker(index));
}); });
} }
...@@ -293,14 +409,20 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -293,14 +409,20 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
}); });
loginWindow.hide(); loginWindow.hide();
} else { } else {
Ext.Msg.show({
title: "Login failed",
msg: "Invalid username or password",
buttons: Ext.Msg.OK,
icon: Ext.Msg.ERROR
});
} }
} }
}] }
]
}).show(); }).show();
}, },
logout: function () { logout: function() {
var i = markers.length; var i = markers.length;
while (i) { while (i) {
i--; i--;
...@@ -311,7 +433,7 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -311,7 +433,7 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
this.showLogin(); this.showLogin();
}, },
init: function () { init: function() {
var me = this, var me = this,
map = me.getView(); map = me.getView();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment