Created
October 19, 2016 20:15
-
-
Save kutyel/7c11ef44a121f949cece41178ce84b1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
shouldFlag: function(selectedIds) { | |
// Assume don't flag | |
var shouldFlagMessages = false; | |
// Keep track of how many are flagged and not flagged | |
var flaggedCount = 0; | |
var unFlaggedCount = 0; | |
// Get only the messages we care about | |
var messagesInQuestion = []; | |
for (var i = 0; i < this.messages.length; i++) { | |
if (selectedIds.indexOf(this.messages[i].id) !== -1) { | |
messagesInQuestion.push(this.messages[i]); | |
} | |
} | |
// Determine the number of flagged messages vs. unflagged messages in the set | |
for (var i = 0; i < messagesInQuestion.length; i++) { | |
if (messagesInQuestion[i].flagged) { | |
flaggedCount++; | |
} else { | |
unFlaggedCount++; | |
} | |
} | |
// Only flag the messages if there are no flagged messages | |
// OR there are messagesInQuestion present that are not flagged | |
if (flaggedCount === 0 || unFlaggedCount !== 0) { | |
shouldFlagMessages = true; | |
} | |
return shouldFlagMessages; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment