diff --git a/controllers/route.go b/controllers/route.go index 46c73b97..c8138cd0 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -1,6 +1,7 @@ package controllers import ( + "fmt" "html/template" "log" "net/http" @@ -30,7 +31,8 @@ func CreateAdminRouter() http.Handler { router.HandleFunc("/logout", Use(Logout, mid.RequireLogin)) router.HandleFunc("/register", Register) router.HandleFunc("/settings", Use(Settings, mid.RequireLogin)) - router.HandleFunc("/preview", Use(Preview, mid.RequireLogin)) + router.HandleFunc("/html/preview", Use(Preview, mid.RequireLogin)) + router.HandleFunc("/html/clone", Use(Clone, mid.RequireLogin)) // Create the API routes api := router.PathPrefix("/api").Subrouter() api = api.StrictSlash(true) @@ -236,7 +238,19 @@ func Preview(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { http.Error(w, "Method not allowed", http.StatusBadRequest) } - getTemplate(w, "dashboard").ExecuteTemplate(w, "base", struct{}{}) + fmt.Fprintf(w, "%s", r.FormValue("html")) +} + +// Clone takes a URL as a POST parameter and returns the site HTML +func Clone(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + if r.Method != "POST" { + http.Error(w, "Method not allowed", http.StatusBadRequest) + } + if url, ok := vars["url"]; ok { + Logger.Println(url) + } + http.Error(w, "No URL given.", http.StatusBadRequest) } func getTemplate(w http.ResponseWriter, tmpl string) *template.Template { diff --git a/static/js/app/controllers.js b/static/js/app/controllers.js index d1bdf052..1e05040a 100644 --- a/static/js/app/controllers.js +++ b/static/js/app/controllers.js @@ -785,6 +785,7 @@ var LandingPageModalCtrl = function($scope, $modalInstance) { $modalInstance.dismiss('') $scope.savePage(page) }; + $scope.csrf_token = csrf_token }; app.controller('SettingsCtrl', function($scope, $http, $window) { diff --git a/static/js/app/partials/landing_pages.html b/static/js/app/partials/landing_pages.html index 099a09e6..8d78e8c1 100644 --- a/static/js/app/partials/landing_pages.html +++ b/static/js/app/partials/landing_pages.html @@ -51,10 +51,10 @@ Toggle Dropdown
diff --git a/static/js/app/partials/modals/landingPageModal.html b/static/js/app/partials/modals/landingPageModal.html index 66fd2ed6..d854a9ef 100644 --- a/static/js/app/partials/modals/landingPageModal.html +++ b/static/js/app/partials/modals/landingPageModal.html @@ -5,6 +5,7 @@