[★] Serving up the require.js stuff properly, now getting transactions.

This commit is contained in:
Elf M. Sternberg 2016-02-13 13:37:45 -08:00
parent 1c89e0bc2d
commit 07ae886569
5 changed files with 50 additions and 17 deletions

View File

@ -1,4 +1,12 @@
all: static/index.html static/index.js static/officehours.js
SOURCES = source/*.coffee source/*.haml main.hy
all: static/index.html static/index.js static/officehours.js main.py
# Needed because Flask's "debugger" setting doesn't grok
# Hy directly. Nuisance!
main.py:
hy2py main.hy > main.py
static/%.html: source/%.haml
haml --unix-newlines --no-escape-attrs --double-quote-attributes $< > $@
@ -9,4 +17,6 @@ static/%.js: source/%.coffee
clean:
rm static/*.html static/*.js
watch:
while inotifywait $(SOURCES); do clear ; make all ; done

27
main.hy
View File

@ -26,9 +26,30 @@
(send-from-directory "static" "index.html")))
(with-decorator
(.route app "/oh/hours/<start:start>")
(print start)
(jsonify { start: start }))
(.route app "/index.js")
(defn index []
(send-from-directory "static" "index.js")))
(with-decorator
(.route app "/officehours.js")
(defn officehours []
(send-from-directory "static" "officehours.js")))
(with-decorator
(.route app "/lib/<path:path>")
(defn lib [path]
(send-from-directory "static/lib" path)))
(with-decorator
(.route app "/oh/hours/<path:start>")
(defn defhours [start]
(jsonify { "start" start })))
(with-decorator
(.route app "/oh/hours/<path:start>")
(defn hours [start]
(print start)
(jsonify { "start" start })))
;(with-decorator
; (.route app "/")

View File

@ -4,9 +4,12 @@ require.config
'jquery': './lib/jquery.min'
'backbone': './lib/backbone-min'
'json2': './lib/json2'
'domReady': './lib/domReady'
shim:
json2:
exports: 'JSON'
'backbone': ['json2']
require ['backbone', 'json2'], () ->
require ['officehours'], (start) ->
$(start)
require ['officehours', 'domReady'], (start, ready) ->
ready(start)

View File

@ -3,7 +3,8 @@
%head
%title Appointment Calendar
%link{:href => "/static/officehours.css", :rel => "stylesheet", :type => "text/css"}
%script{:src => "static/officehours.js"}
%script{:src => "static/lib/require.js"}
%script{:src => "static/index.js"}
%body
.container

View File

@ -10,13 +10,13 @@ define [
diff = d.getDate() - day + (if day == 0 then -6 else 1)
new Date d.setDate diff
class Officehours
class OfficeHours extends Backbone.Model
start: null,
url: ->
if start isintanceof Date then "/oh/hours/#{urlEncode start}" else "/oh/hours/"
if @start instanceof Date then "/oh/hours/#{encodeURIComponent @start}" else "/oh/hours/"
initialize:
initialize: (model, option) ->
@start = monday(new Date)
# This is going to go with the Google idea of a view and overlays:
@ -25,22 +25,20 @@ define [
class Appointments extends Backbone.View
class OfficeHours extends Backbone.View
class OfficeHoursView extends Backbone.View
class DayView extends Backbone.View
class CalendarView extends Backbone.View
className 'calendar'
className: 'calendar'
events
events:
'click .forward': "nextWeek"
'click .backward': "lastWeek"
initialize: (options) ->
->
officehours = new OfficeHours
$.when(officehours.fetch()).then(console.log(officehours.get('start')))
officehours = new OfficeHours()
$.when(officehours.fetch()).then(console.log(officehours))