diff --git a/Resources/public/dist/components/articles/edit/settings/main.js b/Resources/public/dist/components/articles/edit/settings/main.js index 4d2cf720e..ac6abcf8d 100644 --- a/Resources/public/dist/components/articles/edit/settings/main.js +++ b/Resources/public/dist/components/articles/edit/settings/main.js @@ -1 +1 @@ -define(["underscore","jquery","sulusecurity/components/users/models/user","sulucontact/models/contact","services/suluarticle/article-manager","text!/admin/articles/template/settings.html"],function(a,b,c,d,e,f){"use strict";var g={templates:{form:f},translations:{author:"sulu_article.author",authored:"sulu_article.form.settings.changelog.authored",authoredOnly:"sulu_article.form.settings.changelog.authored-only",changelog:"sulu_article.form.settings.changelog",changed:"sulu_article.form.settings.changelog.changed",changedOnly:"sulu_article.form.settings.changelog.changed-only",created:"sulu_article.form.settings.changelog.created",createdOnly:"sulu_article.form.settings.changelog.created-only"}};return{type:"form-tab",defaults:g,authorFullname:null,parseData:function(a){return{id:a.id,author:a.author,authored:a.authored,creator:a.creator,changer:a.changer,created:a.created,changed:a.changed}},rendered:function(){this.updateChangelog(this.data),this.bindDomEvents()},submit:function(b){if(this.sandbox.form.validate(this.formId)){var c=this.sandbox.form.getData(this.formId);a.each(c,function(a,b){this.data[b]=a}.bind(this)),this.save(this.data,b)}},save:function(a,b){e.save(a,a.id,this.options.locale,b).then(function(b){this.saved(a),this.sandbox.emit("sulu.tab.saved",b.id,b)}.bind(this)).fail(function(b){this.sandbox.emit("sulu.article.error",b.status,a)}.bind(this))},saved:function(a){this.data=this.parseData(a)},getTemplate:function(){return this.templates.form({translations:this.translations})},getFormId:function(){return"#settings-form"},listenForChange:function(){this.sandbox.dom.on(this.formId,"change keyup",this.setDirty.bind(this)),this.sandbox.on("sulu.content.changed",this.setDirty.bind(this)),this.sandbox.on("husky.ckeditor.changed",this.setDirty.bind(this))},setAuthorChangelog:function(a,b){var c,d=this.sandbox.date.format(b);a=a||this.authorFullname,a?(this.authorFullname=a,c=this.sandbox.util.sprintf(this.translations.authored,{author:a,authored:d})):c=this.sandbox.util.sprintf(this.translations.authoredOnly,{authored:d}),this.sandbox.dom.text("#author",c)},setCreationChangelog:function(a,b){var c,d=this.sandbox.date.format(b,!0);c=a?this.sandbox.util.sprintf(this.translations.created,{creator:a,created:d}):this.sandbox.util.sprintf(this.translations.createdOnly,{created:d}),this.sandbox.dom.text("#created",c)},setChangeChangelog:function(a,b){var c,d=this.sandbox.date.format(b,!0);c=a?this.sandbox.util.sprintf(this.translations.changed,{changer:a,changed:d}):this.sandbox.util.sprintf(this.translations.changedOnly,{changed:d}),this.sandbox.dom.text("#changed",c)},updateChangelog:function(a){var c=b.Deferred(),d=b.Deferred(),e=b.Deferred();a.creator===a.changer?this.loadUser(a.creator).done(function(b){c.resolve(b.get("fullName"),a.created),d.resolve(b.get("fullName"),a.changed)}.bind(this)).fail(function(){c.resolve(null,a.created),d.resolve(null,a.changed)}.bind(this)):(this.loadUser(a.creator).done(function(b){c.resolve(b.get("fullName"),a.created)}.bind(this)).fail(function(){c.resolve(null,a.created)}.bind(this)),this.loadUser(a.changer).done(function(b){d.resolve(b.get("fullName"),a.changed)}.bind(this)).fail(function(){d.resolve(null,a.changed)}.bind(this))),a.author?this.loadContact(a.author).done(function(b){e.resolve(b.get("fullName"),new Date(a.authored))}.bind(this)).fail(function(){e.resolve(null,new Date(a.authored))}.bind(this)):e.resolve(null,new Date(a.authored)),this.sandbox.data.when(c,d,e).then(function(a,b,c){this.setCreationChangelog(a[0],a[1]),this.setChangeChangelog(b[0],b[1]),this.setAuthorChangelog(c[0],c[1]),this.sandbox.dom.show("#changelog-container")}.bind(this))},loadUser:function(a){var d=b.Deferred(),e=new c({id:a});return e.fetch({global:!1,success:function(a){d.resolve(a)}.bind(this),error:function(){d.reject()}.bind(this)}),d},loadContact:function(a){var c=b.Deferred(),e=new d({id:a});return e.fetch({global:!1,success:function(a){c.resolve(a)}.bind(this),error:function(){c.reject()}.bind(this)}),c},bindDomEvents:function(){this.sandbox.dom.on("#change-author","click",function(){this.openAuthorSelection()}.bind(this))},openAuthorSelection:function(){var a=b("
"),c=b("");this.$el.append(a),this.sandbox.start([{name:"overlay@husky",options:{el:a,instanceName:"author-selection",openOnStart:!0,removeOnClose:!0,skin:"medium",slides:[{title:this.translations.author,okCallback:function(){this.sandbox.emit("sulu_article.get-author")}.bind(this),data:c}]}}]),this.sandbox.once("husky.overlay.author-selection.initialized",function(){this.sandbox.start([{name:"articles/edit/settings/author-selection@suluarticle",options:{el:c,locale:this.options.locale,data:{author:this.data.author,authored:this.data.authored},selectCallback:function(a){this.setAuthor(a),this.sandbox.emit("husky.overlay.author-selection.close")}.bind(this)}}])}.bind(this))},setAuthor:function(a){return this.setDirty(),this.data.authored=a.authored,a.authorItem?(this.setAuthorChangelog(a.authorItem.firstName+" "+a.authorItem.lastName,new Date(a.authored)),void(this.data.author=a.author)):void this.setAuthorChangelog(null,new Date(a.authored))}}}); \ No newline at end of file +define(["underscore","jquery","sulusecurity/components/users/models/user","sulucontact/models/contact","services/suluarticle/article-manager","text!/admin/articles/template/settings.html"],function(a,b,c,d,e,f){"use strict";var g={templates:{form:f},translations:{author:"sulu_article.author",authored:"sulu_article.form.settings.changelog.authored",authoredOnly:"sulu_article.form.settings.changelog.authored-only",changelog:"sulu_article.form.settings.changelog",changed:"sulu_article.form.settings.changelog.changed",changedOnly:"sulu_article.form.settings.changelog.changed-only",created:"sulu_article.form.settings.changelog.created",createdOnly:"sulu_article.form.settings.changelog.created-only"}};return{type:"form-tab",defaults:g,authorFullname:null,parseData:function(a){return{id:a.id,author:a.author,authored:a.authored,creator:a.creator,changer:a.changer,created:a.created,changed:a.changed}},rendered:function(){this.updateChangelog(this.data),this.bindDomEvents()},submit:function(b){if(this.sandbox.form.validate(this.formId)){var c=this.sandbox.form.getData(this.formId);a.each(c,function(a,b){this.data[b]=a}.bind(this)),this.save(this.data,b)}},save:function(a,b){e.save(a,a.id,this.options.locale,b).then(function(b){this.saved(a),this.sandbox.emit("sulu.tab.saved",b.id,b)}.bind(this)).fail(function(b){this.sandbox.emit("sulu.article.error",b.status,a)}.bind(this))},saved:function(a){this.data=this.parseData(a)},getTemplate:function(){return this.templates.form({translations:this.translations})},getFormId:function(){return"#settings-form"},listenForChange:function(){this.sandbox.dom.on(this.formId,"change keyup",this.setDirty.bind(this)),this.sandbox.on("sulu.content.changed",this.setDirty.bind(this)),this.sandbox.on("husky.ckeditor.changed",this.setDirty.bind(this))},setAuthorChangelog:function(a,b){var c,d=this.sandbox.date.format(b);a=a||this.authorFullname,a?(this.authorFullname=a,c=this.sandbox.util.sprintf(this.translations.authored,{author:a,authored:d})):c=this.sandbox.util.sprintf(this.translations.authoredOnly,{authored:d}),this.sandbox.dom.text("#author",c)},setCreationChangelog:function(a,b){var c,d=this.sandbox.date.format(b,!0);c=a?this.sandbox.util.sprintf(this.translations.created,{creator:a,created:d}):this.sandbox.util.sprintf(this.translations.createdOnly,{created:d}),this.sandbox.dom.text("#created",c)},setChangeChangelog:function(a,b){var c,d=this.sandbox.date.format(b,!0);c=a?this.sandbox.util.sprintf(this.translations.changed,{changer:a,changed:d}):this.sandbox.util.sprintf(this.translations.changedOnly,{changed:d}),this.sandbox.dom.text("#changed",c)},updateChangelog:function(a){var c=b.Deferred(),d=b.Deferred(),e=b.Deferred();a.creator&&a.changer&&a.creator===a.changer?this.loadUser(a.creator).done(function(b){c.resolve(b.get("fullName"),a.created),d.resolve(b.get("fullName"),a.changed)}.bind(this)).fail(function(){c.resolve(null,a.created),d.resolve(null,a.changed)}.bind(this)):(this.loadUser(a.creator).done(function(b){c.resolve(b.get("fullName"),a.created)}.bind(this)).fail(function(){c.resolve(null,a.created)}.bind(this)),this.loadUser(a.changer).done(function(b){d.resolve(b.get("fullName"),a.changed)}.bind(this)).fail(function(){d.resolve(null,a.changed)}.bind(this))),a.author?this.loadContact(a.author).done(function(b){e.resolve(b.get("fullName"),new Date(a.authored))}.bind(this)).fail(function(){e.resolve(null,new Date(a.authored))}.bind(this)):e.resolve(null,new Date(a.authored)),this.sandbox.data.when(c,d,e).then(function(a,b,c){this.setCreationChangelog(a[0],a[1]),this.setChangeChangelog(b[0],b[1]),this.setAuthorChangelog(c[0],c[1]),this.sandbox.dom.show("#changelog-container")}.bind(this))},loadUser:function(a){var d=b.Deferred();if(!a)return d.reject(),d;var e=new c({id:a});return e.fetch({global:!1,success:function(a){d.resolve(a)}.bind(this),error:function(){d.reject()}.bind(this)}),d},loadContact:function(a){var c=b.Deferred(),e=new d({id:a});return e.fetch({global:!1,success:function(a){c.resolve(a)}.bind(this),error:function(){c.reject()}.bind(this)}),c},bindDomEvents:function(){this.sandbox.dom.on("#change-author","click",function(){this.openAuthorSelection()}.bind(this))},openAuthorSelection:function(){var a=b(""),c=b("");this.$el.append(a),this.sandbox.start([{name:"overlay@husky",options:{el:a,instanceName:"author-selection",openOnStart:!0,removeOnClose:!0,skin:"medium",slides:[{title:this.translations.author,okCallback:function(){this.sandbox.emit("sulu_article.get-author")}.bind(this),data:c}]}}]),this.sandbox.once("husky.overlay.author-selection.initialized",function(){this.sandbox.start([{name:"articles/edit/settings/author-selection@suluarticle",options:{el:c,locale:this.options.locale,data:{author:this.data.author,authored:this.data.authored},selectCallback:function(a){this.setAuthor(a),this.sandbox.emit("husky.overlay.author-selection.close")}.bind(this)}}])}.bind(this))},setAuthor:function(a){return this.setDirty(),this.data.authored=a.authored,a.authorItem?(this.setAuthorChangelog(a.authorItem.firstName+" "+a.authorItem.lastName,new Date(a.authored)),void(this.data.author=a.author)):void this.setAuthorChangelog(null,new Date(a.authored))}}}); \ No newline at end of file diff --git a/Resources/public/js/components/articles/edit/settings/main.js b/Resources/public/js/components/articles/edit/settings/main.js index 486e2513c..6f9ece79c 100644 --- a/Resources/public/js/components/articles/edit/settings/main.js +++ b/Resources/public/js/components/articles/edit/settings/main.js @@ -229,7 +229,7 @@ define([ var changerDef = $.Deferred(); var authorDef = $.Deferred(); - if (data.creator === data.changer) { + if (data.creator && data.changer && data.creator === data.changer) { this.loadUser(data.creator).done(function(model) { creatorDef.resolve(model.get('fullName'), data.created); changerDef.resolve(model.get('fullName'), data.changed); @@ -279,9 +279,16 @@ define([ * @return {*} */ loadUser: function(id) { - var deferred = $.Deferred(), - user = new User({id: id}); + var deferred = $.Deferred(); + + // when no id set return here + if (!id) { + deferred.reject(); + + return deferred; + } + var user = new User({id: id}); user.fetch({ global: false,