diff --git a/js/layout-javascript/agenda-code.js b/js/layout-javascript/agenda-code.js index 8bb7ae4e..fa408793 100644 --- a/js/layout-javascript/agenda-code.js +++ b/js/layout-javascript/agenda-code.js @@ -36,6 +36,7 @@ function DynamicList(id, data) { this.agendaDates = []; this.showBookmarks; this.fetchedAllBookmarks = false; + this.allFilterPropertiesAdded = false; this.searchValue = ''; this.activeFilters = {}; @@ -1029,7 +1030,7 @@ DynamicList.prototype.initialize = function() { }); }) .then(function(records) { - _this.listItems = _this.getPermissions(records); + _this.listItems = records; return _this.Utils.Records.getFields(_this.listItems, _this.data.dataSourceId).then(function(columns) { _this.dataSourceColumns = columns; @@ -1048,12 +1049,13 @@ DynamicList.prototype.initialize = function() { .then(function(response) { _this.listItems = _.uniqBy(response, 'id'); _this.checkIsToOpen(); - _this.modifiedListItems = _this.Utils.Records.addFilterProperties({ + _this.listItems = _this.Utils.Records.addFilterProperties({ records: _this.listItems, config: _this.data }); + _this.allFilterPropertiesAdded = true; - return _this.addFilters(_this.modifiedListItems); + return _this.addFilters(_this.listItems); }).then(function() { _this.parseFilterQueries(); _this.parseSearchQueries(); @@ -1307,10 +1309,14 @@ DynamicList.prototype.groupLoopDataByDate = function(loopData, dateField) { DynamicList.prototype.addSummaryData = function(records) { var _this = this; - var modifiedData = _this.Utils.Records.addFilterProperties({ - records: records, - config: _this.data - }); + var modifiedData = records; + + if (!_this.allFilterPropertiesAdded) { + modifiedData = _this.Utils.Records.addFilterProperties({ + records: modifiedData, + config: _this.data + }); + } // Uses sumamry view settings set by users var loopData = _.map(modifiedData, function(entry) { @@ -1318,8 +1324,6 @@ DynamicList.prototype.addSummaryData = function(records) { id: entry.id, flClasses: entry.data['flClasses'], flFilters: entry.data['flFilters'], - editEntry: entry.editEntry, - deleteEntry: entry.deleteEntry, pollButton: _this.data.pollEnabled && entry.data[_this.data.pollColumn] && entry.data[_this.data.pollColumn] !== '', @@ -1551,16 +1555,16 @@ DynamicList.prototype.getAddPermission = function(data) { return data; }; -DynamicList.prototype.getPermissions = function(entries) { - var _this = this; +DynamicList.prototype.addPermissions = function(entry) { + if (!_.isObject(entry)) { + return entry; + } // Adds flag for Edit and Delete buttons - _.forEach(entries, function(entry) { - entry.editEntry = _this.Utils.Record.isEditable(entry, _this.data, _this.myUserData); - entry.deleteEntry = _this.Utils.Record.isDeletable(entry, _this.data, _this.myUserData); - }); + entry.editEntry = this.Utils.Record.isEditable(entry, this.data, this.myUserData); + entry.deleteEntry = this.Utils.Record.isDeletable(entry, this.data, this.myUserData); - return entries; + return entry; }; DynamicList.prototype.addFilters = function(records) { @@ -1677,7 +1681,7 @@ DynamicList.prototype.getAllBookmarks = function() { }) }).then(function(results) { var bookmarkedIds = _.compact(_.map(results.data, function(record) { - var match = _.get(record, 'data.content.entryId', '').match(/(\d*)-bookmark/); + var match = ((record.data && record.data.content && record.data.content.entryId) || '').match(/(\d*)-bookmark/); return match ? parseInt(match[1], 10) : ''; })); @@ -2519,6 +2523,7 @@ DynamicList.prototype.addDetailViewData = function(entry) { return option.editable; }); + entry = _this.addPermissions(entry); entry.entryDetails = []; // Uses detail view settings not set by users diff --git a/js/layout-javascript/news-feed-code.js b/js/layout-javascript/news-feed-code.js index e3b5203d..e0d25f1e 100644 --- a/js/layout-javascript/news-feed-code.js +++ b/js/layout-javascript/news-feed-code.js @@ -41,6 +41,7 @@ function DynamicList(id, data) { this.isSearching; this.showBookmarks; this.fetchedAllBookmarks = false; + this.allFilterPropertiesAdded = false; this.searchValue = ''; this.activeFilters = {}; @@ -1126,7 +1127,7 @@ DynamicList.prototype.initializeOverlaySocials = function(id) { DynamicList.prototype.getAllBookmarks = function() { var _this = this; - if (_this.fetchedAllBookmarks || !_.get(_this.data, 'social.bookmark') || !_this.data.bookmarkDataSourceId) { + if (_this.fetchedAllBookmarks || !(_this.data.social && _this.data.social.bookmark) || !_this.data.bookmarkDataSourceId) { return Promise.resolve(); } @@ -1152,7 +1153,7 @@ DynamicList.prototype.getAllBookmarks = function() { }) }).then(function(results) { var bookmarkedIds = _.compact(_.map(results.data, function(record) { - var match = _.get(record, 'data.content.entryId', '').match(/(\d*)-bookmark/); + var match = ((record.data && record.data.content && record.data.content.entryId) || '').match(/(\d*)-bookmark/); return match ? parseInt(match[1], 10) : ''; })); @@ -1206,7 +1207,7 @@ DynamicList.prototype.initializeSocials = function(records) { }; DynamicList.prototype.getCommentUsers = function() { - if (!_.get(this.data, 'social.comments')) { + if (!(this.data.social && this.data.social.comments)) { return Promise.resolve(); } @@ -1229,14 +1230,14 @@ DynamicList.prototype.getCommentUsers = function() { _this.allUsers = users; // Update my user data - if (!_.isEmpty(_this.myUserData)) { - var myUser = _.find(_this.allUsers, function(user) { - return _this.myUserData[_this.data.userEmailColumn] === user.data[_this.data.userEmailColumn]; - }); + if (_this.myUserData) { + _this.allUsers.some(function(user) { + if (_this.myUserData[_this.data.userEmailColumn] === user.data[_this.data.userEmailColumn]) { + _this.myUserData = $.extend(true, _this.myUserData, user.data); - if (myUser) { - _this.myUserData = $.extend(true, _this.myUserData, myUser.data); - } + return true; + } + }); } return _this.Utils.Users.getUsersToMention({ @@ -1299,7 +1300,7 @@ DynamicList.prototype.initialize = function() { }); }) .then(function(records) { - _this.listItems = _this.getPermissions(records); + _this.listItems = records; if (!_this.data.detailViewAutoUpdate) { return Promise.resolve(); @@ -1318,12 +1319,13 @@ DynamicList.prototype.initialize = function() { .then(function(response) { _this.listItems = _.uniqBy(response, 'id'); _this.checkIsToOpen(); - _this.modifiedListItems = _this.Utils.Records.addFilterProperties({ + _this.listItems = _this.Utils.Records.addFilterProperties({ records: _this.listItems, config: _this.data }); + _this.allFilterPropertiesAdded = true; - return _this.addFilters(_this.modifiedListItems); + return _this.addFilters(_this.listItems); }) .then(function() { _this.parseFilterQueries(); @@ -1369,7 +1371,7 @@ DynamicList.prototype.parseSearchQueries = function() { var _this = this; if (!_.get(_this.pvSearchQuery, 'value')) { - // Continue to exectute query filters + // Continue to execute query filters return _this.searchData({ initialRender: true }); @@ -1604,17 +1606,20 @@ DynamicList.prototype.renderBaseHTML = function() { DynamicList.prototype.addSummaryData = function(records) { var _this = this; - var modifiedData = _this.Utils.Records.addFilterProperties({ - records: records, - config: _this.data - }); + var modifiedData = records; + + if (!_this.allFilterPropertiesAdded) { + modifiedData = _this.Utils.Records.addFilterProperties({ + records: modifiedData, + config: _this.data + }); + } + var loopData = _.map(modifiedData, function(entry) { var newObject = { id: entry.id, flClasses: entry.data['flClasses'], flFilters: entry.data['flFilters'], - editEntry: entry.editEntry, - deleteEntry: entry.deleteEntry, likesEnabled: entry.likesEnabled, bookmarksEnabled: entry.bookmarksEnabled, commentsEnabled: entry.commentsEnabled, @@ -1707,16 +1712,16 @@ DynamicList.prototype.getAddPermission = function(data) { return data; }; -DynamicList.prototype.getPermissions = function(entries) { - var _this = this; +DynamicList.prototype.addPermissions = function(entry) { + if (!_.isObject(entry)) { + return entry; + } // Adds flag for Edit and Delete buttons - _.forEach(entries, function(entry) { - entry.editEntry = _this.Utils.Record.isEditable(entry, _this.data, _this.myUserData); - entry.deleteEntry = _this.Utils.Record.isDeletable(entry, _this.data, _this.myUserData); - }); + entry.editEntry = this.Utils.Record.isEditable(entry, this.data, this.myUserData); + entry.deleteEntry = this.Utils.Record.isDeletable(entry, this.data, this.myUserData); - return entries; + return entry; }; DynamicList.prototype.addFilters = function(records) { @@ -2012,7 +2017,7 @@ DynamicList.prototype.getLikeIdentifier = function(record) { }; DynamicList.prototype.setupLikeButton = function(options) { - if (!_.get(this.data, 'social.likes')) { + if (!(this.data.social && this.data.social.likes)) { return Promise.resolve(); } @@ -2194,7 +2199,7 @@ DynamicList.prototype.getBookmarkIdentifier = function(record) { }; DynamicList.prototype.setupBookmarkButton = function(options) { - if (!_.get(this.data, 'social.bookmark')) { + if (!(this.data.social && this.data.social.bookmark)) { return Promise.resolve(); } @@ -2335,6 +2340,7 @@ DynamicList.prototype.addDetailViewData = function(entry) { return entry; } + entry = _this.addPermissions(entry); entry.entryDetails = []; // Define detail view data based on user's settings @@ -2575,7 +2581,7 @@ DynamicList.prototype.getCommentIdentifier = function(record) { }; DynamicList.prototype.getEntryComments = function(options) { - if (!_.get(this.data, 'social.comments')) { + if (!(this.data.social && this.data.social.comments)) { return Promise.resolve(); } @@ -2637,7 +2643,7 @@ DynamicList.prototype.connectToUsersDataSource = function() { }; DynamicList.prototype.updateCommentCounter = function(options) { - if (!_.get(this.data, 'social.comments')) { + if (!(this.data.social && this.data.social.comments)) { return; } @@ -2697,7 +2703,7 @@ DynamicList.prototype.showComments = function(id, commentId) { var newDate = new Date(entry.createdAt); var timeInMilliseconds = newDate.getTime(); var userName = _.compact(_.map(_this.data.userNameFields, function(name) { - return _.get(entry, 'data.settings.user.' + name); + return entry.data && entry.data.settings && entry.data.settings.user && entry.data.settings.user[name]; })).join(' ').trim(); entryComments[index].timeInMilliseconds = timeInMilliseconds; @@ -2968,7 +2974,7 @@ DynamicList.prototype.appendTempComment = function(id, value, guid, userFromData var timestamp = (new Date()).toISOString(); var userName = _.compact(_.map(_this.data.userNameFields, function(name) { return _this.myUserData.isSaml2 - ? _.get(userFromDataSource, 'data.' + name) + ? userFromDataSource.data && userFromDataSource.data[name] : _this.myUserData[name]; })).join(' ').trim(); @@ -2993,7 +2999,7 @@ DynamicList.prototype.appendTempComment = function(id, value, guid, userFromData DynamicList.prototype.replaceComment = function(guid, commentData, context) { var _this = this; var userName = _.compact(_.map(_this.data.userNameFields, function(name) { - return _.get(commentData, 'data.settings.user.' + name); + return commentData.data && commentData.data.settings && commentData.data.settings.user && commentData.data.settings.user[name]; })).join(' ').trim(); if (!commentData.literalDate) { diff --git a/js/layout-javascript/simple-list-code.js b/js/layout-javascript/simple-list-code.js index a83957d6..6712345c 100644 --- a/js/layout-javascript/simple-list-code.js +++ b/js/layout-javascript/simple-list-code.js @@ -33,6 +33,7 @@ function DynamicList(id, data) { this.isSearching; this.showBookmarks; this.fetchedAllBookmarks = false; + this.allFilterPropertiesAdded = false; this.listItems; this.modifiedListItems; @@ -1086,7 +1087,7 @@ DynamicList.prototype.initialize = function() { }); }) .then(function(records) { - _this.listItems = _this.getPermissions(records); + _this.listItems = records; if (!_this.data.detailViewAutoUpdate) { return Promise.resolve(); @@ -1105,12 +1106,13 @@ DynamicList.prototype.initialize = function() { .then(function(response) { _this.listItems = _.uniqBy(response, 'id'); _this.checkIsToOpen(); - _this.modifiedListItems = _this.Utils.Records.addFilterProperties({ + _this.listItems = _this.Utils.Records.addFilterProperties({ records: _this.listItems, config: _this.data }); + _this.allFilterPropertiesAdded = true; - return _this.addFilters(_this.modifiedListItems); + return _this.addFilters(_this.listItems); }) .then(function() { _this.parseFilterQueries(); @@ -1388,17 +1390,20 @@ DynamicList.prototype.renderBaseHTML = function() { DynamicList.prototype.addSummaryData = function(records) { var _this = this; - var modifiedData = _this.Utils.Records.addFilterProperties({ - records: records, - config: _this.data - }); + var modifiedData = records; + + if (!_this.allFilterPropertiesAdded) { + modifiedData = _this.Utils.Records.addFilterProperties({ + records: modifiedData, + config: _this.data + }); + } + var loopData = _.map(modifiedData, function(entry) { var newObject = { id: entry.id, flClasses: entry.data['flClasses'], flFilters: entry.data['flFilters'], - editEntry: entry.editEntry, - deleteEntry: entry.deleteEntry, likesEnabled: entry.likesEnabled, bookmarksEnabled: entry.bookmarksEnabled, commentsEnabled: entry.commentsEnabled, @@ -1490,16 +1495,16 @@ DynamicList.prototype.getAddPermission = function(data) { return data; }; -DynamicList.prototype.getPermissions = function(entries) { - var _this = this; +DynamicList.prototype.addPermissions = function(entry) { + if (!_.isObject(entry)) { + return entry; + } // Adds flag for Edit and Delete buttons - _.forEach(entries, function(entry) { - entry.editEntry = _this.Utils.Record.isEditable(entry, _this.data, _this.myUserData); - entry.deleteEntry = _this.Utils.Record.isDeletable(entry, _this.data, _this.myUserData); - }); + entry.editEntry = this.Utils.Record.isEditable(entry, this.data, this.myUserData); + entry.deleteEntry = this.Utils.Record.isDeletable(entry, this.data, this.myUserData); - return entries; + return entry; }; DynamicList.prototype.addFilters = function(records) { @@ -1787,7 +1792,7 @@ DynamicList.prototype.getLikeIdentifier = function(record) { }; DynamicList.prototype.setupLikeButton = function(options) { - if (!_.get(this.data, 'social.likes')) { + if (!(this.data.social && this.data.social.likes)) { return Promise.resolve(); } @@ -1969,7 +1974,7 @@ DynamicList.prototype.getBookmarkIdentifier = function(record) { }; DynamicList.prototype.setupBookmarkButton = function(options) { - if (!_.get(this.data, 'social.bookmark')) { + if (!(this.data.social && this.data.social.bookmark)) { return Promise.resolve(); } @@ -2160,7 +2165,7 @@ DynamicList.prototype.initializeOverlaySocials = function(id) { DynamicList.prototype.getAllBookmarks = function() { var _this = this; - if (_this.fetchedAllBookmarks || !_.get(_this.data, 'social.bookmark') || !_this.data.bookmarkDataSourceId) { + if (_this.fetchedAllBookmarks || !(_this.data.social && _this.data.social.bookmark) || !_this.data.bookmarkDataSourceId) { return Promise.resolve(); } @@ -2186,7 +2191,7 @@ DynamicList.prototype.getAllBookmarks = function() { }) }).then(function(results) { var bookmarkedIds = _.compact(_.map(results.data, function(record) { - var match = _.get(record, 'data.content.entryId', '').match(/(\d*)-bookmark/); + var match = ((record.data && record.data.content && record.data.content.entryId) || '').match(/(\d*)-bookmark/); return match ? parseInt(match[1], 10) : ''; })); @@ -2240,7 +2245,7 @@ DynamicList.prototype.initializeSocials = function(records) { }; DynamicList.prototype.getCommentUsers = function() { - if (!_.get(this.data, 'social.comments')) { + if (!(this.data.social && this.data.social.comments)) { return Promise.resolve(); } @@ -2263,14 +2268,14 @@ DynamicList.prototype.getCommentUsers = function() { _this.allUsers = users; // Update my user data - if (!_.isEmpty(_this.myUserData)) { - var myUser = _.find(_this.allUsers, function(user) { - return _this.myUserData[_this.data.userEmailColumn] === user.data[_this.data.userEmailColumn]; - }); + if (_this.myUserData) { + _this.allUsers.some(function(user) { + if (_this.myUserData[_this.data.userEmailColumn] === user.data[_this.data.userEmailColumn]) { + _this.myUserData = $.extend(true, _this.myUserData, user.data); - if (myUser) { - _this.myUserData = $.extend(true, _this.myUserData, myUser.data); - } + return true; + } + }); } return _this.Utils.Users.getUsersToMention({ @@ -2292,6 +2297,7 @@ DynamicList.prototype.addDetailViewData = function(entry) { return entry; } + entry = _this.addPermissions(entry); entry.entryDetails = []; // Define detail view data based on user's settings @@ -2522,7 +2528,7 @@ DynamicList.prototype.getCommentIdentifier = function(record) { }; DynamicList.prototype.getEntryComments = function(options) { - if (!_.get(this.data, 'social.comments')) { + if (!(this.data.social && this.data.social.comments)) { return Promise.resolve(); } @@ -2584,7 +2590,7 @@ DynamicList.prototype.connectToUsersDataSource = function() { }; DynamicList.prototype.updateCommentCounter = function(options) { - if (!_.get(this.data, 'social.comments')) { + if (!(this.data.social && this.data.social.comments)) { return; } @@ -2645,7 +2651,7 @@ DynamicList.prototype.showComments = function(id, commentId) { var newDate = new Date(entry.createdAt); var timeInMilliseconds = newDate.getTime(); var userName = _.compact(_.map(_this.data.userNameFields, function(name) { - return _.get(entry, 'data.settings.user.' + name); + return entry.data && entry.data.settings && entry.data.settings.user && entry.data.settings.user[name]; })).join(' ').trim(); entryComments[index].timeInMilliseconds = timeInMilliseconds; @@ -2916,7 +2922,7 @@ DynamicList.prototype.appendTempComment = function(id, value, guid, userFromData var timestamp = (new Date()).toISOString(); var userName = _.compact(_.map(_this.data.userNameFields, function(name) { return _this.myUserData.isSaml2 - ? _.get(userFromDataSource, 'data.' + name) + ? userFromDataSource.data && userFromDataSource.data[name] : _this.myUserData[name]; })).join(' ').trim(); @@ -2942,7 +2948,7 @@ DynamicList.prototype.appendTempComment = function(id, value, guid, userFromData DynamicList.prototype.replaceComment = function(guid, commentData, context) { var _this = this; var userName = _.compact(_.map(_this.data.userNameFields, function(name) { - return _.get(commentData, 'data.settings.user.' + name); + return commentData.data && commentData.data.settings && commentData.data.settings.user && commentData.data.settings.user[name]; })).join(' ').trim(); if (!commentData.literalDate) { diff --git a/js/layout-javascript/small-card-code.js b/js/layout-javascript/small-card-code.js index 8cd387c3..1a84b327 100644 --- a/js/layout-javascript/small-card-code.js +++ b/js/layout-javascript/small-card-code.js @@ -28,6 +28,7 @@ function DynamicList(id, data) { this.isSearching; this.showBookmarks; this.fetchedAllBookmarks = false; + this.allFilterPropertiesAdded = false; this.emailField = 'Email'; this.myProfileData = []; @@ -900,16 +901,16 @@ DynamicList.prototype.initialize = function() { }); }) .then(function(records) { - records = _this.getPermissions(records); - // Get user profile if (!_.isEmpty(_this.myUserData)) { // Create flag for current user - records.forEach(function(record) { + records.some(function(record) { record.isCurrentUser = _this.Utils.Record.isCurrentUser(record, _this.data, _this.myUserData); if (record.isCurrentUser) { _this.myProfileData.push(record); + + return true; } }); } @@ -934,12 +935,13 @@ DynamicList.prototype.initialize = function() { .then(function(response) { _this.listItems = _.uniqBy(response, 'id'); _this.checkIsToOpen(); - _this.modifiedListItems = _this.Utils.Records.addFilterProperties({ + _this.listItems = _this.Utils.Records.addFilterProperties({ records: _this.listItems, config: _this.data }); + _this.allFilterPropertiesAdded = true; - return _this.addFilters(_this.modifiedListItems); + return _this.addFilters(_this.listItems); }) .then(function() { _this.parseFilterQueries(); @@ -1213,17 +1215,20 @@ DynamicList.prototype.renderBaseHTML = function() { DynamicList.prototype.addSummaryData = function(records) { var _this = this; - var modifiedData = _this.Utils.Records.addFilterProperties({ - records: records, - config: _this.data - }); + var modifiedData = records; + + if (!_this.allFilterPropertiesAdded) { + modifiedData = _this.Utils.Records.addFilterProperties({ + records: modifiedData, + config: _this.data + }); + } + var loopData = _.map(modifiedData, function(entry) { var newObject = { id: entry.id, flClasses: entry.data['flClasses'], flFilters: entry.data['flFilters'], - editEntry: entry.editEntry, - deleteEntry: entry.deleteEntry, isCurrentUser: entry.isCurrentUser ? entry.isCurrentUser : false, bookmarksEnabled: entry.bookmarksEnabled, chatEnabled: entry.chatEnabled, @@ -1232,7 +1237,7 @@ DynamicList.prototype.addSummaryData = function(records) { originalData: entry.data }; - // Uses sumamry view settings set by users + // Uses summary view settings set by users _this.data['summary-fields'].forEach(function(obj) { var content = ''; @@ -1316,16 +1321,16 @@ DynamicList.prototype.getAddPermission = function(data) { return data; }; -DynamicList.prototype.getPermissions = function(entries) { - var _this = this; +DynamicList.prototype.addPermissions = function(entry) { + if (!_.isObject(entry)) { + return entry; + } // Adds flag for Edit and Delete buttons - _.forEach(entries, function(entry) { - entry.editEntry = _this.Utils.Record.isEditable(entry, _this.data, _this.myUserData); - entry.deleteEntry = _this.Utils.Record.isDeletable(entry, _this.data, _this.myUserData); - }); + entry.editEntry = this.Utils.Record.isEditable(entry, this.data, this.myUserData); + entry.deleteEntry = this.Utils.Record.isDeletable(entry, this.data, this.myUserData); - return entries; + return entry; }; DynamicList.prototype.addFilters = function(records) { @@ -1546,7 +1551,7 @@ DynamicList.prototype.searchData = function(options) { var profileIconTemplate = Fliplet.Widget.Templates[_this.layoutMapping[_this.data.layout]['profile-icon']]; var profileIconTemplateCompiled = Handlebars.compile(profileIconTemplate()); - _this.modifiedProfileData = _this.addSummaryData(_this.myProfileData, true); + _this.modifiedProfileData = _this.addSummaryData(_this.myProfileData); _this.$container.find('.my-profile-placeholder').html(myProfileTemplateCompiled(_this.modifiedProfileData[0])); _this.$container.find('.my-profile-icon').html(profileIconTemplateCompiled(_this.modifiedProfileData[0])); _this.$container.find('.section-top-wrapper').removeClass('profile-disabled'); @@ -1629,7 +1634,7 @@ DynamicList.prototype.getBookmarkIdentifier = function(record) { }; DynamicList.prototype.setupBookmarkButton = function(options) { - if (!_.get(this.data, 'social.bookmark')) { + if (!(this.data.social && this.data.social.bookmark)) { return Promise.resolve(); } @@ -1793,7 +1798,7 @@ DynamicList.prototype.initializeOverlaySocials = function(id) { DynamicList.prototype.getAllBookmarks = function() { var _this = this; - if (_this.fetchedAllBookmarks || !_.get(_this.data, 'social.bookmark') || !_this.data.bookmarkDataSourceId) { + if (_this.fetchedAllBookmarks || !(_this.data.social && _this.data.social.bookmark) || !_this.data.bookmarkDataSourceId) { return Promise.resolve(); } @@ -1819,7 +1824,7 @@ DynamicList.prototype.getAllBookmarks = function() { }) }).then(function(results) { var bookmarkedIds = _.compact(_.map(results.data, function(record) { - var match = _.get(record, 'data.content.entryId', '').match(/(\d*)-bookmark/); + var match = ((record.data && record.data.content && record.data.content.entryId) || '').match(/(\d*)-bookmark/); return match ? parseInt(match[1], 10) : ''; })); @@ -1845,7 +1850,7 @@ DynamicList.prototype.getAllBookmarks = function() { DynamicList.prototype.initializeSocials = function(records) { var _this = this; - if (!_.get(_this.data, 'social.bookmark') || !_this.data.bookmarkDataSourceId) { + if (!(_this.data.social && _this.data.social.bookmark) || !_this.data.bookmarkDataSourceId) { return Promise.resolve(); } @@ -1880,6 +1885,7 @@ DynamicList.prototype.addDetailViewData = function(entry) { return option.editable; }); + entry = _this.addPermissions(entry); entry.entryDetails = []; // Uses detail view settings not set by users diff --git a/js/layout-javascript/small-h-card-code.js b/js/layout-javascript/small-h-card-code.js index 06f1c5e1..b581d09d 100644 --- a/js/layout-javascript/small-h-card-code.js +++ b/js/layout-javascript/small-h-card-code.js @@ -22,7 +22,6 @@ function DynamicList(id, data) { this.allowClick = true; this.emailField = 'Email'; - this.myProfileData; this.modifiedProfileData; this.myUserData = {}; @@ -429,20 +428,6 @@ DynamicList.prototype.initialize = function() { }); }) .then(function(records) { - records = _this.getPermissions(records); - - // Get user profile - if (!_.isEmpty(_this.myUserData)) { - // Create flag for current user - records.forEach(function(record) { - record.isCurrentUser = _this.Utils.Record.isCurrentUser(record, _this.data, _this.myUserData); - }); - - _this.myProfileData = _.filter(records, function(row) { - return row.isCurrentUser; - }); - } - // Make rows available Globally _this.listItems = records; @@ -734,16 +719,16 @@ DynamicList.prototype.getAddPermission = function(data) { return data; }; -DynamicList.prototype.getPermissions = function(entries) { - var _this = this; +DynamicList.prototype.addPermissions = function(entry) { + if (!_.isObject(entry)) { + return entry; + } // Adds flag for Edit and Delete buttons - _.forEach(entries, function(entry) { - entry.editEntry = _this.Utils.Record.isEditable(entry, _this.data, _this.myUserData); - entry.deleteEntry = _this.Utils.Record.isDeletable(entry, _this.data, _this.myUserData); - }); + entry.editEntry = this.Utils.Record.isEditable(entry, this.data, this.myUserData); + entry.deleteEntry = this.Utils.Record.isDeletable(entry, this.data, this.myUserData); - return entries; + return entry; }; DynamicList.prototype.addDetailViewData = function(entry) { @@ -762,6 +747,7 @@ DynamicList.prototype.addDetailViewData = function(entry) { return option.editable; }); + entry = _this.addPermissions(entry); entry.entryDetails = []; // Uses detail view settings not set by users diff --git a/js/utils.js b/js/utils.js index ef2f9148..2783eb9e 100644 --- a/js/utils.js +++ b/js/utils.js @@ -178,9 +178,9 @@ Fliplet.Registry.set('dynamicListUtils', (function() { /** * This function adds selected LFD item's images to the layout context * - * @param {Object} ctx - curent layout context + * @param {Object} ctx - current layout context * @param {Object} entry - selected LFD entry - * @return {void} this funtion doesn't return anything it commits modifications to layout context + * @return {void} this function doesn't return anything it commits modifications to layout context */ function assignImageContent(ctx, entry) { var dynamicData = _.filter(ctx.data.detailViewOptions, function(option) { @@ -440,7 +440,7 @@ Fliplet.Registry.set('dynamicListUtils', (function() { * filtersInOverlay { Boolean } - represent us if filters shown in the overlay * $target { Jquery instance } - Jq instance on which user have pressed * - * @returns {void} this funtion doesn't return anything it add changes directly to the DOM + * @returns {void} this function doesn't return anything it add changes directly to the DOM */ function updateActiveFilterCount(options) { if (!options.filtersInOverlay || !options.$target || !options.$target.length) { @@ -1090,11 +1090,13 @@ Fliplet.Registry.set('dynamicListUtils', (function() { return _[config.filterMatch === 'all' ? 'every' : 'some'](filters[field], function(value) { if (field === 'undefined') { // Legacy class-based filters - return _.includes(_.map(_.get(record, 'data.flFilters'), 'data.class'), value); + return _.includes(_.map(record.data && record.data.flFilters, function(flFilter) { + return flFilter.data && flFilter.data.class; + }), value); } // Filter UI contains data-field, i.e. uses new field-based filters - return _.some(_.get(recordFieldValues, field), function(recordFieldValue) { + return _.some(recordFieldValues[field], function(recordFieldValue) { // Loosely typed comparison is used to make filtering more predictable for users // eslint-disable-next-line eqeqeq return recordFieldValue == value; @@ -1106,7 +1108,7 @@ Fliplet.Registry.set('dynamicListUtils', (function() { function getRecordUniqueId(options) { options = options || {}; - var primaryKey = _.get(options, 'config.dataPrimaryKey'); + var primaryKey = options.config && options.config.dataPrimaryKey; if (typeof primaryKey === 'function') { return primaryKey({ @@ -1116,10 +1118,10 @@ Fliplet.Registry.set('dynamicListUtils', (function() { } if (typeof primaryKey === 'string' && primaryKey.length) { - return _.get(options, ['record', 'data', primaryKey]); + return options.record && options.record.data && options.record.data[primaryKey]; } - return _.get(options, ['record', 'id']); + return options.record && options.record.id; } function getRecordFieldValues(records, fields) { @@ -1133,7 +1135,9 @@ Fliplet.Registry.set('dynamicListUtils', (function() { } return _.zipObject(fields, _.map(fields, function(field) { - return _.sortBy(_.uniq(splitByCommas(_.map(records, ['data', field])))); + return _.sortBy(_.uniq(splitByCommas(_.map(records, function(record) { + return record.data && record.data[field]; + })))); })); } @@ -2004,9 +2008,9 @@ Fliplet.Registry.set('dynamicListUtils', (function() { function recordIsCurrentUser(record, config, userData) { return config.userEmailColumn !== 'none' - && !_.isEmpty(_.get(userData, config.userEmailColumn)) - && !_.isEmpty(_.get(record, ['data', config.userListEmailColumn])) - && _.get(userData, config.userEmailColumn) === _.get(record, ['data', config.userListEmailColumn]); + && !_.isEmpty(userData[config.userEmailColumn]) + && !_.isEmpty(record.data && record.data[config.userListEmailColumn]) + && userData[config.userEmailColumn] === (record.data && record.data[config.userListEmailColumn]); } function userCanAddRecord(config, userData) { @@ -2100,12 +2104,12 @@ Fliplet.Registry.set('dynamicListUtils', (function() { function resetSortIcons(options) { options.$sortList.each(function() { - var $listitem = $(this); - var listSortOrder = $listitem.data('sortOrder'); - var $listIcon = $listitem.find('i'); + var $listItem = $(this); + var listSortOrder = $listItem.data('sortOrder'); + var $listIcon = $listItem.find('i'); $listIcon.removeClass('fa-sort-' + listSortOrder).addClass('fa-sort'); - $listitem.data('sortOrder', 'none'); + $listItem.data('sortOrder', 'none'); }); } @@ -2137,9 +2141,9 @@ Fliplet.Registry.set('dynamicListUtils', (function() { * * @param {String} error - error message from the navigateToScreen function * @param {Object} errorMessages - Messages that we will show in toast. - * required poperties: - * 'pageError' - message that we will show when no page is specifyed - * 'openError' - message that we will show when error ocures on page open + * required properties: + * 'pageError' - message that we will show when no page is specified + * 'openError' - message that we will show when error occurs on page open * * @returns {void} */