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

Multiple imports without jQuery foo #58

Merged
merged 3 commits into from
Nov 28, 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
104 changes: 58 additions & 46 deletions css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,71 +22,83 @@
*/

#app-settings .settings-fieldset .settings-fieldset-interior input {
width: 90%;
width: 90%;
}
#app-settings .settings-fieldset .settings-fieldset-interior select {
width: 40%;
width: 40%;
}
#app-settings .settings-fieldset .settings-upload {
position: absolute;
top: 12.5px;
width: 100%;
display: block;
height: 25.88235px;
font-weight: 300;
font-size: 14px;
cursor: pointer;
z-index: 10;
padding: 7.33333px 0 0 0 !important;
text-align: center;
border: 1px solid rgba(190, 190, 190, 0.9);
background-position: 5%;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-ms-border-radius: 3px;
border-radius: 3px;
position: absolute;
top: 12.5px;
width: 100%;
display: block;
height: 25.88235px;
font-weight: 300;
font-size: 14px;
cursor: pointer;
z-index: 10;
padding: 7.33333px 0 0 0 !important;
text-align: center;
border: 1px solid rgba(190, 190, 190, 0.9);
background-position: 5%;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-ms-border-radius: 3px;
border-radius: 3px;
}
#app-settings .settings-fieldset .settings-fieldset-interior-item:hover {
background: transparent;
background: transparent;
}
#app-settings .settings-fieldset .settings-fieldset-interior-upload {
width: 95%;
height: 55px;
width: 95%;
height: 55px;
}
#app-settings .settings-fieldset .settings-fieldset-interior-upload input {
position: absolute;
top: 18px;
position: absolute;
top: 18px;
}
#app-settings .settings-fieldset .settings-fieldset-interior input[type="file"] {
top: 12.5px;
position: absolute;
width: 100%;
height: 33.21569px;
padding: 0;
font-size: 16px;
margin-left: 0px;
overflow: hidden;
z-index: 20;
opacity: 0;
top: 12.5px;
position: absolute;
width: 100%;
height: 33.21569px;
padding: 0;
font-size: 16px;
margin-left: 0px;
overflow: hidden;
z-index: 20;
opacity: 0;
}

.dialog .table {
width: 100%;
-webkit-transition: 0.05s ease-out 0.05s;
-moz-transition: 0.05s ease-out 0.05s;
-ms-transition: 0.05s ease-out 0.05s;
transition: 0.05s ease-out 0.05s;
width: 100%;
-webkit-transition: 0.05s ease-out 0.05s;
-moz-transition: 0.05s ease-out 0.05s;
-ms-transition: 0.05s ease-out 0.05s;
transition: 0.05s ease-out 0.05s;
}
.dialog .table .name {
padding-left: 20px;
padding-left: 20px;
}
.dialog .table .dialog-select {
width: 100%;
width: 100%;
}
.dialog .table:hover {
background: #ddd;
-webkit-transition: 0.05s ease-out 0.05s;
-moz-transition: 0.05s ease-out 0.05s;
-ms-transition: 0.05s ease-out 0.05s;
transition: 0.05s ease-out 0.05s;
background: #ddd;
-webkit-transition: 0.05s ease-out 0.05s;
-moz-transition: 0.05s ease-out 0.05s;
-ms-transition: 0.05s ease-out 0.05s;
transition: 0.05s ease-out 0.05s;
}

#importdialog .buttongroup button {
padding: 10px;
}

#importdialog .loading {
background-position: 2px;
}

#importdialog .loading.disabled {
background-color: #6c8fc0;
}
72 changes: 30 additions & 42 deletions js/app/controllers/settingscontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,52 @@
*/

/**
* Controller: SettingController
* Description: Takes care of the Calendar Settings.
*/
* Controller: SettingController
* Description: Takes care of the Calendar Settings.
*/

