3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">
\r
9 Ext.onReady(function(){
\r
10 Ext.QuickTips.init();
\r
12 var win = window.nativeWindow;
\r
14 var opener = Ext.air.NativeWindow.getRootHtmlWindow();
\r
15 var taskId = String(window.location).split('=')[1];
\r
16 var isNew = !taskId;
\r
17 var completed = false;
\r
19 win.title = 'Task - ' + Ext.util.Format.ellipsis(getTask().data.title, 40);
\r
21 var tb = new Ext.Toolbar({
\r
27 iconCls: 'icon-mark-complete',
\r
28 text: 'Mark Complete',
\r
29 handler: function(){
\r
30 setCompleted(!completed);
\r
32 setMsg('This task was completed on ' + new Date().format('l, F d, Y'));
\r
44 {iconCls: 'icon-delete-task', text: 'Delete', handler: function(){
\r
45 Ext.Msg.confirm('Confirm Delete', 'Are you sure you want to delete this task?', function(btn){
\r
47 opener.tx.data.tasks.remove(getTask());
\r
55 var title = new Ext.form.TextField({
\r
56 fieldLabel: 'Task Subject',
\r
61 var dueDate = new Ext.form.DateField({
\r
62 fieldLabel: 'Due Date',
\r
68 var list = new ListSelector({
\r
69 fieldLabel: 'Task List',
\r
71 store: opener.tx.data.lists,
\r
75 list.on('render', function(){
\r
76 this.menu.on('beforeshow', function(m){
\r
77 list.tree.setWidth(Math.max(180, list.getSize().width));
\r
80 win.addEventListener('closing', function(){
\r
81 opener.tx.data.lists.unbindTree(list.tree);
\r
85 var hasReminder = new Ext.form.Checkbox({
\r
86 boxLabel: 'Reminder:',
\r
90 var reminder = new Ext.ux.form.DateTime({
\r
93 timeFormat: 'g:i A',
\r
94 dateFormat: 'm/d/Y',
\r
96 tpl: opener.Templates.timeField,
\r
97 listClass:'x-combo-list-small',
\r
102 var description = new Ext.form.HtmlEditor({
\r
104 name: 'description',
\r
105 anchor: '100% -95', // anchor width by percentage and height by raw adjustment
\r
106 onEditorEvent : function(e){
\r
108 if(e.browserEvent.type == 'mousedown' && (t = e.getTarget('a', 3))){
\r
109 t.target = '_blank';
\r
111 this.updateToolbar();
\r
115 var form = new Ext.form.FormPanel({
\r
117 baseCls: 'x-plain',
\r
119 margins:'10 10 5 10',
\r
121 buttonAlign: 'right',
\r
122 minButtonWidth: 80,
\r
125 handler: function(){
\r
128 window.nativeWindow.close();
\r
133 handler: function(){ window.nativeWindow.close(); }
\r
144 baseCls: 'x-plain',
\r
148 baseCls: 'x-plain',
\r
153 baseCls: 'x-plain',
\r
159 autoEl: {cls:'divider'}
\r
163 baseCls: 'x-plain',
\r
167 baseCls: 'x-plain',
\r
173 baseCls: 'x-plain',
\r
181 var viewport = new Ext.Viewport({
\r
186 var msg = Ext.get('msg');
\r
187 var task = getTask();
\r
189 if(task && task.data.completedDate){
\r
190 setMsg('This task was completed on ' + task.data.completedDate.format('l, F d, Y'));
\r
193 hasReminder.on('check', function(cb, checked){
\r
194 reminder.setDisabled(!checked);
\r
195 if(checked && !reminder.getValue()){
\r
196 reminder.setValue(opener.tx.data.getDefaultReminder(getTask()));
\r
200 refreshData.defer(10);
\r
202 win.visible = true;
\r
207 function refreshData(){
\r
209 var task = getTask();
\r
210 hasReminder.setValue(!!task.data.reminder);
\r
211 form.getForm().loadRecord(task);
\r
212 setCompleted(task.data.completed);
\r
216 function saveData(){
\r
219 task = opener.tx.data.tasks.createTask(
\r
221 list.getRawValue(),
\r
222 dueDate.getValue(),
\r
223 description.getValue(),
\r
228 task.set('completed', completed);
\r
230 if(!hasReminder.getValue()){
\r
231 reminder.setValue('');
\r
233 form.getForm().updateRecord(task);
\r
236 function setCompleted(value){
\r
238 var cplBtn = Ext.getCmp('cpl-btn');
\r
240 cplBtn.setText('Mark Active');
\r
241 cplBtn.setIconClass('icon-mark-active');
\r
242 hasReminder.disable();
\r
243 reminder.disable();
\r
246 cplBtn.setText('Mark Complete');
\r
247 cplBtn.setIconClass('icon-mark-complete');
\r
249 hasReminder.enable();
\r
250 reminder.setDisabled(!hasReminder.checked);
\r
254 function setMsg(msgText){
\r
257 msg.setDisplayed(false);
\r
259 msg.setDisplayed('');
\r
260 msg.update(msgText);
\r
262 description.anchorSpec.bottom = function(v){
\r
265 var h = msg.getHeight();
\r
266 return v - 95 - (h ? h + 8 : 0);
\r
272 function validate(){
\r
273 if(Ext.isEmpty(title.getValue(), false)){
\r
274 Ext.Msg.alert('Warning', 'Unable to save changes. A subject is required.', function(){
\r
282 function getTask(){
\r
283 var t = opener.tx.data.tasks.lookup(taskId);
\r
285 //workaround WebKit cross-frame date issue
\r
286 fixDateMember(t.data, 'completedDate');
\r
287 fixDateMember(t.data, 'reminder');
\r
288 fixDateMember(t.data, 'dueDate');
\r