From de5c3fc256210a7b1e815cbf7f0655d19c89e96a Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Tue, 7 Mar 2017 09:28:30 +0100 Subject: [PATCH 1/3] Fixed bug when an article has no creator/changer/author --- .../components/articles/edit/settings/main.js | 2 +- .../components/articles/edit/settings/main.js | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Resources/public/dist/components/articles/edit/settings/main.js b/Resources/public/dist/components/articles/edit/settings/main.js index 4d2cf720e..5d2114677 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){var e=new c({id:a});e.fetch({global:!1,success:function(a){d.resolve(a)}.bind(this),error:function(){d.reject()}.bind(this)})}else d.reject();return 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..f38e204da 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,20 +279,25 @@ define([ * @return {*} */ loadUser: function(id) { - var deferred = $.Deferred(), - user = new User({id: id}); + var deferred = $.Deferred(); - user.fetch({ - global: false, + if (id) { + var user = new User({id: id}); - success: function(model) { - deferred.resolve(model) - }.bind(this), + user.fetch({ + global: false, - error: function() { - deferred.reject(); - }.bind(this) - }); + success: function(model) { + deferred.resolve(model) + }.bind(this), + + error: function() { + deferred.reject(); + }.bind(this) + }); + } else { + deferred.reject(); + } return deferred; }, From 4a15ec290d7c8750426260add7780557ce6db98b Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Tue, 7 Mar 2017 09:58:59 +0100 Subject: [PATCH 2/3] Code clean up --- .../components/articles/edit/settings/main.js | 2 +- .../components/articles/edit/settings/main.js | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Resources/public/dist/components/articles/edit/settings/main.js b/Resources/public/dist/components/articles/edit/settings/main.js index 5d2114677..ff2f6c4f0 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&&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){var e=new c({id:a});e.fetch({global:!1,success:function(a){d.resolve(a)}.bind(this),error:function(){d.reject()}.bind(this)})}else d.reject();return 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});e.fetch({global:!1,success:function(a){d.resolve(a)}.bind(this),error:function(){d.reject()}.bind(this)})},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 f38e204da..b5c43a002 100644 --- a/Resources/public/js/components/articles/edit/settings/main.js +++ b/Resources/public/js/components/articles/edit/settings/main.js @@ -281,25 +281,25 @@ define([ loadUser: function(id) { var deferred = $.Deferred(); - if (id) { - var user = new User({id: id}); + // when no id set return here + if (!id) { + deferred.reject(); - user.fetch({ - global: false, + return deferred; + } - success: function(model) { - deferred.resolve(model) - }.bind(this), + var user = new User({id: id}); + user.fetch({ + global: false, - error: function() { - deferred.reject(); - }.bind(this) - }); - } else { - deferred.reject(); - } + success: function(model) { + deferred.resolve(model) + }.bind(this), - return deferred; + error: function() { + deferred.reject(); + }.bind(this) + }); }, /** From ff8b9c7b57addcee1a9ae47337a98687731f9b4c Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Tue, 7 Mar 2017 10:03:17 +0100 Subject: [PATCH 3/3] Added missing return statement --- Resources/public/dist/components/articles/edit/settings/main.js | 2 +- Resources/public/js/components/articles/edit/settings/main.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Resources/public/dist/components/articles/edit/settings/main.js b/Resources/public/dist/components/articles/edit/settings/main.js index ff2f6c4f0..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&&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});e.fetch({global:!1,success:function(a){d.resolve(a)}.bind(this),error:function(){d.reject()}.bind(this)})},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 b5c43a002..6f9ece79c 100644 --- a/Resources/public/js/components/articles/edit/settings/main.js +++ b/Resources/public/js/components/articles/edit/settings/main.js @@ -300,6 +300,8 @@ define([ deferred.reject(); }.bind(this) }); + + return deferred; }, /**