0011978: Fix Copy to clipboard in monthview
[tine20] / tine20 / Calendar / js / MainScreenCenterPanel.js
index 9435c6d..3972d37 100644 (file)
@@ -25,7 +25,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
     
     /**
      * @cfg {String} loadMaskText
-     * _('Loading events, please wait...')
+     * i18n._('Loading events, please wait...')
      */
     loadMaskText: 'Loading events, please wait...',
     
@@ -134,7 +134,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
     initActions: function () {
         this.action_editInNewWindow = new Ext.Action({
             requiredGrant: 'readGrant',
-            text: this.i18nEditActionText ? this.app.i18n._hidden(this.i18nEditActionText) : String.format(Tine.Tinebase.translation._hidden('Edit {0}'), this.i18nRecordName),
+            text: this.i18nEditActionText ? this.app.i18n._hidden(this.i18nEditActionText) : String.format(i18n._hidden('Edit {0}'), this.i18nRecordName),
             disabled: true,
             handler: this.onEditInNewWindow.createDelegate(this, ["edit"]),
             iconCls: 'action_edit'
@@ -142,7 +142,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
         
         this.action_addInNewWindow = new Ext.Action({
             requiredGrant: 'addGrant',
-            text: this.i18nAddActionText ? this.app.i18n._hidden(this.i18nAddActionText) : String.format(Tine.Tinebase.translation._hidden('Add {0}'), this.i18nRecordName),
+            text: this.i18nAddActionText ? this.app.i18n._hidden(this.i18nAddActionText) : String.format(i18n._hidden('Add {0}'), this.i18nRecordName),
             handler: this.onEditInNewWindow.createDelegate(this, ["add"]),
             iconCls: 'action_add'
         });
@@ -172,10 +172,10 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
         this.action_deleteRecord = new Ext.Action({
             requiredGrant: 'deleteGrant',
             allowMultiple: true,
-            singularText: this.i18nDeleteActionText ? i18nDeleteActionText[0] : String.format(Tine.Tinebase.translation.n_hidden('Delete {0}', 'Delete {0}', 1), this.i18nRecordName),
-            pluralText: this.i18nDeleteActionText ? i18nDeleteActionText[1] : String.format(Tine.Tinebase.translation.n_hidden('Delete {0}', 'Delete {0}', 1), this.i18nRecordsName),
-            translationObject: this.i18nDeleteActionText ? this.app.i18n : Tine.Tinebase.translation,
-            text: this.i18nDeleteActionText ? this.i18nDeleteActionText[0] : String.format(Tine.Tinebase.translation.n_hidden('Delete {0}', 'Delete {0}', 1), this.i18nRecordName),
+            singularText: this.i18nDeleteActionText ? i18nDeleteActionText[0] : String.format(i18n.n_hidden('Delete {0}', 'Delete {0}', 1), this.i18nRecordName),
+            pluralText: this.i18nDeleteActionText ? i18nDeleteActionText[1] : String.format(i18n.n_hidden('Delete {0}', 'Delete {0}', 1), this.i18nRecordsName),
+            translationObject: this.i18nDeleteActionText ? this.app.i18n : i18n,
+            text: this.i18nDeleteActionText ? this.i18nDeleteActionText[0] : String.format(i18n.n_hidden('Delete {0}', 'Delete {0}', 1), this.i18nRecordName),
             handler: this.onDeleteRecords,
             disabled: true,
             iconCls: 'action_delete',
@@ -271,6 +271,28 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
             enableToggle: true,
             toggleGroup: 'Calendar_Toolbar_tgViews'
         });
+        this.toggleFullScreen = new Ext.Toolbar.Button({
+            text: '\u2197',
+            scope: this,
+            handler: function() {
+                if (this.ownerCt.ref == 'tineViewportMaincardpanel') {
+                    Tine.Tinebase.viewport.tineViewportMaincardpanel.remove(this, false);
+                    Tine.Tinebase.viewport.tineViewportMaincardpanel.layout.setActiveItem(Tine.Tinebase.viewport.tineViewportMaincardpanel.layout.lastActiveItem);
+                    this.originalOwner.add(this);
+                    this.originalOwner.layout.setActiveItem(this);
+                    this.toggleFullScreen.setText('\u2197');
+                    this.southPanel.expand();
+                } else {
+                    this.originalOwner = this.ownerCt;
+                    this.originalOwner.remove(this, false);
+                    Tine.Tinebase.viewport.tineViewportMaincardpanel.layout.lastActiveItem = Tine.Tinebase.viewport.tineViewportMaincardpanel.layout.activeItem;
+                    Tine.Tinebase.viewport.tineViewportMaincardpanel.add(this);
+                    Tine.Tinebase.viewport.tineViewportMaincardpanel.layout.setActiveItem(this);
+                    this.toggleFullScreen.setText('\u2199');
+                    this.southPanel.collapse();
+                }
+            }
+        });
         
        this.action_import = new Ext.Action({
             requiredGrant: 'addGrant',
@@ -302,6 +324,8 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
             this.changeViewActions.push(this.showYearView);
         }
 
+        this.changeViewActions.push(this.toggleFullScreen);
+
         this.recordActions = [
             this.action_editInNewWindow,
             this.action_deleteRecord
@@ -404,6 +428,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
         if (this.detailsPanel) {
             this.items.push({
                 region: 'south',
+                ref: 'southPanel',
                 border: false,
                 collapsible: true,
                 collapseMode: 'mini',
@@ -606,7 +631,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
             }
             
             addAction = {
-                text: this.i18nAddActionText ? this.app.i18n._hidden(this.i18nAddActionText) : String.format(Tine.Tinebase.translation._hidden('Add {0}'), this.i18nRecordName),
+                text: this.i18nAddActionText ? this.app.i18n._hidden(this.i18nAddActionText) : String.format(i18n._hidden('Add {0}'), this.i18nRecordName),
                 handler: this.onEditInNewWindow.createDelegate(this, ["add", null, null, {dtStart: dtStart, is_all_day_event: datetime && datetime.is_all_day_event}]),
                 iconCls: 'action_add'
             };
@@ -1078,7 +1103,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
         
         // else
         var i18nQuestion = String.format(this.app.i18n.ngettext('Do you really want to delete this event?', 'Do you really want to delete the {0} selected events?', selection.length), selection.length);
-        Ext.MessageBox.confirm(Tine.Tinebase.translation._hidden('Confirm'), i18nQuestion, function (btn) {
+        Ext.MessageBox.confirm(i18n._hidden('Confirm'), i18nQuestion, function (btn) {
             if (btn === 'yes') {
                 this.onDeleteRecordsConfirmNonRecur(panel, selection);
             } else {
@@ -1104,7 +1129,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
             },
             failure: function () {
                 panel.getTopToolbar().onLoad();
-                Ext.MessageBox.alert(Tine.Tinebase.translation._hidden('Failed'), String.format(this.app.i18n.n_('Failed to delete event', 'Failed to delete the {0} events', selection.length), selection.length));
+                Ext.MessageBox.alert(i18n._hidden('Failed'), String.format(this.app.i18n.n_('Failed to delete event', 'Failed to delete the {0} events', selection.length), selection.length));
             }
         };
         
@@ -1149,6 +1174,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
         }
 
         event.isCopy = true;
+        event.view = event.view ? event.view : panel.view;
 
         Tine.Tinebase.data.Clipboard.push(event);
     },
@@ -1176,20 +1202,27 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
      * @param {Date} datetime
      */
     onPasteEvent: function(datetime) {
-        var record = Tine.Tinebase.data.Clipboard.pull('Calendar', 'Event');
-        var isCopy = record.isCopy;
+        var record = Tine.Tinebase.data.Clipboard.pull('Calendar', 'Event'),
+            isCopy = record.isCopy,
+            sourceView = record.view,
+            sourceRecord = record,
+            sourceViewAttendee = sourceView.ownerCt.attendee,
+            destinationView = this.getCalendarPanel(this.activeView).getView(),
+            destinationViewAttendee = destinationView.ownerCt.attendee;
 
         if (! record) {
             return;
         }
         
-        var dtend   = record.get('dtend');
-        var dtstart = record.get('dtstart');
-        var eventLength = dtend - dtstart;
+        var dtend   = record.get('dtend'),
+            dtstart = record.get('dtstart'),
+            eventLength = dtend - dtstart,
+            store = this.getStore();
+
+        record.beginEdit();
 
         if (isCopy != true) {
-            // remove before update
-            var store = this.getStore();
+            // remove from ui before update
             var oldRecord = store.getAt(store.findExact('id', record.getId()));
             if (oldRecord && oldRecord.hasOwnProperty('ui')) {
                 oldRecord.ui.remove();
@@ -1199,6 +1232,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
 
             record.set('editGrant', true);
             record.set('id', '');
+            record.view = sourceView;
 
             // remove attender ids
             Ext.each(record.data.attendee, function(attender) {
@@ -1206,14 +1240,42 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
             }, this);
         }
 
-        // Allow to change attendee if in split view
-        var defaultAttendee = Tine.Calendar.Model.Event.getDefaultData().attendee;
-        if (record.data.attendee[0].user_id.account_id != defaultAttendee[0].user_id.account_id) {
-            record.data.attendee[0] = Tine.Calendar.Model.Event.getDefaultData().attendee[0];
+        // @TODO move to common function with daysView::notifyDrop parts
+        // change attendee in split view
+        if (sourceViewAttendee || destinationViewAttendee) {
+            var attendeeStore = Tine.Calendar.Model.Attender.getAttendeeStore(sourceRecord.get('attendee')),
+                sourceAttendee = sourceViewAttendee ? Tine.Calendar.Model.Attender.getAttendeeStore.getAttenderRecord(attendeeStore, sourceViewAttendee) : false,
+                destinationAttendee = destinationViewAttendee ? Tine.Calendar.Model.Attender.getAttendeeStore.getAttenderRecord(attendeeStore, destinationViewAttendee) : false;
+
+            if (destinationViewAttendee && !destinationAttendee) {
+                destinationAttendee = new Tine.Calendar.Model.Attender(destinationViewAttendee.data);
+
+                attendeeStore.remove(sourceAttendee);
+                attendeeStore.add(destinationAttendee);
+
+                Tine.Calendar.Model.Attender.getAttendeeStore.getData(attendeeStore, record);
+            }
         }
 
-        record.set('dtstart', datetime);
-        record.set('dtend', new Date(datetime.getTime() + eventLength));
+
+        if (datetime.is_all_day_event) {
+            record.set('dtstart', datetime);
+            record.set('dtend', datetime.clone().add(Date.DAY, 1).add(Date.SECOND, -1));
+            record.set('is_all_day_event', true);
+        } else if (datetime.date_only) {
+            var adoptedDtStart = datetime.clone();
+            adoptedDtStart.setHours(dtstart.getHours());
+            adoptedDtStart.setMinutes(dtstart.getMinutes());
+            adoptedDtStart.setSeconds(dtstart.getSeconds());
+
+            record.set('dtstart', adoptedDtStart);
+            record.set('dtend', new Date(adoptedDtStart.getTime() + eventLength));
+        } else {
+            record.set('dtstart', datetime);
+            record.set('dtend', new Date(datetime.getTime() + eventLength));
+        }
+
+        record.endEdit();
 
         if (isCopy == true) {
             record.isCopy = true;
@@ -1461,6 +1523,8 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
             
             // generate html for each busy attender
             var busyAttendeeHTML = '';
+            var denyIgnore = false;
+
             Ext.each(busyAttendee, function(busyAttender) {
                 // TODO refactore name handling of attendee
                 //      -> attender model needs knowlege of how to get names!
@@ -1471,22 +1535,27 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
                 var eventInfos = [];
                 Ext.each(conflictEvents[busyAttender.id], function(fbInfo) {
                     var format = 'H:i';
+                    var eventInfo;
                     var dateFormat = Ext.form.DateField.prototype.format;
                     if (event.get('dtstart').format(dateFormat) != event.get('dtend').format(dateFormat) ||
                         Date.parseDate(fbInfo.dtstart, Date.patterns.ISO8601Long).format(dateFormat) != Date.parseDate(fbInfo.dtend, Date.patterns.ISO8601Long).format(dateFormat))
                     {
-                        format = dateFormat + ' ' + format;
+                        eventInfo = Date.parseDate(fbInfo.dtstart, Date.patterns.ISO8601Long).format(dateFormat + ' ' + format) + ' - ' + Date.parseDate(fbInfo.dtend, Date.patterns.ISO8601Long).format(dateFormat + ' ' + format);
+                    } else {
+                        eventInfo = Date.parseDate(fbInfo.dtstart, Date.patterns.ISO8601Long).format(dateFormat + ' ' + format) + ' - ' + Date.parseDate(fbInfo.dtend, Date.patterns.ISO8601Long).format(format);
                     }
-                    
-                    var eventInfo = Date.parseDate(fbInfo.dtstart, Date.patterns.ISO8601Long).format(format) + ' - ' + Date.parseDate(fbInfo.dtend, Date.patterns.ISO8601Long).format(format);
                     if (fbInfo.event && fbInfo.event.summary) {
                         eventInfo += ' : ' + fbInfo.event.summary;
                     }
+                    if (fbInfo.type == 'BUSY_UNAVAILABLE') {
+                        denyIgnore = true;
+                        eventInfo += '<span class="cal-conflict-eventinfos-unavailable">' + this.app.i18n._('Unavailable') + '</span>';
+                    }
                     eventInfos.push(eventInfo);
                 }, this);
                 busyAttendeeHTML += '<div class="cal-conflict-eventinfos">' + eventInfos.join(', <br />') + '</div>';
                 
-            });
+            }, this);
             
             this.conflictConfirmWin = Tine.widgets.dialog.MultiOptionsDialog.openWindow({
                 modal: true,
@@ -1498,7 +1567,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
                                '</div>' +
                                busyAttendeeHTML,
                 options: [
-                    {text: this.app.i18n._('Ignore Conflict'), name: 'ignore'},
+                    {text: this.app.i18n._('Ignore Conflict'), name: 'ignore', disabled: denyIgnore},
                     {text: this.app.i18n._('Edit Event'), name: 'edit', checked: true},
                     {text: this.app.i18n._('Cancel this action'), name: 'cancel'}
                 ],