diff --git a/Admin/ArticleJsConfig.php b/Admin/ArticleJsConfig.php index 2801f31f0..110611c1c 100644 --- a/Admin/ArticleJsConfig.php +++ b/Admin/ArticleJsConfig.php @@ -14,6 +14,7 @@ use Sulu\Bundle\AdminBundle\Admin\JsConfigInterface; use Sulu\Bundle\ArticleBundle\Util\TypeTrait; use Sulu\Component\Content\Compat\StructureManagerInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; /** * Provides js-configuration. @@ -22,17 +23,34 @@ class ArticleJsConfig implements JsConfigInterface { use TypeTrait; + /** + * @var TokenStorageInterface + */ + private $tokenStorage; + /** * @var StructureManagerInterface */ private $structureManager; /** + * @var array + */ + private $typeConfiguration; + + /** + * @param TokenStorageInterface $tokenStorage * @param StructureManagerInterface $structureManager + * @param $typeConfiguration */ - public function __construct(StructureManagerInterface $structureManager) - { + public function __construct( + TokenStorageInterface $tokenStorage, + StructureManagerInterface $structureManager, + $typeConfiguration + ) { + $this->tokenStorage = $tokenStorage; $this->structureManager = $structureManager; + $this->typeConfiguration = $typeConfiguration; } /** @@ -40,11 +58,16 @@ public function __construct(StructureManagerInterface $structureManager) */ public function getParameters() { + $locale = $this->getLocale(); + $types = []; 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, $locale), + ]; } } @@ -58,4 +81,33 @@ public function getName() { return 'sulu_article.types'; } + + /** + * Returns title for given type. + * + * @param string $type + * @param string $locale + * + * @return string + */ + private function getTitle($type, $locale) + { + if (!array_key_exists($type, $this->typeConfiguration) + || !array_key_exists($locale, $this->typeConfiguration[$type]['translations']) + ) { + return $type; + } + + return $this->typeConfiguration[$type]['translations'][$locale]; + } + + /** + * Returns locale. + * + * @return string + */ + private function getLocale() + { + return $this->tokenStorage->getToken()->getUser()->getLocale(); + } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 979c60ebe..9eba7fa54 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,7 +25,20 @@ 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() + ->arrayNode('translations') + ->useAttributeAsKey('locale') + ->prototype('scalar')->end() + ->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..906a15a9f 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -17,7 +17,9 @@ + + %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 65646691e..0b8b69777 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";return{name:"Sulu Article Bundle",initialize:function(c){c.components.addSource("suluarticle","/bundles/suluarticle/dist/components");var d=Object.keys(b.get("sulu-content").locales),e={defaultLocale:d[0],locales:d,languageChanger:a.map(d,function(a){return{id:a,title:a}}),settingsKey:"articleLanguage",types:Object.keys(b.get("sulu_article.types"))};b.set("sulu_article",e);var f=function(){return c.sandbox.sulu.getUserSetting(e.settingsKey)||e.defaultLocale};1===e.types.length?(c.sandbox.mvc.routes.push({route:"articles",callback:function(){return c.sandbox.emit("sulu.router.navigate","articles/"+f())}}),c.sandbox.mvc.routes.push({route:"articles/:locale",callback:function(a){return'
"}}),c.sandbox.mvc.routes.push({route:"articles/:locale/add",callback:function(a,b){return'
"}})):(c.sandbox.mvc.routes.push({route:"articles",callback:function(){return c.sandbox.emit("sulu.router.navigate","articles:"+e.types[0]+"/"+f())}}),c.sandbox.mvc.routes.push({route:"articles::type",callback:function(a){return c.sandbox.emit("sulu.router.navigate","articles:"+a+"/"+f())}}),c.sandbox.mvc.routes.push({route:"articles::type/:locale",callback:function(a,b){return'
'}}),c.sandbox.mvc.routes.push({route:"articles/:locale/add::type",callback:function(a,b){return'
'}})),c.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";return{name:"Sulu Article Bundle",initialize:function(c){c.components.addSource("suluarticle","/bundles/suluarticle/dist/components");var d=Object.keys(b.get("sulu-content").locales),e={defaultLocale:d[0],locales:d,languageChanger:a.map(d,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",e);var f=function(){return c.sandbox.sulu.getUserSetting(e.settingsKey)||e.defaultLocale};1===e.typeNames.length?(c.sandbox.mvc.routes.push({route:"articles",callback:function(){return c.sandbox.emit("sulu.router.navigate","articles/"+f())}}),c.sandbox.mvc.routes.push({route:"articles/:locale",callback:function(a){return'
"}}),c.sandbox.mvc.routes.push({route:"articles/:locale/add",callback:function(a,b){return'
"}})):(c.sandbox.mvc.routes.push({route:"articles",callback:function(){return c.sandbox.emit("sulu.router.navigate","articles:"+e.typeNames[0]+"/"+f())}}),c.sandbox.mvc.routes.push({route:"articles::type",callback:function(a){return c.sandbox.emit("sulu.router.navigate","articles:"+a+"/"+f())}}),c.sandbox.mvc.routes.push({route:"articles::type/:locale",callback:function(a,b){return'
'}}),c.sandbox.mvc.routes.push({route:"articles/:locale/add::type",callback:function(a,b){return'
'}})),c.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 4332ba665..cf05cdbf6 100644 --- a/Resources/public/js/main.js +++ b/Resources/public/js/main.js @@ -34,7 +34,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); @@ -47,7 +48,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() { @@ -58,21 +59,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()); } });