diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 351b2bd1..8e6fbcce 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -62,8 +62,6 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven {redirectTo: (params) -> "/project/#{params.pslug}/wiki/home"}, ) $routeProvider.when("/project/:pslug/wiki/:slug", {templateUrl: "/partials/wiki.html", resolve: {loader: tgLoaderProvider.add()}}) - $routeProvider.when("/project/:pslug/wiki/:slug/edit", - {templateUrl: "/partials/wiki-edit.html"}) # Issues $routeProvider.when("/project/:pslug/issues", diff --git a/app/coffee/modules/base.coffee b/app/coffee/modules/base.coffee index 4719e659..8310d95c 100644 --- a/app/coffee/modules/base.coffee +++ b/app/coffee/modules/base.coffee @@ -74,7 +74,6 @@ urls = { "project-wiki": "/project/:project/wiki", "project-wiki-page": "/project/:project/wiki/:slug", - "project-wiki-page-edit": "/project/:project/wiki/:slug/edit", # Admin "project-admin-home": "/project/:project/admin/project-profile/details" diff --git a/app/coffee/modules/wiki/main.coffee b/app/coffee/modules/wiki/main.coffee index de58d10e..6abc2599 100644 --- a/app/coffee/modules/wiki/main.coffee +++ b/app/coffee/modules/wiki/main.coffee @@ -38,6 +38,7 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin) "$scope", "$rootScope", "$tgRepo", + "$tgModel", "$tgConfirm", "$tgResources", "$routeParams", @@ -51,7 +52,7 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin) "tgLoader" ] - constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, + constructor: (@scope, @rootscope, @repo, @model, @confirm, @rs, @params, @q, @location, @filter, @log, @appTitle, @navUrls, @analytics, tgLoader) -> @scope.projectSlug = @params.pslug @scope.wikiSlug = @params.slug @@ -80,7 +81,15 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin) @scope.wiki = wiki return wiki - @scope.wiki = {content: ""} + if @scope.project.my_permissions.indexOf("add_wiki_page") == -1 + return null + + data = { + project: @scope.projectId + slug: @scope.wikiSlug + content: "" + } + @scope.wiki = @model.make_model("wiki", data) return @scope.wiki loadWikiLinks: -> @@ -109,28 +118,13 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin) @scope.wikiId = data.wikipage return prom.then null, (xhr) => - ctx = {project: @params.pslug, slug: @params.slug} - @location.path(@navUrls.resolve("project-wiki-page-edit", ctx)) + @scope.wikiId = null return promise.then(=> @.loadProject()) .then(=> @.loadUsersAndRoles()) .then(=> @q.all([@.loadWikiLinks(), @.loadWiki()])) - edit: -> - ctx = { - project: @scope.projectSlug - slug: @scope.wikiSlug - } - @location.path(@navUrls.resolve("project-wiki-page-edit", ctx)) - - cancel: -> - ctx = { - project: @scope.projectSlug - slug: @scope.wikiSlug - } - @location.path(@navUrls.resolve("project-wiki-page", ctx)) - delete: -> # TODO: i18n title = "Delete Wiki Page" @@ -151,59 +145,6 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin) module.controller("WikiDetailController", WikiDetailController) -############################################################################# -## Wiki Edit Controller -############################################################################# - -class WikiEditController extends WikiDetailController - save: debounce 2000, -> - onSuccess = => - ctx = { - project: @scope.projectSlug - slug: @scope.wiki.slug - } - @location.path(@navUrls.resolve("project-wiki-page", ctx)) - @confirm.notify("success") - - onError = => - @confirm.notify("error") - - if @scope.wiki.id - @repo.save(@scope.wiki).then onSuccess, onError - else - @analytics.trackEvent("wikipage", "create", "create wiki page", 1) - @scope.wiki.project = @scope.projectId - @scope.wiki.slug = @scope.wikiSlug - @repo.create("wiki", @scope.wiki).then onSuccess, onError - -module.controller("WikiEditController", WikiEditController) - - -############################################################################# -## Wiki Main Directive -############################################################################# - -WikiDirective = ($tgrepo, $log, $location, $confirm) -> - link = ($scope, $el, $attrs) -> - $ctrl = $el.controller() - - return {link:link} - -module.directive("tgWikiDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", WikiDirective]) - - -############################################################################# -## Wiki Edit Main Directive -############################################################################# - -WikiEditDirective = ($tgrepo, $log, $location, $confirm) -> - link = ($scope, $el, $attrs) -> - $ctrl = $el.controller() - - return {link:link} - -module.directive("tgWikiEdit", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", WikiEditDirective]) - ############################################################################# ## Wiki User Info Directive @@ -243,3 +184,115 @@ WikiUserInfoDirective = ($log) -> } module.directive("tgWikiUserInfo", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", WikiUserInfoDirective]) + + +############################################################################# +## Editable Wiki Content Directive +############################################################################# + +EditableWikiContentDirective = ($window, $document, $repo, $confirm, $loading, $location, $navUrls, + $analytics) -> + template = """ +