app.controller('SettingsController', ['$scope', '$rootScope', 'Restangular', 'CalendarModel','UploadModel', 'DialogModel',
function ($scope, $rootScope, Restangular, CalendarModel, UploadModel, DialogModel) {
'use strict';
$scope.files = [];

$scope.settingsCalDavLink = OC.linkToRemote('caldav') + '/';
$scope.settingsCalDavPrincipalLink = OC.linkToRemote('caldav') + '/principals/' + escapeHTML(encodeURIComponent(oc_current_user)) + '/';

// have to use the native HTML call for filereader to work efficiently
var importinput = document.getElementById('import');
var reader = new FileReader();

$scope.upload = function () {
UploadModel.upload();
$scope.files = [];
};
var reader = new FileReader();

$rootScope.$on('fileAdded', function (e, call) {
$scope.files.push(call);
$scope.$apply();
if ($scope.files.length > 0) {
var file = importinput.files[0];
reader.onload = function(e) {
$scope.filescontent = reader.result;
};
reader.readAsText(file);
DialogModel.initsmall('#importdialog');
DialogModel.open('#importdialog');
}
$scope.$digest(); // TODO : Shouldn't digest reset scope for it to be implemented again and again?
$('#import').on('change', function () {
$scope.calendarAdded(this);
});

$scope.importcalendar = function (id) {
$scope.calendarid = id;
$scope.calendarAdded = function (elem) {
$scope.files = elem.files;
$scope.$apply();
DialogModel.initsmall('#importdialog');
DialogModel.open('#importdialog');
};

$scope.pushcalendar = function (id, index) {
Restangular.one('calendars', $scope.calendarid).withHttpConfig({transformRequest: angular.identity}).customPOST(
$scope.filescontent,
'import',
undefined,
{
'Content-Type': 'text/calendar'
}
).then( function () {
$scope.files.splice(index,1);
DialogModel.close('#importdialog');
}, function (response) {
OC.Notification.show(t('calendar', response.data.message));
});
};
$scope.import = function (file) {
var reader = new FileReader();
file.isImporting = true;

reader.onload = function() {
Restangular.one('calendars', file.importToCalendar).withHttpConfig({transformRequest: angular.identity}).customPOST(
reader.result,
'import',
undefined,
{
'Content-Type': 'text/calendar'
}
).then( function () {
file.done = true;
}, function (response) {
OC.Notification.show(t('calendar', response.data.message));
});
};

$scope.removecalendar = function (index) {
$scope.files.splice(index,1);
reader.readAsText(file);
};

//to send a patch to add a hidden event again
Expand Down
44 changes: 0 additions & 44 deletions js/app/filters/uploadDirective.js

This file was deleted.

94 changes: 30 additions & 64 deletions js/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,64 +919,52 @@ app.controller('EventsModalController', ['$scope', '$templateCache','$rootScope'
]);

/**
* Controller: SettingController
* Description: Takes care of the Calendar Settings.
*/
* Controller: SettingController
* Description: Takes care of the Calendar Settings.
*/

app.controller('SettingsController', ['$scope', '$rootScope', 'Restangular', 'CalendarModel','UploadModel', 'DialogModel',
function ($scope, $rootScope, Restangular, CalendarModel, UploadModel, DialogModel) {
'use strict';
$scope.files = [];

$scope.settingsCalDavLink = OC.linkToRemote('caldav') + '/';
$scope.settingsCalDavPrincipalLink = OC.linkToRemote('caldav') + '/principals/' + escapeHTML(encodeURIComponent(oc_current_user)) + '/';

// have to use the native HTML call for filereader to work efficiently
var importinput = document.getElementById('import');
var reader = new FileReader();

$scope.upload = function () {
UploadModel.upload();
$scope.files = [];
};
var reader = new FileReader();

$rootScope.$on('fileAdded', function (e, call) {
$scope.files.push(call);
$scope.$apply();
if ($scope.files.length > 0) {
var file = importinput.files[0];
reader.onload = function(e) {
$scope.filescontent = reader.result;
};
reader.readAsText(file);
DialogModel.initsmall('#importdialog');
DialogModel.open('#importdialog');
}
$scope.$digest(); // TODO : Shouldn't digest reset scope for it to be implemented again and again?
$('#import').on('change', function () {
$scope.calendarAdded(this);
});

$scope.importcalendar = function (id) {
$scope.calendarid = id;
$scope.calendarAdded = function (elem) {
$scope.files = elem.files;
$scope.$apply();
DialogModel.initsmall('#importdialog');
DialogModel.open('#importdialog');
};

$scope.pushcalendar = function (id, index) {
Restangular.one('calendars', $scope.calendarid).withHttpConfig({transformRequest: angular.identity}).customPOST(
$scope.filescontent,
'import',
undefined,
{
'Content-Type': 'text/calendar'
}
).then( function () {
$scope.files.splice(index,1);
DialogModel.close('#importdialog');
}, function (response) {
OC.Notification.show(t('calendar', response.data.message));
});
};
$scope.import = function (file) {
var reader = new FileReader();
file.isImporting = true;

reader.onload = function() {
Restangular.one('calendars', file.importToCalendar).withHttpConfig({transformRequest: angular.identity}).customPOST(
reader.result,
'import',
undefined,
{
'Content-Type': 'text/calendar'
}
).then( function () {
file.done = true;
}, function (response) {
OC.Notification.show(t('calendar', response.data.message));
});
};

$scope.removecalendar = function (index) {
$scope.files.splice(index,1);
reader.readAsText(file);
};

//to send a patch to add a hidden event again
Expand Down Expand Up @@ -1249,28 +1237,6 @@ app.filter('subscriptionFilter',
}
]);

app.directive('upload', ['UploadModel', function factory(UploadModel) {
'use strict';
return {
restrict: 'A',
link: function (scope, element, attrs) {
$(element).fileupload({
dataType: 'text',
add: function (e, data) {
UploadModel.add(data);
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
UploadModel.setProgress(progress);
},
done: function (e, data) {
UploadModel.setProgress(0);
}
});
}
};
}]);

/**
* Model:
* Description: Generates a random uid.
Expand Down
Loading