[★] 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 static/%.html: source/%.haml
haml --unix-newlines --no-escape-attrs --double-quote-attributes $< > $@ haml --unix-newlines --no-escape-attrs --double-quote-attributes $< > $@
@ -9,4 +17,6 @@ static/%.js: source/%.coffee
clean: clean:
rm static/*.html static/*.js rm static/*.html static/*.js
watch:
while inotifywait $(SOURCES); do clear ; make all ; done

25
main.hy
View File

@ -26,9 +26,30 @@
(send-from-directory "static" "index.html"))) (send-from-directory "static" "index.html")))
(with-decorator (with-decorator
(.route app "/oh/hours/<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) (print start)
(jsonify { start: start })) (jsonify { "start" start })))
;(with-decorator ;(with-decorator
; (.route app "/") ; (.route app "/")

View File

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

View File

@ -3,7 +3,8 @@
%head %head
%title Appointment Calendar %title Appointment Calendar
%link{:href => "/static/officehours.css", :rel => "stylesheet", :type => "text/css"} %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 %body
.container .container

View File

@ -10,13 +10,13 @@ define [
diff = d.getDate() - day + (if day == 0 then -6 else 1) diff = d.getDate() - day + (if day == 0 then -6 else 1)
new Date d.setDate diff new Date d.setDate diff
class Officehours class OfficeHours extends Backbone.Model
start: null, start: null,
url: -> 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) @start = monday(new Date)
# This is going to go with the Google idea of a view and overlays: # 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 Appointments extends Backbone.View
class OfficeHours extends Backbone.View class OfficeHoursView extends Backbone.View
class DayView extends Backbone.View class DayView extends Backbone.View
class CalendarView extends Backbone.View class CalendarView extends Backbone.View
className 'calendar' className: 'calendar'
events:
events
'click .forward': "nextWeek" 'click .forward': "nextWeek"
'click .backward': "lastWeek" 'click .backward': "lastWeek"
initialize: (options) -> initialize: (options) ->
-> ->
officehours = new OfficeHours officehours = new OfficeHours()
$.when(officehours.fetch()).then(console.log(officehours.get('start'))) $.when(officehours.fetch()).then(console.log(officehours))