Commit b0f66383 authored by Caleb Weeks's avatar Caleb Weeks

adding readonly support to selection widget

parent e3eac9a5
......@@ -80,9 +80,22 @@
{{/if}}
</h5>
</div>
<div class="collapsible-body" style="background-color:#fafafa;">
{{> page.component-body bl:key=@component.key bl:fromTopLevel=true}}
</div>
{{#unless bl:map.bl:q.bl:processing}}
<div class="collapsible-body" style="background-color:#fafafa;">
{{> page.component-body bl:key=@component.key bl:fromTopLevel=true}}
</div>
{{else}}
<div class="processing-query">
<p class="loading">
<span><i class="loading-spinner fa fa-refresh fa-spin"></i> This query result is currently being updated</span>
</p>
<p class="done">
<span>Processing complete. Click <a href="javascript:window.location.reload(true)">here</a> to reload</span>
</p>
</div>
{{/unless}}
</li>
{{/inline}}
......
......@@ -2,7 +2,25 @@
module.exports={
init:function($el, $){
var $sel = $el.find("select");
var savedValue = $el.data("saved-value");
var stringifiedSavedValue;
//if there is a saved value and it's not an array, force it into an array
if((savedValue || savedValue === 0) && !$.$.isArray(savedValue)){
savedValue = [savedValue];
}
if(savedValue){
stringifiedSavedValue = $.$.map(savedValue,function(val){return val.toString();});
}
var options=$.widget.options;
if($.widget.readonly && $.widget.type === 'select'){
options = savedValue;
}
if(options){
if(typeof(options)==="function"){
var errCheck;
......@@ -14,24 +32,16 @@ module.exports={
setOptions(null, options);
}
function setOptions(err, options){
if(err){
var msg="Problem building 'selection' widget options.\n";
if(err instanceof Error){err.message=msg+err.message; throw(err)}
else{throw new Error(msg + JSON.stringify(err))}
}
var $sel = $el.find("select");
var savedValue = $el.data("saved-value");
//if there is a saved value and it's not an array, force it into an array
if((savedValue || savedValue === 0) && !$.$.isArray(savedValue)){
savedValue = [savedValue];
}
if(savedValue){
var stringifiedSavedValue = $.$.map(savedValue,function(val){return val.toString();});
}
var selected;
var html=["<option value='' disabled selected style='color:#911'>No selection</option>"];
......
......@@ -7,7 +7,7 @@
{{!-- "checkbox" "radio", "select" or combobox" --}}
<label for="{{safename config.name}}_\{{safename @root._id}}" style="position:relative;top:3px;">{{config.fieldLabel}}</label>
<select class="" name="{{config.name}}" id="{{safename config.name}}_\{{safename @root._id}}" {{#if config.multiple}} multiple {{/if}}>
<select class="{{#if config.readonly}} readonly {{/if}}" name="{{config.name}}" id="{{safename config.name}}_\{{safename @root._id}}" {{#if config.multiple}} multiple {{/if}} >
<option value="" disabled selected style="color:#911">No selection</option>
<option value="">Loading options....</option>
</select>
......
<div class="bl-widget bl-init" data-type="tags" data-key="{{config.key}}" data-value='\{{as-json {{config.hbsValidName}} }}' style="margin-bottom:32px;" >
<div class="bl-widget bl-init" data-type="tags" data-key="{{config.key}}" data-value='\{{as-json {{config.hbsValidName}} }}' {{#if config.readonly}} data-readonly="true"{{/if}} style="margin-bottom:32px;" >
<label for="{{safename config.name}}_\{{safename @root._id}}" style="position:relative; top:5px;">{{config.fieldLabel}}</label>
<div id="{{safename config.name}}_\{{safename @root._id}}" class="chips"></div>
......
......@@ -6650,6 +6650,7 @@ select:disabled {
color: rgba(0, 0, 0, 0.3);
}
.select-wrapper.readonly input.select-dropdown,
.select-wrapper input.select-dropdown:disabled {
color: rgba(0, 0, 0, 0.3);
cursor: default;
......
......@@ -3566,7 +3566,9 @@ if (jQuery) {
$select.wrap(wrapper);
// Add Select Display Element
var dropdownIcon = $('<span class="caret">&#9660;</span>');
if ($select.is(':disabled'))
var disableUi = $select.is(':disabled') || $select.hasClass('readonly');
if (disableUi)
dropdownIcon.addClass('disabled');
// escape double quotes
......@@ -3578,7 +3580,7 @@ if (jQuery) {
$newSelect.after(options);
// Check if section element is disabled
if (!$select.is(':disabled')) {
if (!disableUi) {
$newSelect.dropdown({'hover': false, 'closeOnClick': false});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment