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

Date fix #162

Merged
merged 4 commits into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
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
46 changes: 33 additions & 13 deletions common/input/date/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,52 @@
<title>Focus component examples</title>
<meta name="description" content="Example of the component.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Include Required Prerequisites -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/2.9.0/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/3.3.2/css/bootstrap.css" />

<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/1/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/1/daterangepicker-bs3.css" />
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>
<script src="https://fb.me/react-0.13.3.js"></script>
<link rel="stylesheet" href="/focus-components/example/css/picker.css"/>
<link rel="stylesheet" href="css/form.css"/>
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.9.3/lodash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.1/backbone.js"></script>

<!-- Material degign-->
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap.material-design/0.3.0/css/material-wfont.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap.material-design/0.3.0/css/material.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap.material-design/0.3.0/css/ripples.min.css">
<script src="//cdn.jsdelivr.net/bootstrap.material-design/0.3.0/js/material.min.js"></script>
<script src="//cdn.jsdelivr.net/bootstrap.material-design/0.3.0/js/ripples.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/0.4.0/Showdown.js"></script>

<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/2.9.0/moment.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/1/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css"
href="//cdn.jsdelivr.net/bootstrap.daterangepicker/1/daterangepicker-bs3.css"/>


<!-- Material degign-->
<script src="/focus-components/dist/js/focus.js"></script>
<script src="/focus-components/dist/js/focus-components.js"></script>
<script src="/focus-components/example/js/initFocus.js"></script>
<link rel="stylesheet" href="/focus-components/dist/css/focus-components.css"/>
<link rel="stylesheet" href="/focus-components/example/js/picker.css"/>
</head>

<body>
<script src="/focus-components/example/js/picker.js"></script>
<script src="/focus-components/dist/js/focus.js"></script>
<script src="/focus-components/dist/js/focus-components.js"></script>
<div id="form-container"></div>
<script type="text/javascript">
<script type="text/jsx">
$(function(){
Focus.components = FocusComponents;
var DateInput = Focus.components.common.input.date.component;
React.render(React.createElement(DateInput, {name: "John", value: "01/01/2010", style: {className: "papa"}, onChange: function(evt){console.log("date changed", evt)}}), document.querySelector("#form-container"));
React.render(
<form>
<DateInput name='fieldDate1' formatter={function(d){return moment(d).format('L')}} value={new Date()} style={{className: 'papaDate'}} onChange={function(evt){console.log('date changed', evt)}}/>
</form>
, document.querySelector("#form-container"));
});
</script>

Expand Down
53 changes: 29 additions & 24 deletions common/input/date/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
var jQuery = require('jquery');
//Dependencies.
////http://www.daterangepicker.com/#ex2
var builder = require('focus').component.builder;
var React = require('react');
var inputTextMixin = require('../text').mixin;
let builder = require('focus').component.builder;
let React = require('react');
let inputTextMixin = require('../text').mixin;
let assign = require('object-assign');
/**
* Input text mixin.
* @type {Object}
*/
var inputDateMixin = {
/** @inheritdoc */
mixins: [inputTextMixin],
/** @inheritdoc */
componentDidMount: function inputDateDidMount(){
if(!jQuery.fn.daterangepicker){
console.warn('The jquery daterangepicker plugin should be loaded: see https://github.com/dangrossman/bootstrap-daterangepicker.');
let inputDateMixin = {
/** @inheritdoc */
mixins: [inputTextMixin],
/** @inheritdoc */
componentDidMount(){
let jQuery = require('jquery');
let moment = require('moment');
if(!jQuery.fn.daterangepicker){
console.warn('The jquery daterangepicker plugin should be loaded: see https://github.com/dangrossman/bootstrap-daterangepicker.');
}
if(!moment){
console.warn('The moment library should be loaded: http://http://momentjs.com/');
}
let component = this;
//If the domains set options.
let propsOptions = this.props.options && this.props.options.dateRangePicker ? this.props.options.dateRangePicker : {};
//console.log('parentEL............', `div [data-reactid="${React.findDOMNode(this).parentElement.getAttribute('data-reactid')}"]`);
let dateRangeOptions = assign( propsOptions, {
//Check if the parentElement is the correct container.
parentEl: `[data-reactid="${React.findDOMNode(this).parentElement.getAttribute('data-reactid')}"]`,
singleDatePicker: true,
showDropdowns: true
});
jQuery(React.findDOMNode(this)).daterangepicker(dateRangeOptions, (start)=>{ ///*, end, label*/
component.setState({value: component.props.formatter(start.toDate())});
});
}
var component = this;
//If the domains set options.
let propsOptions = this.props.options && this.props.options.dateRangePicker ? this.props.options.dateRangePicker : {};
console.log('parentEL............', `div [data-reactid="${React.findDOMNode(this).getAttribute('data-reactid')}"]`);
let dateRangeOptions = assign( propsOptions, {
parentEl: `div [data-reactid="${React.findDOMNode(this).getAttribute('data-reactid')}"]`,
singleDatePicker: true,
showDropdowns: true
});
jQuery(React.findDOMNode(this)).daterangepicker(dateRangeOptions, function(start){ ///*, end, label*/
component.setState({value: component.props.formatter(start.toDate())});
});
}
};


Expand Down
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function jsBuild(directory, options) {
react: 'window.React',
focus: 'window.Focus',
jquery: 'window.jQuery',
backbone: 'window.Backbone'
backbone: 'window.Backbone',
moment: 'window.moment'
}))
.transform(babelify)
.bundle()
Expand Down Expand Up @@ -122,7 +123,8 @@ function build(name){
react: 'window.React',
focus: 'window.Focus',
jquery: 'window.jQuery',
backbone: 'window.Backbone'
backbone: 'window.Backbone',
moment: 'window.moment'
}))
.transform(babelify)
.bundle()
Expand Down
Loading