Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichBoxGroup 支持被选中的样式和singleSelect功能 #50

Merged
merged 1 commit into from
May 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/ui/RichBoxGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,49 @@ define(
* @override
*/
RichBoxGroup.prototype.type = 'RichBoxGroup';


/**
* 同步样式
*
* @ignore
*/
function syncStyle() {
var group = this;
var result = u.chain(this.getBoxElements())
.where({checked: true})
.value();
u.each(
u.chain(this.getBoxElements()).value(),
function(item, index) {
if (item.checked === true) {
lib.addClasses(item, group.helper.getPartClasses('checked'));
lib.addClasses(item.parentNode, group.helper.getPartClasses('wrapper-checked'));
}
else {
lib.removeClasses(item, group.helper.getPartClasses('checked'));
lib.removeClasses(item.parentNode, group.helper.getPartClasses('wrapper-checked'));
}
}
);
if (group.boxType == 'checkbox' && group.singleSelect === 'true') {
if (result && result.length) {
var unselectedBox = u.chain(this.getBoxElements())
.where({checked: false})
.value();
u.each(unselectedBox, function(item, index) {
item.disabled = true;
});
}
else {
var allBox = u.chain(this.getBoxElements())
.value();
u.each(allBox, function(item, index) {
item.disabled = false;
});
}
}
}

/**
* 同步值
*
Expand All @@ -48,6 +90,7 @@ define(

this.rawValue = result;
this.fire('change');
syncStyle.call(this);
}

/* eslint-disable fecs-indent */
Expand Down Expand Up @@ -114,6 +157,7 @@ define(
},
group
);
syncStyle.call(group);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加个repaint,然后把逻辑和syncValue合并一下变成sync? @Justineo 觉得呢

}

/**
Expand Down Expand Up @@ -192,6 +236,16 @@ define(
group.removeState('horizontal');
group.addState(orientation);
}
},
{
/**
*
* 选框的样式同步
*/
name: 'singleSelect',
paint: function (group) {
syncStyle.call(group);
}
}
);

Expand Down