function init_file_dropzone(parameter_name) {
Dropzone.options.myGreatDropzone = { // camelized version of the `id`
paramName: parameter_name, // The name that will be used to transfer the file
maxFilesize: 6 }; // MB
}
// init_file_dropzone("staffpicupload")
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// VISUAL EFFECTS
//
function fade_message() {
var a_dom = document.querySelector('#alert');
TinyAnimate.animateCSS(a_dom, 'opacity', '', 1.0, 0.0, 750, 'easeInOutQuart', function() {
});
}
function alert_message(msg,color='yellow') {
var a = $('#alert')
a.text(msg)
a.css('background-color',color)
var a_dom = document.querySelector('#alert');
TinyAnimate.animateCSS(a_dom, 'opacity', '', 0.0, 1.0, 500, 'easeInOutQuart', function() {
setTimeout( fade_message, 2500 )
});
//a.css('visibility','visible')
}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// FORM COMPONENTS
//
// TODO these should know if they're modifying the current user or someone else.
// A single text style question
const TQuestion = Vue.component('field', {
props: [ 'table', 'qid', 'question', 'answer', 'placeholder', 'targetid', ],
data: function () {
return { "a":this.answer } },
watch: {
"answer": function(val,Oldval) { this.a = val },
"a": function (val, oldVal) {
this.$root.events.trigger('changed',[this.qid,this.table, val, this.targetid]) }, },
template: `
`,
})
// A single INLINE text style question
const TIQuestion = Vue.component('ifield', {
props: [ 'table', 'qid', 'question', 'answer', 'placeholder', 'myclass', 'targetid', ],
data: function () {
return { "a":this.answer } },
watch: {
"answer": function(val,Oldval) { this.a = val },
"a": function (val, oldVal) {
this.$root.events.trigger('changed',[this.qid,this.table, val, this.targetid]) }, },
template: ``,
})
// A single checkbox
const Checkbox = Vue.component('checkbox', {
props: [ 'table', 'qid', 'question', 'answer', 'targetid', ],
data: function () {
return { "a":this.answer } },
watch: {
"answer": function(val,Oldval) { this.a = val },
"a": function (val, oldVal) {
var newVal = 0
if (val==true) { newVal = 1 }
this.$root.events.trigger('changed',[this.qid,this.table, newVal, this.targetid]) }, },
template: `
`
})
// A single long format text question
const TAQuestion = Vue.component('tfield', {
props: [ 'table', 'qid', 'question', 'answer', 'targetid', ],
data: function () {
return { "a": this.answer } },
watch: {
"a": function (val, oldVal) {
this.$root.events.trigger('changed',[this.qid,this.table, val, this.targetid]) },
"answer": function (val, oldVal) { this.a = val },
},
template: `
` })
// Select menu
const SelMenu = Vue.component('selectmenu', {
props: [ 'table', 'qid', 'question', 'answer', 'menu', 'labelfield', 'targetid', ],
data: function () {
return { "a": this.answer } },
watch: {
"a": function (val, oldVal) {
this.$root.events.trigger('changed',[this.qid,this.table, val, this.targetid]) },
"answer": function (val, oldVal) { this.a = val },
},
template: `` })
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// ONE LINE OF THE STAFF DIR LISTING
//
const StaffLine = Vue.component('staff_line', {
props: [ 's', 'i' ],
//data: function() { return { } },
methods: {
nope: function() { return 1; },
odd: function(i) { if (i % 2 ==0) { return "even" } return "odd" },
bio: function() { return "bio.php?p=" + this.s.id },
gtitle: function() { if (this.s.gtitle) {return _.findWhere(this.$root.titles_menu, {id:this.s.gtitle}).name}; return "" },
gdept1: function() { if (this.s.dept1) {return _.findWhere(this.$root.depts_menu, {id:this.s.dept1}).name}; return "" },
grole: function() { if (this.s.role) {return _.findWhere(this.$root.roles_menu, {id:this.s.role}).descr}; return "" },
swapedit: function() { console.log("edit " + this.s.first_name + " " + this.s.last_name)
this.$emit('swapout', this.s.id) }
},
template: `
{{s.first_name}} {{s.last_name}}
{{s.department}}
{{s.email}}
{{s.phone_number}}
{{s.room}}
edit
{{gtitle()}}
{{gdept1()}}
{{grole()}}
Published: YesNo
personnel_ext: YesNo
c_users: YesNo
`
});
//
//
// STAFF DIR LISTING
//
// ONE LINE - BUT EDITING!
//
const StaffLineEdit = Vue.component('staff_line_edit', {
props: [ 's', 'i' ],
//data: function() { return { } },
methods: {
nope: function() { return 1; },
odd: function(i) { if (i % 2 ==0) { return "even" } return "odd" },
bio: function() { return "bio.php?p=" + this.s.id },
done: function() { this.$emit('done_edit') },
}, //v-lazy-container="{ selector: 'img' }"
template: `
`
});
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// STAFF DIR LISTING MAIN CONTAINER
//
const DirList = Vue.component('dirlist', {
data: function () {
return { "personnel":[], sortby:'last_name', search:'', reversed: false,
components: {n:StaffLine, e: StaffLineEdit }, editing: -1, } },
mounted: function() {
var self = this;
this.$root.fetch_menus();
fetch('dir_api.php?a=list', { method: 'GET' }).then(function (response) {
// The API call was successful!
if (response.ok) {
response.json().then( function(r2) {
self.personnel = r2;
_.each( self.personnel, function(x) {
if (x.dir_photo_path==null) { x.dir_photo_path='images_sm/nobody.jpg' }
x.searchable = x.first_name.toLowerCase() + ' ' + x.last_name.toLowerCase()
if (x.department) { x.searchable += ' ' + x.department.toLowerCase() }
} )
//if (self.user.use_dir_photo == "0") { self.user.use_dir_photo = false }
//if (self.user.general_photo_release == "0") { self.user.general_photo_release = false }
// pause half a second for the children to get populated before registering update events...
setTimeout(function() {
//self.active = true;
// fancier text editors...
//pell.init( { element: document.getElementById('bio2'), onChange: function(h) { console.log(h) } } )
}, 1600);
} )
} else { return Promise.reject(response) }
}).then(function (data) {
}).catch(function (err) { console.warn('Something went wrong.', err); });
},
methods: {
setsort: function(ss) {
if (this.sortby == ss) { this.reversed = ! this.reversed }
else {
this.reversed = false
this.sortby = ss
}
},
swapme: function(x) {
this.editing = x
},
done_edit: function(id) {
this.editing = -1
},
am_editing: function(id) {
if (id == this.editing) { return StaffLineEdit }
return StaffLine
},
},
computed: {
filtered: function() {
var ff = this.personnel
var self = this
if (this.search) {
var ss = self.search.toLowerCase()
ff = ff.filter(function(x) { return x.searchable.includes(ss) }) }
ff = _.sortBy(ff, function(x) {
if (x[self.sortby]) {
var s = x[self.sortby];
return s.trim().toLowerCase() }
return '' })
if (this.reversed) {
ff.reverse()
}
return ff
}
},
watch: {
},
template: `` })
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// ACTIVITIES LIST MAIN CONTAINER
//
const ActivityList = Vue.component('activitylist', {
data: function () {
return { activities:[], sortby:'title', reversed:false, editing: -1, } },
mounted: function() {
var self = this;
this.$root.fetch_menus();
fetch('dir_api.php?a=get/sessions', { method: 'GET' }).then(function (response) {
// The API call was successful!
if (response.ok) {
response.json().then( function(r2) {
self.activities = r2;
_.each( self.activities, function(x) {
x.searchable = x.title.toLowerCase() + ' ' + x.desc.toLowerCase()
//if (x.department) { x.searchable += ' ' + x.department.toLowerCase() }
} )
//if (self.user.use_dir_photo == "0") { self.user.use_dir_photo = false }
//if (self.user.general_photo_release == "0") { self.user.general_photo_release = false }
// pause half a second for the children to get populated before registering update events...
setTimeout(function() {
//self.active = true;
// fancier text editors...
//pell.init( { element: document.getElementById('bio2'), onChange: function(h) { console.log(h) } } )
}, 1600);
} )
} else { return Promise.reject(response) }
}).then(function (data) {
}).catch(function (err) { console.warn('Something went wrong.', err); });
},
methods: {
setsort: function(ss) {
if (this.sortby == ss) { this.reversed = ! this.reversed }
else {
this.reversed = false
this.sortby = ss
}
},
swapme: function(x) {
this.editing = x
},
done_edit: function(id) {
this.editing = -1
},
am_editing: function(id) {
return 0;
},
},
computed: {
filtered: function() {
var ff = this.activities
var self = this
if (this.search) {
var ss = self.search.toLowerCase()
ff = ff.filter(function(x) { return x.searchable.includes(ss) }) }
ff = _.sortBy(ff, function(x) {
if (x[self.sortby]) {
var s = x[self.sortby];
return s.trim().toLowerCase() }
return '' })
if (this.reversed) {
ff.reverse()
}
return ff
}
},
watch: {
},
template: `` })
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// VERY SIMPLE CALENDAR
//
const MyCal = Vue.component('mycal', {
data: function () {
return { today:new Date(), currentMonth:0, currentYear:0, selectYear:'', selectMonth:'',
months:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
activities:[],
by_date: {},
editing: -1, } },
mounted: function() {
var self = this
this.currentYear = this.today.getFullYear()
this.currentMonth = this.today.getMonth()
this.selectYear = this.currentYear
this.selectMonth = this.currentMonth
fetch('dir_api.php?a=get/sessions', { method: 'GET' }).then(function (response) {
if (response.ok) {
response.json().then( function(r2) {
self.activities = r2
_.each( self.activities, function(x) {
var dd = new Date(x.starttime);
var [m,d,y] = [dd.getMonth(), dd.getDate(), dd.getFullYear()] // months start at 0....
var d_string = d + "-" + m + "-" + y
if (self.by_date[d_string]) { self.by_date[d_string].push(x) }
else { self.by_date[d_string] = [x, ] } } )
self.$forceUpdate()
} )
} else { return Promise.reject(response) }
}).then(function (data) {
}).catch(function (err) { console.warn('Something went wrong.', err); });
},
methods: {
thisDay: function(i,j) {
var dayOfMonth = ((7*(i-1))+j)-this.firstDay()
return dayOfMonth
},
eventsThisDay: function(i,j) {
var dayOfMonth = ((7*(i-1))+j)-this.firstDay()
var d_string = dayOfMonth + "-" + this.selectMonth + "-" + this.selectYear
var day_text = ''
if (this.by_date[d_string]) {
evts = _.filter( this.by_date[d_string], function(x) { console.log(x); return x.typeId!="101" } )
console.log(evts)
return evts
}
return []
},
cleanTime: function(e) {
var dd = new Date(e.starttime);
var [h,m] = [dd.getHours(), dd.getMinutes()]
var ampm = 'am'
if (h > 12) { h -= 12; ampm = 'pm' }
if (m == 0) { m = '' }
else { m = ':' + m }
return h + m + ampm
},
daysInMonth: function() {
return 32 - new Date(this.selectYear, this.selectMonth, 32).getDate()
},
firstDay: function() {
return (new Date(this.selectYear, this.selectMonth)).getDay()
},
next: function() {
this.selectYear = (this.selectYear === 11) ? this.selectYear + 1 : this.selectYear;
this.selectMonth = (this.selectMonth + 1) % 12;
},
previous: function() {
this.selectYear = (this.selectYear === 0) ? this.selectYear - 1 : this.selectYear;
this.selectMonth = (this.selectMonth === 0) ? 11 : this.selectMonth - 1;
},
},
computed: {
},
watch: {
},
template: `
{{months[selectMonth] + " " + selectYear}}
| Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
|
{{ thisDay(i,j) }}
{{cleanTime(ev)}} {{ ev.title }}
|
` })
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// AJAX POST UPDATES TO API
//
function post_update(table,cols,vals,id=0) {
action = "nothing"
if (table=="personnel") { action = "update" }
if (table=="personnel_ext") { action = "update_xt" }
if (table=="webpages") { action = "update_web" }
var idstr = ""
if (id) { idstr = "&id=" + id }
console.log("a="+action+"&cols="+cols+"&vals="+vals+idstr)
fetch('dir_api.php', {
method: 'POST',
headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }),
body: "a="+action+"&cols="+cols+"&vals="+vals+idstr,
}).then(function (response) {
// The API call was successful!
if (response.ok) {
response.json().then( function(r2) {
// display success alert
alert_message('Saved.')
} )
} else { return Promise.reject(response) }
}).then(function (data) {
}).catch(function (err) { alert_message("Couldn't save!",pink); console.warn('Something went wrong.', err); });
}
var evt = {
clear_tables: function() {
var self = this
_.each( this.tables, function(x) { self[x] = [] } )
this.data = {}
this.target_ids = {} },
send_update: function() {
var self = this
//console.log("Sending update... (not really)")
_.each( this.tables, function(x) {
if (self[x].length) {
var cols = ""
var vals = ""
_.each(self[x], function(y) {
if (cols.length) { cols += "," }
if (vals.length) { vals += "," }
cols += y
if (typeof self.data[y] == "string") {
re = /,/g
vals += encodeURIComponent(self.data[y].replace(re,'[CMA]') ) }
else { vals += self.data[y] }
})
//console.log("table: " + x + " Columns: " + cols + ".. Vals: " + vals)
var edit_other = 0
if (self.target_ids[x]) { edit_other = self.target_ids[x] }
post_update(x, cols, vals, edit_other)
}
} ) },
info: "what am I?" ,
data: {},
target_ids: {},
tables: ['personnel','personnel_ext','webpages','welcomepages','conf_sessions','conf_hosts',
'pers_departments','pers_committees','pers_titles'],
}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// INITIALIZE THE APP
//
evt.clear_tables()
MicroEvent.mixin(evt);
var app = new Vue({
el: '#dir_editor',
data: { events: evt,
msg: 'hello', active: false,
user: {'last_name':'', 'first_name':'', 'department':'', 'extension':'', 'phone_number':'', 'email':'',
'staff_type':'', 'room':'', 'status':'', 'user_id':'', 'password':'', 'time_created':'', 'time_updated':'',
'id':'', 'web_on':'', use_dir_photo:0, general_photo_release:0,
officehours:'', title:'', picture:'', education:'', bio:'', courses:'', personal_page:'', changed:'' },
filter: [],
roles_menu: [],
depts_menu: [],
titles_menu: [],
committees_menu: [],
menus_fetched: false,
},
watch: { },
methods: {
fetch_menus: function() {
if (! this.menus_fetched) {
var self = this;
fetch('dir_api.php?a=menus', { method: 'GET' }).then(function (response) {
// The API call was successful!
if (response.ok) {
response.json().then( function(r2) {
self.depts_menu = r2.departments;
self.roles_menu = r2.roles;
self.titles_menu = r2.titles;
self.committees_menu = r2.committees;
self.menus_fetched = true;
} )
} else { return Promise.reject(response) }
}).then(function (data) {
}).catch(function (err) { console.warn('Something went wrong.', err); });
}
},
},
computed: { },
mounted: function() {
var self = this;
fetch('dir_api.php', { method: 'GET' }).then(function (response) {
// The API call was successful!
if (response.ok) {
response.json().then( function(r2) {
self.user = r2;
if (self.user.use_dir_photo == "0") { self.user.use_dir_photo = false }
if (self.user.general_photo_release == "0") { self.user.general_photo_release = false }
// pause half a second for the children to get populated before registering update events...
setTimeout(function() {
self.active = true;
// fancier text editors...
//pell.init( { element: document.getElementById('bio2'), onChange: function(h) { console.log(h) } } )
}, 1600);
} )
} else { return Promise.reject(response) }
}).then(function (data) {
}).catch(function (err) { console.warn('Something went wrong.', err); });
}
})
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
//
// SIMPLE EVENTS
//
var update_fxn = _.debounce( function() {
alert_message('saving...','lightgreen')
evt.send_update(); evt.clear_tables(); }, 1300 )
evt.bind('changed', function(dat) {
if (app.active) {
var column = dat[0]
var table = dat[1]
var value = dat[2]
var target = dat[3]
console.log(dat)
this.data[column] = value
if (!this[table].includes(column) ) {this[table].push(column)}
if (target) { this.target_ids[table] = target }
update_fxn() }
});
//
//
// MISC
//
//
//
//
// v-lazy-container="{ selector: 'img' }"
//