From 6d516b58fb9743bf389d4db8c365eb886d8f651b Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Mon, 25 Jul 2016 13:53:59 +0200 Subject: [PATCH 1/2] added is-publsihed function for route-provider --- Routing/ArticleRouteDefaultProvider.php | 20 +++- .../ArticleRouteDefaultProviderTest.php | 107 ++++++++++++++++++ 2 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 Tests/Unit/Routing/ArticleRouteDefaultProviderTest.php diff --git a/Routing/ArticleRouteDefaultProvider.php b/Routing/ArticleRouteDefaultProvider.php index 961888c66..89fe96afd 100644 --- a/Routing/ArticleRouteDefaultProvider.php +++ b/Routing/ArticleRouteDefaultProvider.php @@ -13,7 +13,7 @@ use Sulu\Bundle\ArticleBundle\Document\ArticleDocument; use Sulu\Bundle\RouteBundle\Routing\Defaults\RouteDefaultsProviderInterface; -use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactory; +use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface; use Sulu\Component\DocumentManager\DocumentManagerInterface; /** @@ -27,17 +27,17 @@ class ArticleRouteDefaultProvider implements RouteDefaultsProviderInterface private $documentManager; /** - * @var StructureMetadataFactory + * @var StructureMetadataFactoryInterface */ private $structureMetadataFactory; /** * @param DocumentManagerInterface $documentManager - * @param StructureMetadataFactory $structureMetadataFactory + * @param StructureMetadataFactoryInterface $structureMetadataFactory */ public function __construct( DocumentManagerInterface $documentManager, - StructureMetadataFactory $structureMetadataFactory + StructureMetadataFactoryInterface $structureMetadataFactory ) { $this->documentManager = $documentManager; $this->structureMetadataFactory = $structureMetadataFactory; @@ -64,6 +64,18 @@ public function getByEntity($entityClass, $id, $locale, $object = null) ]; } + /** + * If article is not published the document will be of typ unknown-document. + * + * {@inheritdoc} + */ + public function isPublished($entityClass, $id, $locale) + { + $object = $this->documentManager->find($id, $locale); + + return $object instanceof ArticleDocument; + } + /** * {@inheritdoc} */ diff --git a/Tests/Unit/Routing/ArticleRouteDefaultProviderTest.php b/Tests/Unit/Routing/ArticleRouteDefaultProviderTest.php new file mode 100644 index 000000000..0f7238854 --- /dev/null +++ b/Tests/Unit/Routing/ArticleRouteDefaultProviderTest.php @@ -0,0 +1,107 @@ +documentManager = $this->prophesize(DocumentManagerInterface::class); + $this->structureMetadataFactory = $this->prophesize(StructureMetadataFactoryInterface::class); + + $this->provider = new ArticleRouteDefaultProvider( + $this->documentManager->reveal(), + $this->structureMetadataFactory->reveal() + ); + } + + public function publishedDataProvider() + { + return [ + [new UnknownDocument(), false], + [new ArticleDocument(), true], + ]; + } + + /** + * @dataProvider publishedDataProvider + */ + public function testIsPublished($document, $result) + { + $this->documentManager->find($this->entityId, $this->locale)->willReturn($document); + + $this->assertEquals($result, $this->provider->isPublished($this->entityClass, $this->entityId, $this->locale)); + } + + public function testGetByEntity() + { + $article = $this->prophesize(ArticleDocument::class); + $article->getStructureType()->willReturn('default'); + + $structureMetadata = new StructureMetadata('default'); + $structureMetadata->view = 'default.html.twig'; + $structureMetadata->cacheLifetime = 3600; + $structureMetadata->controller = 'SuluArticleBundle:Default:index'; + + $this->documentManager->find($this->entityId, $this->locale)->willReturn($article->reveal()); + $this->structureMetadataFactory->getStructureMetadata('article', 'default')->willReturn($structureMetadata); + + $result = $this->provider->getByEntity($this->entityClass, $this->entityId, $this->locale); + + $this->assertEquals( + [ + 'object' => $article->reveal(), + 'view' => 'default.html.twig', + '_controller' => 'SuluArticleBundle:Default:index', + '_cacheLifetime' => 3600, + ], + $result + ); + } +} From 8c97a7063435c097d94b7e85139b2e25f9ec9094 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Mon, 25 Jul 2016 15:16:29 +0200 Subject: [PATCH 2/2] added config for type translations --- Admin/ArticleJsConfig.php | 30 +++++++++++++++++-- DependencyInjection/Configuration.php | 12 +++++++- DependencyInjection/SuluArticleExtension.php | 1 + Resources/config/services.xml | 1 + .../components/articles/edit/details/main.js | 2 +- .../dist/components/articles/edit/main.js | 2 +- .../dist/components/articles/list/main.js | 2 +- Resources/public/dist/main.js | 2 +- .../components/articles/edit/details/main.js | 3 +- .../js/components/articles/edit/main.js | 4 +-- .../js/components/articles/list/main.js | 22 +++++++------- Resources/public/js/main.js | 11 +++---- 12 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Admin/ArticleJsConfig.php b/Admin/ArticleJsConfig.php index 2801f31f0..aaa9f8e12 100644 --- a/Admin/ArticleJsConfig.php +++ b/Admin/ArticleJsConfig.php @@ -27,12 +27,19 @@ class ArticleJsConfig implements JsConfigInterface */ private $structureManager; + /** + * @var array + */ + private $typeConfiguration; + /** * @param StructureManagerInterface $structureManager + * @param $typeConfiguration */ - public function __construct(StructureManagerInterface $structureManager) + public function __construct(StructureManagerInterface $structureManager, $typeConfiguration) { $this->structureManager = $structureManager; + $this->typeConfiguration = $typeConfiguration; } /** @@ -44,7 +51,10 @@ public function getParameters() foreach ($this->structureManager->getStructures('article') as $structure) { $type = $this->getType($structure->getStructure()); if (!array_key_exists($type, $types)) { - $types[$type] = $structure->getKey(); + $types[$type] = [ + 'default' => $structure->getKey(), + 'title' => $this->getTitle($type), + ]; } } @@ -58,4 +68,20 @@ public function getName() { return 'sulu_article.types'; } + + /** + * Returns title for given type. + * + * @param string $type + * + * @return string + */ + private function getTitle($type) + { + if (!array_key_exists($type, $this->typeConfiguration)) { + return ucfirst($type); + } + + return $this->typeConfiguration[$type]['translation_key']; + } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 979c60ebe..e3717b579 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,7 +25,17 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('sulu_article'); + $treeBuilder->root('sulu_article') + ->children() + ->arrayNode('types') + ->useAttributeAsKey('name') + ->prototype('array') + ->children() + ->scalarNode('translation_key')->end() + ->end() + ->end() + ->end() + ->end(); return $treeBuilder; } diff --git a/DependencyInjection/SuluArticleExtension.php b/DependencyInjection/SuluArticleExtension.php index 653e9d9bf..963c51412 100644 --- a/DependencyInjection/SuluArticleExtension.php +++ b/DependencyInjection/SuluArticleExtension.php @@ -95,6 +95,7 @@ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); + $container->setParameter('sulu_articles.types', $config['types']); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 007464e8b..2de964e2d 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -18,6 +18,7 @@ + %sulu_articles.types% diff --git a/Resources/public/dist/components/articles/edit/details/main.js b/Resources/public/dist/components/articles/edit/details/main.js index 065d0ef04..b81ae6e9c 100644 --- a/Resources/public/dist/components/articles/edit/details/main.js +++ b/Resources/public/dist/components/articles/edit/details/main.js @@ -1 +1 @@ -define(["underscore","jquery","config"],function(a,b,c){"use strict";return{layout:{extendExisting:!0,content:{width:"fixed",rightSpace:!1,leftSpace:!1}},initialize:function(){this.saved=!0,this.render(),this.bindCustomEvents(),this.listenForChange()},bindCustomEvents:function(){this.sandbox.on("sulu.tab.template-change",function(a){this.checkRenderTemplate(a.template)},this),this.sandbox.on("sulu.content.contents.default-template",function(a){this.template=a,this.sandbox.emit("sulu.header.toolbar.item.change","template",a)}.bind(this)),this.sandbox.on("sulu.tab.save",this.save.bind(this))},listenForChange:function(){this.sandbox.dom.on(this.$el,"keyup",a.debounce(this.setDirty.bind(this),10),"input, textarea"),this.sandbox.dom.on(this.$el,"change",a.debounce(this.setDirty.bind(this),10),'input[type="checkbox"], select'),this.sandbox.on("sulu.content.changed",this.setDirty.bind(this))},setDirty:function(){this.saved=!1,this.sandbox.emit("sulu.tab.dirty")},save:function(a){if(!this.sandbox.form.validate(this.formId))return this.sandbox.emit("sulu.tab.dirty",!0);var b=this.sandbox.form.getData(this.formId);b.template=this.template,this.sandbox.emit("sulu.articles.save",b,a)},render:function(){this.checkRenderTemplate(this.data.template||null)},checkRenderTemplate:function(a){return a&&this.template===a?this.sandbox.emit("sulu.header.toolbar.item.enable","template",!1):(this.sandbox.emit("sulu.header.toolbar.item.loading","template"),void(""===this.template||this.saved?this.loadFormTemplate(a):this.showRenderTemplateDialog(a)))},showRenderTemplateDialog:function(a){this.sandbox.emit("sulu.overlay.show-warning","sulu.overlay.be-careful","content.template.dialog.content",function(){this.sandbox.emit("sulu.header.toolbar.item.enable","template",!1),this.template&&this.sandbox.emit("sulu.header.toolbar.item.change","template",this.template,!1)}.bind(this),function(){this.loadFormTemplate(a)}.bind(this))},loadFormTemplate:function(a){if(!a){var b=c.get("sulu_article.types");a=b[this.options.type||this.data.type]}if(this.template=a,this.formId="#content-form-container",this.$container=this.sandbox.dom.createElement('
'),this.html(this.$container),this.sandbox.form.getObject(this.formId)){var d=this.data;this.data=this.sandbox.form.getData(this.formId),d.id&&(this.data.id=d.id),this.data=this.sandbox.util.extend({},d,this.data)}require([this.getTemplateUrl(a)],function(a){this.renderFormTemplate(a)}.bind(this))},getTemplateUrl:function(a){var b="text!/admin/content/template/form";return b+=a?"/"+a+".html":".html",b+="?type=article&language="+this.options.locale,this.data.id&&(b+="&uuid="+this.data.id),b},renderFormTemplate:function(a){this.sandbox.dom.html(this.formId,this.sandbox.util.template(a,{translate:this.sandbox.translate,content:this.data,options:this.options})),this.createForm(this.data).then(function(){this.changeTemplateDropdownHandler()}.bind(this))},changeTemplateDropdownHandler:function(){this.template&&this.sandbox.emit("sulu.header.toolbar.item.change","template",this.template),this.sandbox.emit("sulu.header.toolbar.item.enable","template",!1)},createForm:function(a){var b=this.sandbox.form.create(this.formId),c=this.sandbox.data.deferred();return b.initialized.then(function(){this.sandbox.form.setData(this.formId,a).then(function(){this.sandbox.start(this.$el,{reset:!0}).then(function(){this.initSortableBlock(),this.bindFormEvents(),c.resolve()}.bind(this))}.bind(this))}.bind(this)),c.promise()},initSortableBlock:function(){var a,b=this.sandbox.dom.find(".sortable",this.$el);b&&b.length>0&&(this.sandbox.dom.sortable(b,"destroy"),a=this.sandbox.dom.sortable(b,{handle:".move",forcePlaceholderSize:!0}),this.sandbox.dom.unbind(a,"sortupdate"),a.bind("sortupdate",function(a){this.sandbox.emit("sulu.content.changed")}.bind(this)))},bindFormEvents:function(){this.sandbox.dom.on(this.formId,"form-remove",function(){this.initSortableBlock(),this.setDirty()}.bind(this)),this.sandbox.dom.on(this.formId,"form-add",function(a,b,c,d){this.createConfiguration(a.currentTarget);var e=this.sandbox.dom.children(this.$find('[data-mapper-property="'+b+'"]')),f=void 0!==d&&e.length>d?e[d]:this.sandbox.dom.last(e);this.sandbox.start(f),this.setDirty(),this.initSortableBlock()}.bind(this)),this.sandbox.dom.on(this.formId,"init-sortable",function(a){this.initSortableBlock()}.bind(this))},loadComponentData:function(){var a=b.Deferred();return a.resolve(this.options.data()),a}}}); \ No newline at end of file +define(["underscore","jquery","config"],function(a,b,c){"use strict";return{layout:{extendExisting:!0,content:{width:"fixed",rightSpace:!1,leftSpace:!1}},initialize:function(){this.saved=!0,this.render(),this.bindCustomEvents(),this.listenForChange()},bindCustomEvents:function(){this.sandbox.on("sulu.tab.template-change",function(a){this.checkRenderTemplate(a.template)},this),this.sandbox.on("sulu.content.contents.default-template",function(a){this.template=a,this.sandbox.emit("sulu.header.toolbar.item.change","template",a)}.bind(this)),this.sandbox.on("sulu.tab.save",this.save.bind(this))},listenForChange:function(){this.sandbox.dom.on(this.$el,"keyup",a.debounce(this.setDirty.bind(this),10),"input, textarea"),this.sandbox.dom.on(this.$el,"change",a.debounce(this.setDirty.bind(this),10),'input[type="checkbox"], select'),this.sandbox.on("sulu.content.changed",this.setDirty.bind(this))},setDirty:function(){this.saved=!1,this.sandbox.emit("sulu.tab.dirty")},save:function(a){if(!this.sandbox.form.validate(this.formId))return this.sandbox.emit("sulu.tab.dirty",!0);var b=this.sandbox.form.getData(this.formId);b.template=this.template,this.sandbox.emit("sulu.articles.save",b,a)},render:function(){this.checkRenderTemplate(this.data.template||null)},checkRenderTemplate:function(a){return a&&this.template===a?this.sandbox.emit("sulu.header.toolbar.item.enable","template",!1):(this.sandbox.emit("sulu.header.toolbar.item.loading","template"),void(""===this.template||this.saved?this.loadFormTemplate(a):this.showRenderTemplateDialog(a)))},showRenderTemplateDialog:function(a){this.sandbox.emit("sulu.overlay.show-warning","sulu.overlay.be-careful","content.template.dialog.content",function(){this.sandbox.emit("sulu.header.toolbar.item.enable","template",!1),this.template&&this.sandbox.emit("sulu.header.toolbar.item.change","template",this.template,!1)}.bind(this),function(){this.loadFormTemplate(a)}.bind(this))},loadFormTemplate:function(a){if(a||(a=this.options.config.types[this.options.type||this.data.type]["default"]),this.template=a,this.formId="#content-form-container",this.$container=this.sandbox.dom.createElement('
'),this.html(this.$container),this.sandbox.form.getObject(this.formId)){var b=this.data;this.data=this.sandbox.form.getData(this.formId),b.id&&(this.data.id=b.id),this.data=this.sandbox.util.extend({},b,this.data)}require([this.getTemplateUrl(a)],function(a){this.renderFormTemplate(a)}.bind(this))},getTemplateUrl:function(a){var b="text!/admin/content/template/form";return b+=a?"/"+a+".html":".html",b+="?type=article&language="+this.options.locale,this.data.id&&(b+="&uuid="+this.data.id),b},renderFormTemplate:function(a){this.sandbox.dom.html(this.formId,this.sandbox.util.template(a,{translate:this.sandbox.translate,content:this.data,options:this.options})),this.createForm(this.data).then(function(){this.changeTemplateDropdownHandler()}.bind(this))},changeTemplateDropdownHandler:function(){this.template&&this.sandbox.emit("sulu.header.toolbar.item.change","template",this.template),this.sandbox.emit("sulu.header.toolbar.item.enable","template",!1)},createForm:function(a){var b=this.sandbox.form.create(this.formId),c=this.sandbox.data.deferred();return b.initialized.then(function(){this.sandbox.form.setData(this.formId,a).then(function(){this.sandbox.start(this.$el,{reset:!0}).then(function(){this.initSortableBlock(),this.bindFormEvents(),c.resolve()}.bind(this))}.bind(this))}.bind(this)),c.promise()},initSortableBlock:function(){var a,b=this.sandbox.dom.find(".sortable",this.$el);b&&b.length>0&&(this.sandbox.dom.sortable(b,"destroy"),a=this.sandbox.dom.sortable(b,{handle:".move",forcePlaceholderSize:!0}),this.sandbox.dom.unbind(a,"sortupdate"),a.bind("sortupdate",function(a){this.sandbox.emit("sulu.content.changed")}.bind(this)))},bindFormEvents:function(){this.sandbox.dom.on(this.formId,"form-remove",function(){this.initSortableBlock(),this.setDirty()}.bind(this)),this.sandbox.dom.on(this.formId,"form-add",function(a,b,c,d){this.createConfiguration(a.currentTarget);var e=this.sandbox.dom.children(this.$find('[data-mapper-property="'+b+'"]')),f=void 0!==d&&e.length>d?e[d]:this.sandbox.dom.last(e);this.sandbox.start(f),this.setDirty(),this.initSortableBlock()}.bind(this)),this.sandbox.dom.on(this.formId,"init-sortable",function(a){this.initSortableBlock()}.bind(this))},loadComponentData:function(){var a=b.Deferred();return a.resolve(this.options.data()),a}}}); \ No newline at end of file diff --git a/Resources/public/dist/components/articles/edit/main.js b/Resources/public/dist/components/articles/edit/main.js index 11f47ff13..93f28faa1 100644 --- a/Resources/public/dist/components/articles/edit/main.js +++ b/Resources/public/dist/components/articles/edit/main.js @@ -1 +1 @@ -define(["jquery","underscore","sulusecurity/services/user-manager"],function(a,b,c){"use strict";return{defaults:{options:{config:{}},templates:{url:"/admin/api/articles<% if (!!id) { %>/<%= id %><% } %>?locale=<%= locale %>"},translations:{headline:"sulu_article.edit.title",draftLabel:"sulu-document-manager.draft-label"}},header:function(){var a={save:{parent:"saveWithDraft"},template:{options:{dropdownOptions:{url:"/admin/articles/templates?type="+(this.options.type||this.data.type),callback:function(a){this.template=a.template,this.sandbox.emit("sulu.tab.template-change",a)}.bind(this)}}}};return this.options.id&&(a["delete"]={}),{tabs:{url:"/admin/content-navigations?alias=article",options:{data:function(){return this.sandbox.util.deepCopy(this.data)}.bind(this),url:function(){return this.templates.url({id:this.options.id,locale:this.options.locale})}.bind(this),config:this.options.config},componentOptions:{values:this.data}},toolbar:{buttons:a}}},initialize:function(){this.saveState="disabled",this.bindCustomEvents(),this.showDraftLabel()},bindCustomEvents:function(){this.sandbox.on("sulu.header.back",this.toList.bind(this)),this.sandbox.on("sulu.tab.dirty",this.setHeaderBar.bind(this)),this.sandbox.on("sulu.toolbar.save",this.save.bind(this)),this.sandbox.on("sulu.toolbar.delete",this.deleteItem.bind(this)),this.sandbox.on("sulu.tab.data-changed",this.setData.bind(this)),this.sandbox.on("sulu.articles.save",this.saveArticle.bind(this)),this.sandbox.on("sulu.tab.saved",this.showDraftLabel.bind(this)),this.sandbox.on("sulu.header.language-changed",function(a){this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey,a.id),this.toEdit(a.id)}.bind(this))},deleteItem:function(){this.sandbox.util.save("/admin/api/articles/"+this.options.id,"DELETE").then(function(){this.toList()}.bind(this))},toEdit:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(a||this.options.locale)+"/edit:"+(b||this.options.id)+"/details",!0,!0)},toList:function(){1===this.options.config.types.length?this.sandbox.emit("sulu.router.navigate","articles/"+this.options.locale):this.sandbox.emit("sulu.router.navigate","articles:"+(this.options.type||this.data.type)+"/"+this.options.locale)},toAdd:function(){1===this.options.config.types.length?this.sandbox.emit("sulu.router.navigate","articles/"+this.options.locale+"/add",!0,!0):this.sandbox.emit("sulu.router.navigate","articles/"+this.options.locale+"/add:"+(this.options.type||this.data.type),!0,!0)},save:function(a){this.loadingSave(),this.saveTab(a).then(function(b){this.afterSave(a,b)}.bind(this))},setData:function(a){this.data=a},saveTab:function(b){var c=a.Deferred();return this.sandbox.once("sulu.tab.saved",function(a){this.setData(a),c.resolve(a)}.bind(this)),this.sandbox.emit("sulu.tab.save",b),c},saveArticle:function(a,b){return this.sandbox.util.save(this.getUrl(b),this.data.id?"PUT":"POST",a).then(function(a){this.data=a,this.sandbox.emit("sulu.tab.saved",a)}.bind(this))},setHeaderBar:function(a){var b=!a,c=!a,d=!!a&&!this.data.publishedState;this.setSaveToolbarItems.call(this,"saveDraft",b),this.setSaveToolbarItems.call(this,"savePublish",c),this.setSaveToolbarItems.call(this,"publish",d),this.setSaveToolbarItems.call(this,"save",!!b||!!c||!!d),this.saved=a},setSaveToolbarItems:function(a,b){this.sandbox.emit("sulu.header.toolbar.item."+(b?"enable":"disable"),a,!1)},loadingSave:function(){this.saveState="loading",this.sandbox.emit("sulu.header.toolbar.item.loading","save")},afterSave:function(a,b){this.setHeaderBar(!0),this.sandbox.emit("sulu.header.saved",b),"back"===a?this.toList():"new"===a?this.toAdd():this.options.id||this.toEdit(this.options.locale,b.id)},showDraftLabel:function(){this.sandbox.emit("sulu.header.tabs.label.hide"),this.data.id&&!this.data.publishedState&&(this.setHeaderBar(!0),c.find(this.data.changer).then(function(a){this.sandbox.emit("sulu.header.tabs.label.show",this.sandbox.util.sprintf(this.sandbox.translate(this.translations.draftLabel),{changed:this.sandbox.date.format(this.data.changed,!0),user:a.username}))}.bind(this)))},getUrl:function(a){var c=b.template(this.defaults.templates.url,{id:this.options.id,locale:this.options.locale});return a&&(c+="&action="+a),c},loadComponentData:function(){var b=a.Deferred();return this.options.id?(this.sandbox.util.load(this.getUrl()).done(function(a){b.resolve(a)}),b):(b.resolve({}),b)}}}); \ No newline at end of file +define(["jquery","underscore","sulusecurity/services/user-manager"],function(a,b,c){"use strict";return{defaults:{options:{config:{}},templates:{url:"/admin/api/articles<% if (!!id) { %>/<%= id %><% } %>?locale=<%= locale %>"},translations:{headline:"sulu_article.edit.title",draftLabel:"sulu-document-manager.draft-label"}},header:function(){var a={save:{parent:"saveWithDraft"},template:{options:{dropdownOptions:{url:"/admin/articles/templates?type="+(this.options.type||this.data.type),callback:function(a){this.template=a.template,this.sandbox.emit("sulu.tab.template-change",a)}.bind(this)}}}};return this.options.id&&(a["delete"]={}),{tabs:{url:"/admin/content-navigations?alias=article",options:{data:function(){return this.sandbox.util.deepCopy(this.data)}.bind(this),url:function(){return this.templates.url({id:this.options.id,locale:this.options.locale})}.bind(this),config:this.options.config},componentOptions:{values:this.data}},toolbar:{buttons:a}}},initialize:function(){this.saveState="disabled",this.bindCustomEvents(),this.showDraftLabel()},bindCustomEvents:function(){this.sandbox.on("sulu.header.back",this.toList.bind(this)),this.sandbox.on("sulu.tab.dirty",this.setHeaderBar.bind(this)),this.sandbox.on("sulu.toolbar.save",this.save.bind(this)),this.sandbox.on("sulu.toolbar.delete",this.deleteItem.bind(this)),this.sandbox.on("sulu.tab.data-changed",this.setData.bind(this)),this.sandbox.on("sulu.articles.save",this.saveArticle.bind(this)),this.sandbox.on("sulu.tab.saved",this.showDraftLabel.bind(this)),this.sandbox.on("sulu.header.language-changed",function(a){this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey,a.id),this.toEdit(a.id)}.bind(this))},deleteItem:function(){this.sandbox.util.save("/admin/api/articles/"+this.options.id,"DELETE").then(function(){this.toList()}.bind(this))},toEdit:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(a||this.options.locale)+"/edit:"+(b||this.options.id)+"/details",!0,!0)},toList:function(){1===this.options.config.typeNames.length?this.sandbox.emit("sulu.router.navigate","articles/"+this.options.locale):this.sandbox.emit("sulu.router.navigate","articles:"+(this.options.type||this.data.type)+"/"+this.options.locale)},toAdd:function(){1===this.options.config.typeNames.length?this.sandbox.emit("sulu.router.navigate","articles/"+this.options.locale+"/add",!0,!0):this.sandbox.emit("sulu.router.navigate","articles/"+this.options.locale+"/add:"+(this.options.type||this.data.type),!0,!0)},save:function(a){this.loadingSave(),this.saveTab(a).then(function(b){this.afterSave(a,b)}.bind(this))},setData:function(a){this.data=a},saveTab:function(b){var c=a.Deferred();return this.sandbox.once("sulu.tab.saved",function(a){this.setData(a),c.resolve(a)}.bind(this)),this.sandbox.emit("sulu.tab.save",b),c},saveArticle:function(a,b){return this.sandbox.util.save(this.getUrl(b),this.data.id?"PUT":"POST",a).then(function(a){this.data=a,this.sandbox.emit("sulu.tab.saved",a)}.bind(this))},setHeaderBar:function(a){var b=!a,c=!a,d=!!a&&!this.data.publishedState;this.setSaveToolbarItems.call(this,"saveDraft",b),this.setSaveToolbarItems.call(this,"savePublish",c),this.setSaveToolbarItems.call(this,"publish",d),this.setSaveToolbarItems.call(this,"save",!!b||!!c||!!d),this.saved=a},setSaveToolbarItems:function(a,b){this.sandbox.emit("sulu.header.toolbar.item."+(b?"enable":"disable"),a,!1)},loadingSave:function(){this.saveState="loading",this.sandbox.emit("sulu.header.toolbar.item.loading","save")},afterSave:function(a,b){this.setHeaderBar(!0),this.sandbox.emit("sulu.header.saved",b),"back"===a?this.toList():"new"===a?this.toAdd():this.options.id||this.toEdit(this.options.locale,b.id)},showDraftLabel:function(){this.sandbox.emit("sulu.header.tabs.label.hide"),this.data.id&&!this.data.publishedState&&(this.setHeaderBar(!0),c.find(this.data.changer).then(function(a){this.sandbox.emit("sulu.header.tabs.label.show",this.sandbox.util.sprintf(this.sandbox.translate(this.translations.draftLabel),{changed:this.sandbox.date.format(this.data.changed,!0),user:a.username}))}.bind(this)))},getUrl:function(a){var c=b.template(this.defaults.templates.url,{id:this.options.id,locale:this.options.locale});return a&&(c+="&action="+a),c},loadComponentData:function(){var b=a.Deferred();return this.options.id?(this.sandbox.util.load(this.getUrl()).done(function(a){b.resolve(a)}),b):(b.resolve({}),b)}}}); \ No newline at end of file diff --git a/Resources/public/dist/components/articles/list/main.js b/Resources/public/dist/components/articles/list/main.js index 807fb09e9..ad4fe2133 100644 --- a/Resources/public/dist/components/articles/list/main.js +++ b/Resources/public/dist/components/articles/list/main.js @@ -1 +1 @@ -define(["underscore"],function(a){"use strict";var b={options:{config:{}},templates:{list:['
','
','
','
','
'].join("")},translations:{headline:"sulu_article.list.title"}};return{defaults:b,header:function(){var b,c=this.options.config.types,d={icon:"plus-circle",title:"public.add-new"},e=!1;return 1===c.length?d.callback=function(){this.toAdd(c[0])}.bind(this):(d.dropdownItems=a.map(c,function(a){return{title:a,callback:function(){this.toAdd(a)}.bind(this)}}.bind(this)),b=a.map(c,function(a){return{id:a,name:a,key:a}}),e={componentOptions:{callback:this.typeChange.bind(this),preselector:"name",preselect:this.options.type},data:b}),{title:this.translations.headline,underline:!1,noBack:!0,tabs:e,toolbar:{buttons:{addArticle:{options:d},deleteSelected:{}},languageChanger:{data:this.options.config.languageChanger,preSelected:this.options.locale}}}},layout:{content:{width:"max"}},initialize:function(){this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"article","/admin/api/articles/fields",{el:this.$find(".list-toolbar-container"),instanceName:"articles",template:this.sandbox.sulu.buttons.get({settings:{options:{dropdownItems:[{type:"columnOptions"}]}}})},{el:this.sandbox.dom.find(".datagrid-container"),url:"/admin/api/articles?locale="+this.options.locale+"&type="+this.options.type,searchInstanceName:"articles",searchFields:["title"],resultKey:"articles",instanceName:"articles",actionCallback:function(a){this.toEdit(a)}.bind(this),viewOptions:{table:{actionIconColumn:"title"}}})},toEdit:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/edit:"+a+"/details")},toAdd:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/add"+(this.options.config.types.length>1?":"+a:""))},toList:function(a){this.sandbox.emit("sulu.router.navigate","articles/"+(a||this.options.locale))},deleteItems:function(b){this.sandbox.util.save("/admin/api/articles?ids="+b.join(","),"DELETE").then(function(){a.each(b,function(a){this.sandbox.emit("husky.datagrid.articles.record.remove",a)}.bind(this))}.bind(this))},typeChange:function(a){this.sandbox.emit("husky.datagrid.articles.url.update",{type:a.id}),this.sandbox.emit("sulu.router.navigate","articles:"+a.id+"/"+this.options.locale,!1,!1)},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.articles.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this)),this.sandbox.on("sulu.toolbar.delete",function(){this.sandbox.emit("husky.datagrid.articles.items.get-selected",this.deleteItems.bind(this))}.bind(this)),this.sandbox.on("sulu.header.language-changed",function(a){this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey,a.id),this.toList(a.id)}.bind(this))}}}); \ No newline at end of file +define(["underscore","config"],function(a,b){"use strict";var c={options:{config:{}},templates:{list:['
','
','
','
','
'].join("")},translations:{headline:"sulu_article.list.title"}};return{defaults:c,header:function(){var b,c=this.options.config.types,d=this.options.config.typeNames,e={icon:"plus-circle",title:"public.add-new"},f=!1;return 1===d.length?e.callback=function(){this.toAdd(d[0])}.bind(this):(e.dropdownItems=a.map(d,function(a){return{title:c[a].title,callback:function(){this.toAdd(a)}.bind(this)}}.bind(this)),b=a.map(d,function(a){return{id:a,name:c[a].title,key:a}}),f={componentOptions:{callback:this.typeChange.bind(this),preselector:"name",preselect:this.options.type},data:b}),{noBack:!0,tabs:f,toolbar:{buttons:{addArticle:{options:e},deleteSelected:{}},languageChanger:{data:this.options.config.languageChanger,preSelected:this.options.locale}}}},layout:{content:{width:"max"}},initialize:function(){this.render(),this.bindCustomEvents()},render:function(){this.$el.html(this.templates.list()),this.sandbox.sulu.initListToolbarAndList.call(this,"article","/admin/api/articles/fields",{el:this.$find(".list-toolbar-container"),instanceName:"articles",template:this.sandbox.sulu.buttons.get({settings:{options:{dropdownItems:[{type:"columnOptions"}]}}})},{el:this.sandbox.dom.find(".datagrid-container"),url:"/admin/api/articles?locale="+this.options.locale+"&type="+this.options.type,searchInstanceName:"articles",searchFields:["title"],resultKey:"articles",instanceName:"articles",actionCallback:function(a){this.toEdit(a)}.bind(this),viewOptions:{table:{actionIconColumn:"title"}}})},toEdit:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/edit:"+a+"/details")},toAdd:function(a,b){this.sandbox.emit("sulu.router.navigate","articles/"+(b||this.options.locale)+"/add"+(this.options.config.typeNames.length>1?":"+a:""))},toList:function(a){this.sandbox.emit("sulu.router.navigate","articles/"+(a||this.options.locale))},deleteItems:function(b){this.sandbox.util.save("/admin/api/articles?ids="+b.join(","),"DELETE").then(function(){a.each(b,function(a){this.sandbox.emit("husky.datagrid.articles.record.remove",a)}.bind(this))}.bind(this))},typeChange:function(a){this.sandbox.emit("husky.datagrid.articles.url.update",{type:a.id}),this.sandbox.emit("sulu.router.navigate","articles:"+a.id+"/"+this.options.locale,!1,!1)},bindCustomEvents:function(){this.sandbox.on("husky.datagrid.articles.number.selections",function(a){var b=a>0?"enable":"disable";this.sandbox.emit("sulu.header.toolbar.item."+b,"deleteSelected",!1)}.bind(this)),this.sandbox.on("sulu.toolbar.delete",function(){this.sandbox.emit("husky.datagrid.articles.items.get-selected",this.deleteItems.bind(this))}.bind(this)),this.sandbox.on("sulu.header.language-changed",function(a){this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey,a.id),this.toList(a.id)}.bind(this))}}}); \ No newline at end of file diff --git a/Resources/public/dist/main.js b/Resources/public/dist/main.js index 45d49ec13..bec44eee9 100644 --- a/Resources/public/dist/main.js +++ b/Resources/public/dist/main.js @@ -1 +1 @@ -require.config({paths:{suluarticle:"../../suluarticle/dist",suluarticlecss:"../../suluarticle/css"}}),define(["underscore","config"],function(a,b){"use strict";var c=function(){var c=b.get("sulu-content").locales,d=[];return a.each(c,function(a){d=d.concat(Object.keys(a))}),d};return{name:"Sulu Article Bundle",initialize:function(d){d.components.addSource("suluarticle","/bundles/suluarticle/dist/components");var e=c(),f={defaultLocale:e[0],locales:e,languageChanger:a.map(e,function(a){return{id:a,title:a}}),settingsKey:"articleLanguage",types:Object.keys(b.get("sulu_article.types"))};b.set("sulu_article",f);var g=function(){return d.sandbox.sulu.getUserSetting(f.settingsKey)||f.defaultLocale};1===f.types.length?(d.sandbox.mvc.routes.push({route:"articles",callback:function(){return d.sandbox.emit("sulu.router.navigate","articles/"+g())}}),d.sandbox.mvc.routes.push({route:"articles/:locale",callback:function(a){return'
"}}),d.sandbox.mvc.routes.push({route:"articles/:locale/add",callback:function(a,b){return'
"}})):(d.sandbox.mvc.routes.push({route:"articles",callback:function(){return d.sandbox.emit("sulu.router.navigate","articles:"+f.types[0]+"/"+g())}}),d.sandbox.mvc.routes.push({route:"articles::type",callback:function(a){return d.sandbox.emit("sulu.router.navigate","articles:"+a+"/"+g())}}),d.sandbox.mvc.routes.push({route:"articles::type/:locale",callback:function(a,b){return'
'}}),d.sandbox.mvc.routes.push({route:"articles/:locale/add::type",callback:function(a,b){return'
'}})),d.sandbox.mvc.routes.push({route:"articles/:locale/edit::id/:content",callback:function(a,b){return'
"}})}}}); \ No newline at end of file +require.config({paths:{suluarticle:"../../suluarticle/dist",suluarticlecss:"../../suluarticle/css"}}),define(["underscore","config"],function(a,b){"use strict";var c=function(){var c=b.get("sulu-content").locales,d=[];return a.each(c,function(a){d=d.concat(Object.keys(a))}),d};return{name:"Sulu Article Bundle",initialize:function(d){d.components.addSource("suluarticle","/bundles/suluarticle/dist/components");var e=c(),f={defaultLocale:e[0],locales:e,languageChanger:a.map(e,function(a){return{id:a,title:a}}),settingsKey:"articleLanguage",typeNames:Object.keys(b.get("sulu_article.types")),types:b.get("sulu_article.types")};b.set("sulu_article",f);var g=function(){return d.sandbox.sulu.getUserSetting(f.settingsKey)||f.defaultLocale};1===f.typeNames.length?(d.sandbox.mvc.routes.push({route:"articles",callback:function(){return d.sandbox.emit("sulu.router.navigate","articles/"+g())}}),d.sandbox.mvc.routes.push({route:"articles/:locale",callback:function(a){return'
"}}),d.sandbox.mvc.routes.push({route:"articles/:locale/add",callback:function(a,b){return'
"}})):(d.sandbox.mvc.routes.push({route:"articles",callback:function(){return d.sandbox.emit("sulu.router.navigate","articles:"+f.typeNames[0]+"/"+g())}}),d.sandbox.mvc.routes.push({route:"articles::type",callback:function(a){return d.sandbox.emit("sulu.router.navigate","articles:"+a+"/"+g())}}),d.sandbox.mvc.routes.push({route:"articles::type/:locale",callback:function(a,b){return'
'}}),d.sandbox.mvc.routes.push({route:"articles/:locale/add::type",callback:function(a,b){return'
'}})),d.sandbox.mvc.routes.push({route:"articles/:locale/edit::id/:content",callback:function(a,b){return'
"}})}}}); \ No newline at end of file diff --git a/Resources/public/js/components/articles/edit/details/main.js b/Resources/public/js/components/articles/edit/details/main.js index 7a714391c..87d1c5e72 100644 --- a/Resources/public/js/components/articles/edit/details/main.js +++ b/Resources/public/js/components/articles/edit/details/main.js @@ -107,8 +107,7 @@ define(['underscore', 'jquery', 'config'], function(_, $, Config) { loadFormTemplate: function(template) { if (!template) { - var types = Config.get('sulu_article.types'); - template = types[(this.options.type || this.data.type)]; + template = this.options.config.types[(this.options.type || this.data.type)].default; } this.template = template; diff --git a/Resources/public/js/components/articles/edit/main.js b/Resources/public/js/components/articles/edit/main.js index 25a3cac4e..89f6b98b9 100644 --- a/Resources/public/js/components/articles/edit/main.js +++ b/Resources/public/js/components/articles/edit/main.js @@ -106,7 +106,7 @@ define(['jquery', 'underscore', 'sulusecurity/services/user-manager'], function( }, toList: function() { - if (this.options.config.types.length === 1) { + if (this.options.config.typeNames.length === 1) { this.sandbox.emit('sulu.router.navigate', 'articles/' + this.options.locale); } else { this.sandbox.emit('sulu.router.navigate', 'articles:' + (this.options.type || this.data.type) + '/' + this.options.locale); @@ -114,7 +114,7 @@ define(['jquery', 'underscore', 'sulusecurity/services/user-manager'], function( }, toAdd: function() { - if (this.options.config.types.length === 1) { + if (this.options.config.typeNames.length === 1) { this.sandbox.emit('sulu.router.navigate', 'articles/' + this.options.locale + '/add', true, true); } else { this.sandbox.emit('sulu.router.navigate', 'articles/' + this.options.locale + '/add:' + (this.options.type || this.data.type), true, true); diff --git a/Resources/public/js/components/articles/list/main.js b/Resources/public/js/components/articles/list/main.js index 7d0bff340..e438fad49 100644 --- a/Resources/public/js/components/articles/list/main.js +++ b/Resources/public/js/components/articles/list/main.js @@ -7,7 +7,7 @@ * with this source code in the file LICENSE. */ -define(['underscore'], function(_) { +define(['underscore', 'config'], function(_, Config) { 'use strict'; @@ -37,6 +37,7 @@ define(['underscore'], function(_) { header: function() { var types = this.options.config.types, + typeNames = this.options.config.typeNames, button = { icon: 'plus-circle', title: 'public.add-new' @@ -44,24 +45,24 @@ define(['underscore'], function(_) { tabs = false, items; - if (types.length === 1) { + if (typeNames.length === 1) { button.callback = function() { - this.toAdd(types[0]); + this.toAdd(typeNames[0]); }.bind(this); } else { - button.dropdownItems = _.map(types, function(item) { + button.dropdownItems = _.map(typeNames, function(type) { return { - title: item, + title: types[type].title, callback: function() { - this.toAdd(item); + this.toAdd(type); }.bind(this) }; }.bind(this)); - items = _.map(types, function(type) { + items = _.map(typeNames, function(type) { return { id: type, - name: type, + name: types[type].title, key: type }; }); @@ -77,9 +78,6 @@ define(['underscore'], function(_) { } return { - title: this.translations.headline, - underline: false, - noBack: true, tabs: tabs, @@ -155,7 +153,7 @@ define(['underscore'], function(_) { }, toAdd: function(type, locale) { - this.sandbox.emit('sulu.router.navigate', 'articles/' + (locale || this.options.locale) + '/add' + (this.options.config.types.length > 1 ? (':' + type) : '')); + this.sandbox.emit('sulu.router.navigate', 'articles/' + (locale || this.options.locale) + '/add' + (this.options.config.typeNames.length > 1 ? (':' + type) : '')); }, toList: function(locale) { diff --git a/Resources/public/js/main.js b/Resources/public/js/main.js index 0181c0f1c..22af4868e 100644 --- a/Resources/public/js/main.js +++ b/Resources/public/js/main.js @@ -45,7 +45,8 @@ define(['underscore', 'config'], function(_, Config) { return {id: locale, title: locale}; }), settingsKey: 'articleLanguage', - types: Object.keys(Config.get('sulu_article.types')) + typeNames: Object.keys(Config.get('sulu_article.types')), + types: Config.get('sulu_article.types') }; Config.set('sulu_article', config); @@ -58,7 +59,7 @@ define(['underscore', 'config'], function(_, Config) { return app.sandbox.sulu.getUserSetting(config.settingsKey) || config.defaultLocale; }; - if (config.types.length === 1) { + if (config.typeNames.length === 1) { app.sandbox.mvc.routes.push({ route: 'articles', callback: function() { @@ -69,21 +70,21 @@ define(['underscore', 'config'], function(_, Config) { app.sandbox.mvc.routes.push({ route: 'articles/:locale', callback: function(locale) { - return '
'; + return '
'; } }); app.sandbox.mvc.routes.push({ route: 'articles/:locale/add', callback: function(locale, type) { - return '
'; + return '
'; } }); } else { app.sandbox.mvc.routes.push({ route: 'articles', callback: function() { - return app.sandbox.emit('sulu.router.navigate', 'articles:' + config.types[0] + '/' + getLocale()); + return app.sandbox.emit('sulu.router.navigate', 'articles:' + config.typeNames[0] + '/' + getLocale()); } });