From 03b25f5fee26efceb8ae4e5139f41e9ef0e91bb8 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 12 Jun 2015 18:22:17 -0500 Subject: [PATCH] Cleaning up a bit of controllers.js #12 Working on site clone and email import --- controllers/api.go | 68 +- controllers/route.go | 3 +- static/js/app/controllers.js | 85 ++- .../app/partials/modals/landingPageModal.html | 13 +- .../app/partials/modals/siteCloneModal.html | 19 + static/js/ckeditor/CHANGES.md | 720 ++++++++++++++++++ static/js/ckeditor/README.md | 39 + static/js/ckeditor/build-config.js | 11 +- static/js/ckeditor/ckeditor.js | 18 +- static/js/ckeditor/config.js | 4 +- static/js/ckeditor/lang/en.js | 2 +- .../ckeditor/plugins/about/dialogs/about.js | 7 + .../about/dialogs/hidpi/logo_ckeditor.png | Bin 0 -> 13339 bytes .../plugins/about/dialogs/logo_ckeditor.png | Bin 0 -> 6757 bytes static/js/ckeditor/plugins/icons.png | Bin 10896 -> 10227 bytes static/js/ckeditor/plugins/icons_hidpi.png | Bin 37120 -> 34465 bytes static/js/ckeditor/samples/ajax.html | 82 ++ static/js/ckeditor/samples/api.html | 207 +++++ static/js/ckeditor/samples/appendto.html | 56 ++ .../samples/assets/inlineall/logo.png | Bin 0 -> 4283 bytes .../assets/outputxhtml/outputxhtml.css | 204 +++++ .../js/ckeditor/samples/assets/posteddata.php | 59 ++ static/js/ckeditor/samples/assets/sample.jpg | Bin 0 -> 14449 bytes .../samples/assets/uilanguages/languages.js | 7 + static/js/ckeditor/samples/datafiltering.html | 401 ++++++++++ static/js/ckeditor/samples/divreplace.html | 141 ++++ static/js/ckeditor/samples/index.html | 128 ++++ static/js/ckeditor/samples/inlineall.html | 311 ++++++++ static/js/ckeditor/samples/inlinebycode.html | 121 +++ .../js/ckeditor/samples/inlinetextarea.html | 110 +++ static/js/ckeditor/samples/jquery.html | 100 +++ .../plugins/dialog/assets/my_dialog.js | 48 ++ .../samples/plugins/dialog/dialog.html | 187 +++++ .../samples/plugins/enterkey/enterkey.html | 103 +++ .../assets/outputforflash/outputforflash.fla | Bin 0 -> 85504 bytes .../assets/outputforflash/outputforflash.swf | Bin 0 -> 15571 bytes .../assets/outputforflash/swfobject.js | 18 + .../plugins/htmlwriter/outputforflash.html | 280 +++++++ .../plugins/htmlwriter/outputhtml.html | 221 ++++++ .../samples/plugins/magicline/magicline.html | 206 +++++ .../samples/plugins/toolbar/toolbar.html | 232 ++++++ .../samples/plugins/wysiwygarea/fullpage.html | 77 ++ static/js/ckeditor/samples/readonly.html | 73 ++ .../js/ckeditor/samples/replacebyclass.html | 57 ++ static/js/ckeditor/samples/replacebycode.html | 56 ++ static/js/ckeditor/samples/sample.css | 365 +++++++++ static/js/ckeditor/samples/sample.js | 50 ++ .../js/ckeditor/samples/sample_posteddata.php | 16 + static/js/ckeditor/samples/tabindex.html | 75 ++ static/js/ckeditor/samples/uicolor.html | 69 ++ static/js/ckeditor/samples/uilanguages.html | 119 +++ static/js/ckeditor/samples/xhtmlstyle.html | 231 ++++++ .../js/ckeditor/skins/bootstrapck/editor.css | 2 +- .../skins/bootstrapck/editor_gecko.css | 2 +- .../ckeditor/skins/bootstrapck/editor_ie.css | 2 +- .../ckeditor/skins/bootstrapck/editor_ie7.css | 2 +- .../ckeditor/skins/bootstrapck/editor_ie8.css | 2 +- .../skins/bootstrapck/editor_iequirks.css | 2 +- .../js/ckeditor/skins/bootstrapck/icons.png | Bin 10896 -> 10227 bytes .../skins/bootstrapck/icons_hidpi.png | Bin 37120 -> 34465 bytes 60 files changed, 5352 insertions(+), 59 deletions(-) create mode 100644 static/js/app/partials/modals/siteCloneModal.html create mode 100644 static/js/ckeditor/CHANGES.md create mode 100644 static/js/ckeditor/README.md create mode 100644 static/js/ckeditor/plugins/about/dialogs/about.js create mode 100644 static/js/ckeditor/plugins/about/dialogs/hidpi/logo_ckeditor.png create mode 100644 static/js/ckeditor/plugins/about/dialogs/logo_ckeditor.png create mode 100644 static/js/ckeditor/samples/ajax.html create mode 100644 static/js/ckeditor/samples/api.html create mode 100644 static/js/ckeditor/samples/appendto.html create mode 100644 static/js/ckeditor/samples/assets/inlineall/logo.png create mode 100644 static/js/ckeditor/samples/assets/outputxhtml/outputxhtml.css create mode 100644 static/js/ckeditor/samples/assets/posteddata.php create mode 100644 static/js/ckeditor/samples/assets/sample.jpg create mode 100644 static/js/ckeditor/samples/assets/uilanguages/languages.js create mode 100644 static/js/ckeditor/samples/datafiltering.html create mode 100644 static/js/ckeditor/samples/divreplace.html create mode 100644 static/js/ckeditor/samples/index.html create mode 100644 static/js/ckeditor/samples/inlineall.html create mode 100644 static/js/ckeditor/samples/inlinebycode.html create mode 100644 static/js/ckeditor/samples/inlinetextarea.html create mode 100644 static/js/ckeditor/samples/jquery.html create mode 100644 static/js/ckeditor/samples/plugins/dialog/assets/my_dialog.js create mode 100644 static/js/ckeditor/samples/plugins/dialog/dialog.html create mode 100644 static/js/ckeditor/samples/plugins/enterkey/enterkey.html create mode 100644 static/js/ckeditor/samples/plugins/htmlwriter/assets/outputforflash/outputforflash.fla create mode 100644 static/js/ckeditor/samples/plugins/htmlwriter/assets/outputforflash/outputforflash.swf create mode 100644 static/js/ckeditor/samples/plugins/htmlwriter/assets/outputforflash/swfobject.js create mode 100644 static/js/ckeditor/samples/plugins/htmlwriter/outputforflash.html create mode 100644 static/js/ckeditor/samples/plugins/htmlwriter/outputhtml.html create mode 100644 static/js/ckeditor/samples/plugins/magicline/magicline.html create mode 100644 static/js/ckeditor/samples/plugins/toolbar/toolbar.html create mode 100644 static/js/ckeditor/samples/plugins/wysiwygarea/fullpage.html create mode 100644 static/js/ckeditor/samples/readonly.html create mode 100644 static/js/ckeditor/samples/replacebyclass.html create mode 100644 static/js/ckeditor/samples/replacebycode.html create mode 100644 static/js/ckeditor/samples/sample.css create mode 100644 static/js/ckeditor/samples/sample.js create mode 100644 static/js/ckeditor/samples/sample_posteddata.php create mode 100644 static/js/ckeditor/samples/tabindex.html create mode 100644 static/js/ckeditor/samples/uicolor.html create mode 100644 static/js/ckeditor/samples/uilanguages.html create mode 100644 static/js/ckeditor/samples/xhtmlstyle.html diff --git a/controllers/api.go b/controllers/api.go index a5f6cefb..5acfb83b 100644 --- a/controllers/api.go +++ b/controllers/api.go @@ -2,6 +2,7 @@ package controllers import ( "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -350,19 +351,56 @@ func API_Import_Group(w http.ResponseWriter, r *http.Request) { return } JSONResponse(w, ts, http.StatusOK) + return } // API_Import_Email allows for the importing of email. // Returns a Message object func API_Import_Email(w http.ResponseWriter, r *http.Request) { - if r.Method == "POST" { - body, err := ioutil.ReadAll(r.Body) - if err != nil { - Logger.Println(err) - } - w.Header().Set("Content-Type", "text/plain") - fmt.Fprintf(w, "%s", body) + if r.Method != "POST" { + JSONResponse(w, models.Response{Success: false, Message: "Method not allowed"}, http.StatusBadRequest) + return } + body, err := ioutil.ReadAll(r.Body) + if err != nil { + Logger.Println(err) + } + w.Header().Set("Content-Type", "text/plain") + fmt.Fprintf(w, "%s", body) + return +} + +// API_Import_Site allows for the importing of HTML from a website +// Without "include_resources" set, it will merely place a "base" tag +// so that all resources can be loaded relative to the given URL. +func API_Import_Site(w http.ResponseWriter, r *http.Request) { + cr := cloneRequest{} + if r.Method != "POST" { + JSONResponse(w, models.Response{Success: false, Message: "Method not allowed"}, http.StatusBadRequest) + return + } + err := json.NewDecoder(r.Body).Decode(&cr) + if err != nil { + JSONResponse(w, models.Response{Success: false, Message: "Error decoding JSON Request"}, http.StatusBadRequest) + return + } + if err = cr.validate(); err != nil { + JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) + return + } + resp, err := http.Get(cr.URL) + if err != nil { + JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) + return + } + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) + return + } + cs := cloneResponse{HTML: string(body)} + JSONResponse(w, cs, http.StatusOK) + return } // JSONResponse attempts to set the status code, c, and marshal the given interface, d, into a response that @@ -377,3 +415,19 @@ func JSONResponse(w http.ResponseWriter, d interface{}, c int) { w.WriteHeader(c) fmt.Fprintf(w, "%s", dj) } + +type cloneRequest struct { + URL string `json:"url"` + IncludeResources bool `json:"include_resources"` +} + +func (cr *cloneRequest) validate() error { + if cr.URL == "" { + return errors.New("No URL Specified") + } + return nil +} + +type cloneResponse struct { + HTML string `json:"html"` +} diff --git a/controllers/route.go b/controllers/route.go index 2c1cdf50..0a572220 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -31,8 +31,6 @@ func CreateAdminRouter() http.Handler { router.HandleFunc("/logout", Use(Logout, mid.RequireLogin)) router.HandleFunc("/register", Register) router.HandleFunc("/settings", Use(Settings, 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) @@ -48,6 +46,7 @@ func CreateAdminRouter() http.Handler { api.HandleFunc("/pages/{id:[0-9]+}", Use(API_Pages_Id, mid.RequireAPIKey)) api.HandleFunc("/import/group", API_Import_Group) api.HandleFunc("/import/email", API_Import_Email) + api.HandleFunc("/import/site", API_Import_Site) // Setup static file serving router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/"))) diff --git a/static/js/app/controllers.js b/static/js/app/controllers.js index c02b1bfe..fa417a66 100644 --- a/static/js/app/controllers.js +++ b/static/js/app/controllers.js @@ -257,7 +257,7 @@ var CampaignModalCtrl = function($scope, CampaignService, $modalInstance) { $scope.editGroupTableParams.reload() }; $scope.cancel = function() { - $modalInstance.dismiss('cancel'); + $modalInstance.dismiss(); }; $scope.ok = function(campaign) { var newCampaign = new CampaignService(campaign); @@ -613,7 +613,7 @@ var GroupModalCtrl = function($scope, GroupService, $modalInstance, $upload) { }) } }; -} +}; app.controller('TemplateCtrl', function($scope, $modal, TemplateService, ngTableParams) { $scope.errorFlash = function(message) { @@ -795,14 +795,13 @@ var ImportEmailCtrl = function($scope, $http, $modalInstance) { ).success(function(data) {console.log("Success: " + data)}) .error(function(data) {console.log("Error: " + data)}); $modalInstance.close($scope.email.raw) -}; -$scope.cancel = function() {$modalInstance.dismiss()} -}; + }; +} app.controller('LandingPageCtrl', function($scope, $modal, LandingPageService, ngTableParams) { $scope.errorFlash = function(message) { - $scope.flashes = []; - $scope.flashes.push({ + $scope.flashes = {"main" : [], "modal" : []}; + $scope.flashes.modal.push({ "type": "danger", "message": message, "icon": "fa-exclamation-circle" @@ -810,8 +809,8 @@ app.controller('LandingPageCtrl', function($scope, $modal, LandingPageService, n } $scope.successFlash = function(message) { - $scope.flashes = []; - $scope.flashes.push({ + $scope.flashes = {"main" : [], "modal" : []};; + $scope.flashes.modal.push({ "type": "success", "message": message, "icon": "fa-check-circle" @@ -892,22 +891,84 @@ app.controller('LandingPageCtrl', function($scope, $modal, LandingPageService, n } }); -var LandingPageModalCtrl = function($scope, $modalInstance) { +var LandingPageModalCtrl = function($scope, $modalInstance, $http) { $scope.editorOptions = { fullPage: true, allowedContent: true, startupMode: "source" } + $scope.errorFlash = function(message) { + $scope.flashes = {"main" : [], "modal" : []}; + $scope.flashes.modal.push({ + "type": "danger", + "message": message, + "icon": "fa-exclamation-circle" + }) + } + + $scope.successFlash = function(message) { + $scope.flashes = {"main" : [], "modal" : []};; + $scope.flashes.modal.push({ + "type": "success", + "message": message, + "icon": "fa-check-circle" + }) + } + $scope.cloneSite = function() { + var siteModalInstance = $modal.open({ + templateUrl: '/js/app/partials/modals/siteCloneModal.html', //<---- Need to make this + controller: SiteCloneCtrl, + scope: $scope + }); + siteModalInstance.result.then(function(data) { + $scope.successFlash(data.message) + $scope.html = data.html; + }, function() {}); + }; $scope.cancel = function() { - $modalInstance.dismiss('cancel'); + $modalInstance.dismiss(); }; $scope.ok = function(page) { $modalInstance.dismiss('') $scope.savePage(page) }; - $scope.csrf_token = csrf_token }; +var SiteCloneCtrl = function($scope, $modalInstance, $http) { + $scope.errorFlash = function(message) { + $scope.flashes = {"main" : [], "modal" : []}; + $scope.flashes.modal.push({ + "type": "danger", + "message": message, + "icon": "fa-exclamation-circle" + }) + } + $scope.ok = function() { + if ($scope.url == "") { + $scope.errorFlash("No URL Specified") + return + } + $http.post({ + method: "POST", + url: "/api/import/site", + data: { + "url" : $scope.url, + "include_resources" : $scope.include_resources + }, + headers : { + "Content-Type" : "application/json" + } + }).success(function(response){ + $modalInstance.close(response); + }).error(function(response){ + $scope.errorFlash(response.message) + }); + } + $scope.cancel = function() { + $modalInstance.dismiss(); + }; +} + app.controller('SettingsCtrl', function($scope, $http, $window) { $scope.flashes = []; $scope.user = user; diff --git a/static/js/app/partials/modals/landingPageModal.html b/static/js/app/partials/modals/landingPageModal.html index 4539e38e..786c0cd4 100644 --- a/static/js/app/partials/modals/landingPageModal.html +++ b/static/js/app/partials/modals/landingPageModal.html @@ -5,7 +5,11 @@