Skip to content

Commit

Permalink
Merge pull request #181 from helols/iss-112-label-issue
Browse files Browse the repository at this point in the history
Reviewed-by: Suwon Chae
  • Loading branch information
doortts authored Mar 22, 2017
2 parents 39a9d76 + bb83dc2 commit 7e88e19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 18 additions & 6 deletions public/javascripts/common/yobi.ui.Select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,28 @@
var data = [evt.object];
var element = $(evt.object.element);
var select2Object = $(evt.target).data("select2");
var oldData = select2Object.data()

// Remove label which category is same with selected label from current data
// if selected label belonged exclusive category
if(element.data("categoryIsExclusive")){
var filtered = _filterLabelInSameCategory(evt.object, select2Object.data());
var categoryId = $(evt.object.element).data("categoryId");
var filtered = _filterLabelInSameCategory(categoryId, oldData);
data = data.concat(filtered);

if(oldData.length != filtered.length){
_unselect(select2Object, categoryId);
}
} else {
data = data.concat(select2Object.data());
data = data.concat(oldData);
}

_rememberLastScrollTop();

// Set data as filtered
// and trigger "change" event
select2Object.data(data, true);

if(select2Object.opts.closeOnSelect !== false){
select2Object.close();
}
Expand All @@ -215,9 +221,7 @@
return false;
}

function _filterLabelInSameCategory(label, currentData){
var categoryId = $(label.element).data("categoryId");

function _filterLabelInSameCategory(categoryId, currentData){
return currentData.filter(function(data){
return (categoryId !== $(data.element).data("categoryId"));
});
Expand All @@ -240,6 +244,14 @@
function _onOpenIssueLabel(){
_restoreLastScrollTop();
}

// When select2 v3.x is migrated to v4.x, it will probably need to be updated.
function _unselect(select2Object, categoryId){
select2Object.results.find(".select2-selected").filter(function(){
var optionElement = $(this).data("select2-data").element;
return $(optionElement).data("categoryId") === categoryId;
}).removeClass("select2-selected");
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions public/javascripts/service/yobi.issue.LabelEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@
if(elements.inputCategory.val().length === 0 ||
elements.inputName.val().length === 0 ||
elements.inputColor.val().length === 0){
$yobi.alert(Messages("label.failed") + "\n" + Messages("label.error.empty"));
$yobi.alert(Messages("label.failedTo", Messages("label.add")) + "\n" + Messages("label.error.empty"));
return false;
}

if(_getRefinedHexColor(elements.inputColor.val()) === false){
$yobi.alert(Messages("label.failed") + "\n" + Messages("label.error.color", elements.inputColor.val()));
$yobi.alert(Messages("label.failedTo", Messages("label.add")) + "\n" + Messages("label.error.color", elements.inputColor.val()));
return false;
}

Expand Down

0 comments on commit 7e88e19

Please sign in to comment.