Skip to content

Instantly share code, notes, and snippets.

@ramrrr
Last active December 19, 2015 22:39
Show Gist options
  • Select an option

  • Save ramrrr/6029096 to your computer and use it in GitHub Desktop.

Select an option

Save ramrrr/6029096 to your computer and use it in GitHub Desktop.
Validation
<div class="form-horizontal">
<div {{bindAttr class=":control-group view.channel.channelConfig.validationErrors.invalid:error"}}>
<label class="control-label">{{t composer.configuration}} </label>
<div class="controls">
{{view.description}}
<div class="pull-right">
{{#if model.channelConfig.callTries}}
<b> {{model.channelConfig.callTries}} tries , {{model.channelConfig.callInterval}} min interval</b>
{{/if}}
</div>
<div class="btn-toolbar">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
{{t send.alert.define.sms.configuration}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
{{#each availableConfigs}}
<li><a href="#" {{action setConfig this}}>
{{name}}
</a></li>
{{else}}
<li><a>No configs available</a></li>
{{/each}}
</ul>
</div>
<div class="btn-group">
<button class="btn" {{action setModal "customize"}}>{{t composer.customize}}</button>
</div>
</div>
{{#if view.channel.channelConfig.validationErrors.invalid}}
<span class="help-inline">
{{view.channel.channelConfig.validationErrors.description}}
{{view.channel.channelConfig.validationErrors.priority}}
</span>
{{/if}}
</div>
<label class="control-label">{{t composer.originatingNumber}}</label>
<div class="btn-toolbar">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
Orignating number
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
{{#each availableConfigs}}
<li><a href="#" {{action setConfig this}}>
{{description}}
</a></li>
{{else}}
<li><a>No originating number available</a></li>
{{/each}}
</ul>
</div>
</div>
</div>
<div {{bindAttr class=":control-group view.channel.message.validationErrors.messageInvalid:error"}}>
</div>
</div>
{{#view UI.ModalView name="customize" activeModalBinding="activeModal"}}
<div class="modal-header">
<button type="button" class="close" {{action validateBeforeClose "none"}} aria-hidden="true">×</button>
<h3 id="myModalLabel">{{t composer.customize.config}}</h3>
</div>
<div class="modal-body">
<div class="form-horizontal">
{{#if model.channelConfig.validationErrors.invalid}}
<span class="help-inline">
{{#with model.channelConfig.validationErrors}}
{{description}}
{{priority}}
{{outboundLines}}
{{/with}}
</span>
{{/if}}
<div class="control-group">
<label class="control-label">
{{t group.name}}
<span class="required">*</span>
</label>
<div class="controls">
{{view view.parentView.nameInput}}
</div>
</div>
<div class="control-group">
<label class="control-label">
{{t entity.common.description}}
<span class="required">*</span>
</label>
<div class="controls">
{{view view.parentView.descriptionInput}}
</div>
</div>
<div class="control-group">
<label class="control-label">
{{t voice.config.priority}}:
<span class="required">*</span>
</label>
<div class="controls">
{{view Ember.Select class="select-mini" contentBinding="VoiceData.voicePriority"
optionValuePath="content.key"
optionLabelPath="content.value"
valueBinding="model.channelConfig.priority"}}
</div>
</div>
<div class="control-group">
<label class="control-label">
{{t voice.config.outboundlines}}
<span class="required">*</span>
</label>
<div class="controls">
{{view Ember.TextField class="input-mini" valueBinding="model.channelConfig.outboundLines"}}
<label>{{t voice.config.outboundlines.max}} {{VoiceData.voiceMaxoutboundLines}} </label>
</div>
</div>
<div class="control-group">
<label class="control-label">{{t voice.config.callperson}}</label>
<div class="controls">
{{view Ember.Select class="select-mini" contentBinding="VoiceData.voiceNoOfTries"
optionValuePath="content.key"
optionLabelPath="content.value"
valueBinding="model.channelConfig.callTries"}}
<label> {{t voice.config.doesnot.answer}} </label>
</div>
</div>
<div class="control-group">
<label class="control-label">{{t voice.config.call.interval}}</label>
<div class="controls">
{{view Ember.Select class="select-mini" contentBinding= "VoiceData.voiceIntervalOfTries"
optionValuePath="content.key"
optionLabelPath="content.value"
valueBinding="model.channelConfig.callInterval"}}
<label>{{t voice.config.mins}}</label>
</div>
</div>
<div class="control-group">
<label class="control-label">{{t voice.config.call.number}}</label>
<div class="controls">
{{view Ember.Select class="select-mini" contentBinding= "VoiceData.voiceHangupTimes"
optionValuePath="content.key"
optionLabelPath="content.value"
valueBinding="model.channelConfig.callHangupTime"}}
<label>{{t voice.config.hangup}}</label>
</div>
</div
<div class="control-group">
<div class="controls">
{{view Ember.Checkbox checkedBinding="model.channelConfig.canPause"}}
<label>
Can Pause:
</label>
</div>
{{#if model.channelConfig.canPause}}
<label class="control-label">Pause From :</label>
<div class="controls">
{{view Ember.TextField class="input-mini" valueBinding="model.channelConfig.pauseFromDay"}} th day at
<div class="input-append bootstrap-timepicker-component">
{{view UI.TimePicker class="timepicker-default input-small"
timeBinding="pauseFromTimeDate"}}
<span class="add-on"><i class="icon-time"></i></span>
</div>
</div>
<label class="control-label">Pause To :</label>
<div class="controls">
{{view Ember.TextField class="input-mini" valueBinding="model.channelConfig.pauseToDay"}} th day at
<div class="input-append bootstrap-timepicker-component">
{{view UI.TimePicker class="timepicker-default input-small"
timeBinding="pauseToTimeDate"}}
<span class="add-on"><i class="icon-time"></i></span>
</div>
</div>
{{/if}}
<div class="controls">
{{view Ember.Checkbox checkedBinding="model.channelConfig.finishBy"}}
<label>
Automatic cancel alert if not finished by:
</label>
</div>
{{#if model.channelConfig.finishBy}}
<div class="controls">
{{view Ember.TextField class="input-mini"
valueBinding="model.channelConfig.cancellationDay"}} th day at
<div class="input-append bootstrap-timepicker-component">
{{view UI.TimePicker class="timepicker-default input-small"
timeBinding="cancelTimeDate"}}
<span class="add-on"><i class="icon-time"></i></span>
</div>
</div>
{{/if}}
</div>
</div>
<div class="modal-footer">
<button class="btn" {{action validateBeforeClose "none"}}>{{t composer.close}}</button>
</div>
</div>
{{/view}}
var App = require("core/App");
var Channel = require("channel/Channel")
var VoiceMessage = require("./VoiceMessage")
var VoiceChannelConfig = require("./VoiceChannelConfig")
var AddressPhone = require("recipientConfiguration/AddressPhone")
// Register the voice view
require("./VoiceView")
require("./VoiceController")
module.exports = App.VoiceChannel = Channel.extend({
message: DS.belongsTo(VoiceMessage),
channelConfig: DS.belongsTo(VoiceChannelConfig),
view: "voice",
controller: "voice",
validate: function(callback) {
this.beginValidation()
.validateField("channelConfig")
.done(callback);
},
init: function() {
this._super();
this.set("message", VoiceMessage.createRecord())
this.set("channelConfig", VoiceChannelConfig.createRecord())
},
loadFromLibrary: function(alert) {
var voiceMessage = alert.get("messageLibrary.voiceMessage");
if (voiceMessage) {
this.set("message.message", voiceMessage.get("message"));
}
},
acceptsAddress: function(address) {
return (address instanceof AddressPhone)
}
})
App.VoiceChannel.channelName = Ember.I18n.t("send.alert.define.msg.voice") ;
DS.RESTAdapter.map(App.VoiceChannel, {
message: { embedded: 'always' },
channelConfig: { embedded: 'always' }
});
DS.RESTAdapter.configure(App.VoiceChannel,{
sideloadAs: 'voice_channels'
});
var App = require("core/App");
var ChannelConfig = require("channel/ChannelConfig")
var HasValidation = require("core/HasValidation")
module.exports = App.VoiceChannelConfig = ChannelConfig.extend(HasValidation, {
channel: DS.belongsTo('App.VoiceChannel'),
description: DS.attr("string"),
name: DS.attr("string"),
priority: DS.attr("string"),
outboundLines: DS.attr("string"),
callHangupTime : DS.attr("string"),
callTries : DS.attr("string"),
callInterval : DS.attr("string"),
pauseToDay : DS.attr("string"),
pauseFromDay : DS.attr("string"),
cancellationDay : DS.attr("string"),
pauseFromTime: DS.attr("number"),
pauseToTime: DS.attr("number"),
cancelTime: DS.attr("number"),
isDefault : DS.attr("string"),
pauseToTimeDate: function(key, value) {
if (arguments.length === 1) {
var date = new Date();
date.setHours(Math.floor(this.get("pauseToTime") / 3600) );
date.setMinutes(Math.floor(this.get("pauseToTime") % 3600))
return date;
} else {
this.set("pauseToTime", date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds())
}
}.property("pauseToTime"),
pauseFromTimeDate: function(key, value) {
if (arguments.length === 1) {
var date = new Date();
date.setHours(Math.floor(this.get("pauseFromTime") / 3600) );
date.setMinutes(Math.floor(this.get("pauseFromTime") % 3600))
return date;
} else {
this.set("pauseFromTime", date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds())
}
}.property("pauseFromTime"),
cancelTimeDate: function(key, value) {
if (arguments.length === 1) {
var date = new Date();
date.setHours(Math.floor(this.get("cancelTime") / 3600) );
date.setMinutes(Math.floor(this.get("cancelTime") % 3600))
return date;
} else {
this.set("cancelTime", date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds())
}
}.property("cancelTime"),
auto: DS.attr('date', {
defaultValue: function() {
return (new Date());
}
}),
validate: function(callback) {
this.beginValidation()
.rejectIfEmpty("description", "Missing description")
.rejectIfEmpty("priority", "Missing priority")
.rejectIfEmpty("outboundLines", "Missing outboundLines")
.done(callback);
}
})
DS.RESTAdapter.configure(App.VoiceChannelConfig,{
sideloadAs: 'voice_channel_configs'
});
var App = require("core/App")
var HasModal = require("core/HasModal")
var VoiceChannelConfig = require("./VoiceChannelConfig")
require("./VoiceView")
module.exports = App.VoiceController = Ember.ObjectController.extend(HasModal, {
availableConfigs: [],
defaultConfigs : [],
onModelChange: function() {
var self = this;
var configs = VoiceChannelConfig.find({});
configs.on("didLoad", function() {
configs.forEach(function(config) {
self.availableConfigs.pushObject(config)
})
var defaultConfigs = configs.filterProperty("isDefault")
if (defaultConfigs.get("length") > 0) {
self.setConfig(defaultConfigs.objectAt(0));
}
})
}.observes("model"),
validateBeforeClose:function(){
var self = this;
this.get("model").validate(function(ok) {
debugger
if (ok) {
self.setModal("none") ;
}
})
} ,
setConfig: function(config) {
this.set("model.channelConfig.description", config.get("description"))
this.set("model.channelConfig.name", config.get("name"))
this.set("model.channelConfig.priority", config.get("priority"))
this.set("model.channelConfig.outboundLines", config.get("outboundLines"))
this.set("model.channelConfig.callHangupTime", config.get("callHangupTime"))
this.set("model.channelConfig.callTries", config.get("callTries"))
this.set("model.channelConfig.callInterval", config.get("callInterval"))
this.set("model.channelConfig.pauseFromTime", config.get("pauseFromTime"))
this.set("model.channelConfig.pauseToTime", config.get("pauseToTime"))
this.set("model.channelConfig.cancelTime", config.get("cancelTime"))
this.set("model.channelConfig.pauseToDay", config.get("pauseToDay"))
this.set("model.channelConfig.pauseFromDay", config.get("pauseFromDay"))
this.set("model.channelConfig.cancellationDay", config.get("cancellationDay"))
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment