Index: lams_tool_images/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r4b47f86b588e38c9e7e9f2760c75f775cb080831 -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 4b47f86b588e38c9e7e9f2760c75f775cb080831) +++ lams_tool_images/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -25,12 +25,17 @@ label.authoring.heading.advance.desc =Please input advance options for image gallery label.authoring.basic.title =Title label.authoring.basic.add.image =Add Image +label.authoring.basic.add.images =Add Images +label.authoring.basic.add.multiple.images =Add Multiple Images +label.authoring.basic.upload.multiple.images =Upload multiple images +label.authoring.basic.upload.single.image =Upload single image label.authoring.basic.image.list =Image List label.authoring.basic.resource.edit =Edit label.authoring.basic.resource.delete =Delete label.authoring.advanced.reflectOnActivity =Add Notebook at end of Image Gallery with the following instructions: label.authoring.basic.resource.title.input =Title label.authoring.basic.resource.file.input =File +label.authoring.basic.resource.files.input =Files label.authoring.basic.resource.description.input =Description label.authoring.online.file =Upload online file label.authoring.offline.file =Upload offline file @@ -41,6 +46,7 @@ label.authoring.offline.delete =Delete label.authoring.advance.allow.learner.share.images =Allow learners to share their images label.authoring.advance.allow.learner.comment.images =Allow learners to comment on images +label.authoring.advance.notify.monitoring.teachers =Notify monitoring teachers when a learner submits an image label.authoring.advance.allow.learner.ratings.or.vote =Ratings or Vote label.authoring.advance.allow.learner.vote =Allow learners to vote for their favorite images label.authoring.advance.allow.learner.rank =Allow learners to rank the images @@ -109,6 +115,7 @@ error.resource.item.desc.blank =Comment/Instruction can not be blank error.resource.item.title.blank =Title can not be blank. error.resource.image.not.alowed.format =Allowed file formats: gif, png, jpg +error.resource.image.not.alowed.format.for =Error occurred uploading {0}. Allowed file formats: gif, png, jpg error.resource.item.url.blank =URL can not be blank. error.resource.item.file.blank =File can not be blank. error.resource.image.comment.blank =Comment can not be blank. @@ -170,5 +177,7 @@ admin.return =Return to maintain LAMS admin.button.save =Save label.default.user.name =Instructor +event.imagesubmit.subject =LAMS: Learner submitted an image in image gallery tool +event.imagesubmit.body =The learner {0} submitted an image in a image gallery tool.\n\nThis message was send automatically, following tool''s advanced settings. #======= End labels: Exported 166 labels for en AU ===== Index: lams_tool_images/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -rdb681dba0a5e44ae9f4e4cf6b9bc575d6175212f -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision db681dba0a5e44ae9f4e4cf6b9bc575d6175212f) +++ lams_tool_images/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -25,12 +25,17 @@ label.authoring.heading.advance.desc =Please input advance options for image gallery label.authoring.basic.title =Title label.authoring.basic.add.image =Add Image +label.authoring.basic.add.images =Add Images +label.authoring.basic.add.multiple.images =Add Multiple Images +label.authoring.basic.upload.multiple.images =Upload multiple images +label.authoring.basic.upload.single.image =Upload single image label.authoring.basic.image.list =Image List label.authoring.basic.resource.edit =Edit label.authoring.basic.resource.delete =Delete label.authoring.advanced.reflectOnActivity =Add Notebook at end of Image Gallery with the following instructions: label.authoring.basic.resource.title.input =Title label.authoring.basic.resource.file.input =File +label.authoring.basic.resource.files.input =Files label.authoring.basic.resource.description.input =Description label.authoring.online.file =Upload online file label.authoring.offline.file =Upload offline file @@ -110,6 +115,7 @@ error.resource.item.desc.blank =Comment/Instruction can not be blank error.resource.item.title.blank =Title can not be blank. error.resource.image.not.alowed.format =Allowed file formats: gif, png, jpg +error.resource.image.not.alowed.format.for =Error occurred uploading {0}. Allowed file formats: gif, png, jpg error.resource.item.url.blank =URL can not be blank. error.resource.item.file.blank =File can not be blank. error.resource.image.comment.blank =Comment can not be blank. Index: lams_tool_images/conf/language/rams/ApplicationResources.properties =================================================================== diff -u -r4b47f86b588e38c9e7e9f2760c75f775cb080831 -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/conf/language/rams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 4b47f86b588e38c9e7e9f2760c75f775cb080831) +++ lams_tool_images/conf/language/rams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -25,12 +25,17 @@ label.authoring.heading.advance.desc =Please input advance options for image gallery label.authoring.basic.title =Title label.authoring.basic.add.image =Add Image +label.authoring.basic.add.images =Add Images +label.authoring.basic.add.multiple.images =Add Multiple Images +label.authoring.basic.upload.multiple.images =Upload multiple images +label.authoring.basic.upload.single.image =Upload single image label.authoring.basic.image.list =Image List label.authoring.basic.resource.edit =Edit label.authoring.basic.resource.delete =Delete label.authoring.advanced.reflectOnActivity =Add Notebook at end of Image Gallery with the following instructions: label.authoring.basic.resource.title.input =Title label.authoring.basic.resource.file.input =File +label.authoring.basic.resource.files.input =Files label.authoring.basic.resource.description.input =Description label.authoring.online.file =Upload online file label.authoring.offline.file =Upload offline file @@ -41,6 +46,7 @@ label.authoring.offline.delete =Delete label.authoring.advance.allow.learner.share.images =Allow learners to share their images label.authoring.advance.allow.learner.comment.images =Allow learners to comment on images +label.authoring.advance.notify.monitoring.teachers =Notify monitoring teachers when a learner submits an image label.authoring.advance.allow.learner.ratings.or.vote =Ratings or Vote label.authoring.advance.allow.learner.vote =Allow learners to vote for their favorite images label.authoring.advance.allow.learner.rank =Allow learners to rank the images @@ -109,6 +115,7 @@ error.resource.item.desc.blank =Comment/Instruction can not be blank error.resource.item.title.blank =Title can not be blank. error.resource.image.not.alowed.format =Allowed file formats: gif, png, jpg +error.resource.image.not.alowed.format.for =Error occurred uploading {0}. Allowed file formats: gif, png, jpg error.resource.item.url.blank =URL can not be blank. error.resource.item.file.blank =File can not be blank. error.resource.image.comment.blank =Comment can not be blank. @@ -170,5 +177,7 @@ admin.return =Return to maintain LAMS admin.button.save =Save label.default.user.name =Instructor +event.imagesubmit.subject =LAMS: Learner submitted an image in image gallery tool +event.imagesubmit.body =The learner {0} submitted an image in a image gallery tool.\n\nThis message was send automatically, following tool''s advanced settings. #======= End labels: Exported 160 labels for en AU ===== Index: lams_tool_images/conf/language/rams/ApplicationResources_en_AU.properties =================================================================== diff -u -r4b47f86b588e38c9e7e9f2760c75f775cb080831 -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/conf/language/rams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 4b47f86b588e38c9e7e9f2760c75f775cb080831) +++ lams_tool_images/conf/language/rams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -25,12 +25,17 @@ label.authoring.heading.advance.desc =Please input advance options for image gallery label.authoring.basic.title =Title label.authoring.basic.add.image =Add Image +label.authoring.basic.add.images =Add Images +label.authoring.basic.add.multiple.images =Add Multiple Images +label.authoring.basic.upload.multiple.images =Upload multiple images +label.authoring.basic.upload.single.image =Upload single image label.authoring.basic.image.list =Image List label.authoring.basic.resource.edit =Edit label.authoring.basic.resource.delete =Delete label.authoring.advanced.reflectOnActivity =Add Notebook at end of Image Gallery with the following instructions: label.authoring.basic.resource.title.input =Title label.authoring.basic.resource.file.input =File +label.authoring.basic.resource.files.input =Files label.authoring.basic.resource.description.input =Description label.authoring.online.file =Upload online file label.authoring.offline.file =Upload offline file @@ -41,6 +46,7 @@ label.authoring.offline.delete =Delete label.authoring.advance.allow.learner.share.images =Allow learners to share their images label.authoring.advance.allow.learner.comment.images =Allow learners to comment on images +label.authoring.advance.notify.monitoring.teachers =Notify monitoring teachers when a learner submits an image label.authoring.advance.allow.learner.ratings.or.vote =Ratings or Vote label.authoring.advance.allow.learner.vote =Allow learners to vote for their favorite images label.authoring.advance.allow.learner.rank =Allow learners to rank the images @@ -109,6 +115,7 @@ error.resource.item.desc.blank =Comment/Instruction can not be blank error.resource.item.title.blank =Title can not be blank. error.resource.image.not.alowed.format =Allowed file formats: gif, png, jpg +error.resource.image.not.alowed.format.for =Error occurred uploading {0}. Allowed file formats: gif, png, jpg error.resource.item.url.blank =URL can not be blank. error.resource.item.file.blank =File can not be blank. error.resource.image.comment.blank =Comment can not be blank. @@ -170,5 +177,7 @@ admin.return =Return to maintain LAMS admin.button.save =Save label.default.user.name =Instructor +event.imagesubmit.subject =LAMS: Learner submitted an image in image gallery tool +event.imagesubmit.body =The learner {0} submitted an image in a image gallery tool.\n\nThis message was send automatically, following tool''s advanced settings. #======= End labels: Exported 160 labels for en AU ===== Index: lams_tool_images/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r82c1ca392c8358b98025e0402e5eb4f1216c3dee -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 82c1ca392c8358b98025e0402e5eb4f1216c3dee) +++ lams_tool_images/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -75,51 +75,68 @@ - - + parameter="newImageInit"> + - - + - - + - + parameter="removeImage"> + parameter="upImage"> + parameter="downImage"> - - + parameter="removeImageFile"> + + + + + + + + @@ -153,6 +170,23 @@ + + + + + + + + + + + + + + HttpSession ImageGalleryItemList. Notice, this save is not persist them into database, just save + * HttpSession temporarily. Only they will be persist when the entire authoring page is being + * persisted. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + */ + private ActionForward saveMultipleImages(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + MultipleImagesForm multipleForm = (MultipleImagesForm) form; + ActionErrors errors = validateMultipleImages(multipleForm); + + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("images"); + } + + try { + extractMultipleFormToImageGalleryItems(request, multipleForm); + } catch (Exception e) { + // any upload exception will display as normal error message rather then throw exception directly + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(ImageGalleryConstants.ERROR_MSG_UPLOAD_FAILED, + e.getMessage())); + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("images"); + } + } + // set session map ID so that itemlist.jsp can get sessionMAP + request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, multipleForm.getSessionMapID()); + // return null to close this window + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } + + /** * Remove imageGallery item from HttpSession list and update page display. As authoring rule, all persist only * happen when user submit whole page. So this remove is just impact HttpSession values. * @@ -768,7 +833,7 @@ * @param response * @return */ - private ActionForward removeItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, + private ActionForward removeImage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { // get back sessionMAP @@ -979,8 +1044,75 @@ image.setCreateByAuthor(true); image.setHide(false); } + + /** + * Extract web form content to imageGallery items. + * + * @param request + * @param multipleForm + * @throws ImageGalleryException + */ + private void extractMultipleFormToImageGalleryItems(HttpServletRequest request, MultipleImagesForm multipleForm) + throws Exception { + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(multipleForm.getSessionMapID()); + // check whether it is "edit(old item)" or "add(new item)" + SortedSet imageList = getImageList(sessionMap); + + List fileList = createFileListFromMultipleForm(multipleForm); + for (FormFile file : fileList) { + ImageGalleryItem image = new ImageGalleryItem(); + image.setCreateDate(new Timestamp(new Date().getTime())); + int maxSeq = 1; + if (imageList != null && imageList.size() > 0) { + ImageGalleryItem last = imageList.last(); + maxSeq = last.getSequenceId() + 1; + } + image.setSequenceId(maxSeq); + imageList.add(image); + + // uploadImageGalleryItemFile + // and setting file properties' fields: item.setFileUuid(); item.setFileVersionId(); item.setFileType(); + // item.setFileName(); + IImageGalleryService service = getImageGalleryService(); + try { + service.uploadImageGalleryItemFile(image, file); + } catch (UploadImageGalleryFileException e) { + imageList.remove(image); + throw e; + } + + Long nextConsecutiveImageTitle = (Long) sessionMap.get(ImageGalleryConstants.ATTR_NEXT_IMAGE_TITLE); + sessionMap.put(ImageGalleryConstants.ATTR_NEXT_IMAGE_TITLE, nextConsecutiveImageTitle + 1); + String imageLocalized = getImageGalleryService().getLocalisedMessage("label.authoring.image", null); + String title = imageLocalized + " " + nextConsecutiveImageTitle; + image.setTitle(title); + + image.setDescription(""); + image.setCreateByAuthor(true); + image.setHide(false); + } + } + /** + * Validate imageGallery. + * + * @param imageGalleryForm + * @return + */ + private ActionMessages validateImageGallery(ImageGalleryForm imageGalleryForm, HttpServletRequest request) { + ActionMessages errors = new ActionMessages(); + + // define it later mode(TEACHER) skip below validation. + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if (StringUtils.equals(modeStr, ToolAccessMode.TEACHER.toString())) { + return errors; + } + + return errors; + } + + /** * Validate imageGallery item. * * @param itemForm @@ -1000,37 +1132,85 @@ // check for allowed format : gif, png, jpg if (itemForm.getFile() != null) { String contentType = itemForm.getFile().getContentType(); - if (StringUtils.isEmpty(contentType) - || !(contentType.equals("image/gif") || contentType.equals("image/png") - || contentType.equals("image/jpg") || contentType.equals("image/jpeg") || contentType - .equals("image/pjpeg"))) { + if (isContentTypeForbidden(contentType)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT)); } } return errors; } - + /** - * Validate imageGallery. + * Validate imageGallery item. * - * @param imageGalleryForm + * @param multipleForm * @return */ - private ActionMessages validateImageGallery(ImageGalleryForm imageGalleryForm, HttpServletRequest request) { - ActionMessages errors = new ActionMessages(); + private ActionErrors validateMultipleImages(MultipleImagesForm multipleForm) { + ActionErrors errors = new ActionErrors(); - // define it later mode(TEACHER) skip below validation. - String modeStr = request.getParameter(AttributeNames.ATTR_MODE); - if (StringUtils.equals(modeStr, ToolAccessMode.TEACHER.toString())) { - return errors; + List fileList = createFileListFromMultipleForm(multipleForm); + + // validate files size + for (FormFile file : fileList) { + FileValidatorUtil.validateFileSize(file, true, errors); + + // check for allowed format : gif, png, jpg + String contentType = file.getContentType(); + if (isContentTypeForbidden(contentType)) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( + ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT_FOR, file.getFileName())); + } } return errors; } + + /** + * Create file list from multiple form. + * + * @param multipleForm + * @return + */ + private List createFileListFromMultipleForm(MultipleImagesForm multipleForm) { + List fileList = new ArrayList(); + if (! StringUtils.isEmpty(multipleForm.getFile1().getFileName())) { + fileList.add(multipleForm.getFile1()); + } + if (! StringUtils.isEmpty(multipleForm.getFile2().getFileName())) { + fileList.add(multipleForm.getFile2()); + } + if (! StringUtils.isEmpty(multipleForm.getFile3().getFileName())) { + fileList.add(multipleForm.getFile3()); + } + if (! StringUtils.isEmpty(multipleForm.getFile4().getFileName())) { + fileList.add(multipleForm.getFile4()); + } + if (! StringUtils.isEmpty(multipleForm.getFile5().getFileName())) { + fileList.add(multipleForm.getFile5()); + } + + return fileList; + } + /** + * Checks if the format is allowed. + * + * @param contentType + * @return + */ + private boolean isContentTypeForbidden(String contentType) { + boolean isContentTypeForbidden = StringUtils.isEmpty(contentType) + || !(contentType.equals("image/gif") || contentType.equals("image/png") + || contentType.equals("image/jpg") || contentType.equals("image/jpeg") || contentType + .equals("image/pjpeg")); + + return isContentTypeForbidden; + } + + /** * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR mode. * * @param request Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/LearningAction.java =================================================================== diff -u -r8e512e5f28ad5c247d577c7189e2b7908f506240 -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/LearningAction.java (.../LearningAction.java) (revision 8e512e5f28ad5c247d577c7189e2b7908f506240) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/LearningAction.java (.../LearningAction.java) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -25,6 +25,7 @@ package org.lamsfoundation.lams.tool.imageGallery.web.action; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; @@ -45,6 +46,7 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; +import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.events.DeliveryMethodMail; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; @@ -65,6 +67,7 @@ import org.lamsfoundation.lams.tool.imageGallery.util.ImageGalleryItemComparator; import org.lamsfoundation.lams.tool.imageGallery.web.form.ImageGalleryItemForm; import org.lamsfoundation.lams.tool.imageGallery.web.form.ImageRatingForm; +import org.lamsfoundation.lams.tool.imageGallery.web.form.MultipleImagesForm; import org.lamsfoundation.lams.tool.imageGallery.web.form.ReflectionForm; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -102,6 +105,12 @@ if (param.equals("saveNewImage")) { return saveNewImage(mapping, form, request, response); } + if (param.equals("initMultipleImages")) { + return initMultipleImages(mapping, form, request, response); + } + if (param.equals("saveMultipleImages")) { + return saveMultipleImages(mapping, form, request, response); + } // ================ Comments ======================= if (param.equals("loadImageData")) { @@ -338,6 +347,64 @@ } /** + * Initial page for add imageGallery item (single file or URL). + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward initMultipleImages(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + MultipleImagesForm multipleForm = (MultipleImagesForm) form; + multipleForm.setSessionMapID(WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID)); + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } + + /** + * Save file or url imageGallery item into database. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward saveMultipleImages(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + MultipleImagesForm multipleForm = (MultipleImagesForm) form; + ActionErrors errors = validateMultipleImages(multipleForm); + + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("images"); + } + + try { + extractMultipleFormToImageGalleryItems(request, multipleForm); + } catch (Exception e) { + // any upload exception will display as normal error message rather then throw exception directly + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(ImageGalleryConstants.ERROR_MSG_UPLOAD_FAILED, + e.getMessage())); + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("images"); + } + } + + //redirect + String sessionMapID = multipleForm.getSessionMapID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.ATTR_MODE); + request.setAttribute(AttributeNames.ATTR_MODE, mode); + Long sessionId = (Long) sessionMap.get(ImageGalleryConstants.ATTR_TOOL_SESSION_ID); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); + + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } + + /** * Sets Image data to session variable, to be shown on main learning page. * * @param mapping @@ -712,6 +779,27 @@ } } } + + /** + * Extract web form content to imageGallery items. + * + * @param request + * @param multipleForm + * @throws ImageGalleryException + */ + private void extractMultipleFormToImageGalleryItems(HttpServletRequest request, MultipleImagesForm multipleForm) + throws Exception { + + List fileList = createFileListFromMultipleForm(multipleForm); + for (FormFile file : fileList) { + ImageGalleryItemForm imageForm = new ImageGalleryItemForm(); + imageForm.setSessionMapID(multipleForm.getSessionMapID()); + imageForm.setTitle(""); + imageForm.setDescription(""); + imageForm.setFile(file); + extractFormToImageGalleryItem(request, imageForm); + } + } /** * Validate imageGallery item. @@ -732,16 +820,82 @@ // check for allowed format : gif, png, jpg if (itemForm.getFile() != null) { String contentType = itemForm.getFile().getContentType(); - if (StringUtils.isEmpty(contentType) - || !(contentType.equals("image/gif") || contentType.equals("image/png") - || contentType.equals("image/jpg") || contentType.equals("image/jpeg") || contentType - .equals("image/pjpeg") || contentType.equals("image/x-png"))) { + if (isContentTypeForbidden(contentType)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT)); } } return errors; } + + /** + * Validate imageGallery items. + * + * @param multipleForm + * @return + */ + private ActionErrors validateMultipleImages(MultipleImagesForm multipleForm) { + ActionErrors errors = new ActionErrors(); + List fileList = createFileListFromMultipleForm(multipleForm); + + // validate files size + for (FormFile file : fileList) { + FileValidatorUtil.validateFileSize(file, true, errors); + + // check for allowed format : gif, png, jpg + String contentType = file.getContentType(); + if (isContentTypeForbidden(contentType)) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( + ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT_FOR, file.getFileName())); + } + } + + return errors; + } + + /** + * Create file list from multiple form. + * + * @param multipleForm + * @return + */ + private List createFileListFromMultipleForm(MultipleImagesForm multipleForm) { + + List fileList = new ArrayList(); + if (! StringUtils.isEmpty(multipleForm.getFile1().getFileName())) { + fileList.add(multipleForm.getFile1()); + } + if (! StringUtils.isEmpty(multipleForm.getFile2().getFileName())) { + fileList.add(multipleForm.getFile2()); + } + if (! StringUtils.isEmpty(multipleForm.getFile3().getFileName())) { + fileList.add(multipleForm.getFile3()); + } + if (! StringUtils.isEmpty(multipleForm.getFile4().getFileName())) { + fileList.add(multipleForm.getFile4()); + } + if (! StringUtils.isEmpty(multipleForm.getFile5().getFileName())) { + fileList.add(multipleForm.getFile5()); + } + + return fileList; + } + + /** + * Checks if the format is allowed. + * + * @param contentType + * @return + */ + private boolean isContentTypeForbidden(String contentType) { + boolean isContentTypeForbidden = StringUtils.isEmpty(contentType) + || !(contentType.equals("image/gif") || contentType.equals("image/png") + || contentType.equals("image/jpg") || contentType.equals("image/jpeg") || contentType + .equals("image/pjpeg")); + + return isContentTypeForbidden; + } + } Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/MonitoringAction.java =================================================================== diff -u -r82c1ca392c8358b98025e0402e5eb4f1216c3dee -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision 82c1ca392c8358b98025e0402e5eb4f1216c3dee) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -47,6 +47,7 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; +import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.tool.ToolAccessMode; @@ -64,6 +65,7 @@ import org.lamsfoundation.lams.tool.imageGallery.service.UploadImageGalleryFileException; import org.lamsfoundation.lams.tool.imageGallery.web.form.ImageCommentForm; import org.lamsfoundation.lams.tool.imageGallery.web.form.ImageGalleryItemForm; +import org.lamsfoundation.lams.tool.imageGallery.web.form.MultipleImagesForm; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.FileValidatorUtil; import org.lamsfoundation.lams.util.WebUtil; @@ -91,6 +93,12 @@ } if (param.equals("saveNewImage")) { return saveNewImage(mapping, form, request, response); + } + if (param.equals("initMultipleImages")) { + return initMultipleImages(mapping, form, request, response); + } + if (param.equals("saveMultipleImages")) { + return saveMultipleImages(mapping, form, request, response); } if (param.equals("imageSummary")) { return imageSummary(mapping, form, request, response); @@ -150,7 +158,7 @@ } /** - * Initial page for add imageGallery item (single file or URL). + * Initial page for addding new imageGallery item. * * @param mapping * @param form @@ -160,7 +168,6 @@ */ private ActionForward newImageInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - ImageGalleryItemForm itemForm = (ImageGalleryItemForm) form; String sessionMapID = request.getParameter(ImageGalleryConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); @@ -206,6 +213,61 @@ } /** + * Initial page for addding new imageGallery item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward initMultipleImages(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + String sessionMapID = request.getParameter(ImageGalleryConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } + + /** + * Save imageGallery item into database. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward saveMultipleImages(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + MultipleImagesForm multipleForm = (MultipleImagesForm) form; + String sessionMapID = multipleForm.getSessionMapID(); + request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMapID); + + ActionErrors errors = validateMultipleImages(multipleForm); + + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("images"); + } + + try { + extractMultipleFormToImageGalleryItems(request, multipleForm); + } catch (Exception e) { + // any upload exception will display as normal error message rather then throw exception directly + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(ImageGalleryConstants.ERROR_MSG_UPLOAD_FAILED, + e.getMessage())); + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("images"); + } + } + + //redirect + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } + + /** * Display edit page for existed imageGallery item. * * @param mapping @@ -529,6 +591,27 @@ } /** + * Extract web form content to imageGallery items. + * + * @param request + * @param multipleForm + * @throws ImageGalleryException + */ + private void extractMultipleFormToImageGalleryItems(HttpServletRequest request, MultipleImagesForm multipleForm) + throws Exception { + + List fileList = createFileListFromMultipleForm(multipleForm); + for (FormFile file : fileList) { + ImageGalleryItemForm imageForm = new ImageGalleryItemForm(); + imageForm.setSessionMapID(multipleForm.getSessionMapID()); + imageForm.setTitle(""); + imageForm.setDescription(""); + imageForm.setFile(file); + extractFormToImageGalleryItem(request, imageForm); + } + } + + /** * Validate imageGallery item. * * @param itemForm @@ -547,16 +630,82 @@ // check for allowed format : gif, png, jpg if (itemForm.getFile() != null) { String contentType = itemForm.getFile().getContentType(); - if (StringUtils.isEmpty(contentType) - || !(contentType.equals("image/gif") || contentType.equals("image/png") - || contentType.equals("image/jpg") || contentType.equals("image/jpeg") || contentType - .equals("image/pjpeg") || contentType.equals("image/x-png"))) { + if (isContentTypeForbidden(contentType)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT)); } } return errors; } + + /** + * Validate imageGallery items. + * + * @param multipleForm + * @return + */ + private ActionErrors validateMultipleImages(MultipleImagesForm multipleForm) { + ActionErrors errors = new ActionErrors(); + List fileList = createFileListFromMultipleForm(multipleForm); + + // validate files size + for (FormFile file : fileList) { + FileValidatorUtil.validateFileSize(file, true, errors); + + // check for allowed format : gif, png, jpg + String contentType = file.getContentType(); + if (isContentTypeForbidden(contentType)) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( + ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT_FOR, file.getFileName())); + } + } + + return errors; + } + + /** + * Create file list from multiple form. + * + * @param multipleForm + * @return + */ + private List createFileListFromMultipleForm(MultipleImagesForm multipleForm) { + + List fileList = new ArrayList(); + if (! StringUtils.isEmpty(multipleForm.getFile1().getFileName())) { + fileList.add(multipleForm.getFile1()); + } + if (! StringUtils.isEmpty(multipleForm.getFile2().getFileName())) { + fileList.add(multipleForm.getFile2()); + } + if (! StringUtils.isEmpty(multipleForm.getFile3().getFileName())) { + fileList.add(multipleForm.getFile3()); + } + if (! StringUtils.isEmpty(multipleForm.getFile4().getFileName())) { + fileList.add(multipleForm.getFile4()); + } + if (! StringUtils.isEmpty(multipleForm.getFile5().getFileName())) { + fileList.add(multipleForm.getFile5()); + } + + return fileList; + } + + /** + * Checks if the format is allowed. + * + * @param contentType + * @return + */ + private boolean isContentTypeForbidden(String contentType) { + boolean isContentTypeForbidden = StringUtils.isEmpty(contentType) + || !(contentType.equals("image/gif") || contentType.equals("image/png") + || contentType.equals("image/jpg") || contentType.equals("image/jpeg") || contentType + .equals("image/pjpeg")); + + return isContentTypeForbidden; + } + } Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/MultipleImagesForm.java =================================================================== diff -u --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/MultipleImagesForm.java (revision 0) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/MultipleImagesForm.java (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -0,0 +1,193 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.imageGallery.web.form; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.upload.FormFile; + +/** + * Multiple Images Form. + * + * @struts.form name="multipleImagesForm" + * @author Andrey Balan + */ +public class MultipleImagesForm extends ActionForm { + + private static final long serialVersionUID = -5595679171112282994L; + + private String imageIndex; + private String sessionMapID; + + // tool access mode; + private String mode; + + private String title; + private String description; + // flag of this item has attachment or not + private boolean hasFile; + private Long fileUuid; + private Long fileVersionId; + private String fileName; + private FormFile file1; + private FormFile file2; + private FormFile file3; + private FormFile file4; + private FormFile file5; + + //used only in monitoring + private String imageUid; + + /** + * Returns ImageGallery order index. + * + * @return ImageGallery order index + */ + public String getImageIndex() { + return imageIndex; + } + + /** + * Sets ImageGallery order index. + * + * @param imageIndex + * ImageGallery order index + */ + public void setImageIndex(String imageIndex) { + this.imageIndex = imageIndex; + } + + public String getSessionMapID() { + return sessionMapID; + } + + public void setSessionMapID(String sessionMapID) { + this.sessionMapID = sessionMapID; + } + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public Long getFileUuid() { + return fileUuid; + } + + public void setFileUuid(Long fileUuid) { + this.fileUuid = fileUuid; + } + + public Long getFileVersionId() { + return fileVersionId; + } + + public void setFileVersionId(Long fileVersionId) { + this.fileVersionId = fileVersionId; + } + + public boolean isHasFile() { + return hasFile; + } + + public void setHasFile(boolean hasFile) { + this.hasFile = hasFile; + } + + public FormFile getFile1() { + return file1; + } + + public void setFile1(FormFile file) { + this.file1 = file; + } + + public FormFile getFile2() { + return file2; + } + + public void setFile2(FormFile file) { + this.file2 = file; + } + + public FormFile getFile3() { + return file3; + } + + public void setFile3(FormFile file) { + this.file3 = file; + } + + public FormFile getFile4() { + return file4; + } + + public void setFile4(FormFile file) { + this.file4 = file; + } + + public FormFile getFile5() { + return file5; + } + + public void setFile5(FormFile file) { + this.file5 = file; + } + + public String getImageUid() { + return imageUid; + } + + public void setImageUid(String imageUid) { + this.imageUid = imageUid; + } +} + + \ No newline at end of file Index: lams_tool_images/web/includes/javascript/imageGalleryitem.js =================================================================== diff -u -r8a7c47632a6a93892f015f068d12adb376c0ae2d -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/web/includes/javascript/imageGalleryitem.js (.../imageGalleryitem.js) (revision 8a7c47632a6a93892f015f068d12adb376c0ae2d) +++ lams_tool_images/web/includes/javascript/imageGalleryitem.js (.../imageGalleryitem.js) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -27,3 +27,20 @@ function cancelImageGalleryItem(){ window.top.hideMessage(); } + /** + * Launches the popup window for the instruction files + */ + function showMessage(url) { + var area=window.top.document.getElementById("reourceInputArea"); + if(area != null){ + area.style.width="650px"; + area.style.height="100%"; + area.src=url; + area.style.display="block"; + } + var elem = window.top.document.getElementById("saveCancelButtons"); + if (elem != null) { + elem.style.display="none"; + } + location.hash = "reourceInputArea"; + } Index: lams_tool_images/web/pages/authoring/basic.jsp =================================================================== diff -u -r989e4b47442b99cfcdf170f565a1b0c4c69fb03c -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/web/pages/authoring/basic.jsp (.../basic.jsp) (revision 989e4b47442b99cfcdf170f565a1b0c4c69fb03c) +++ lams_tool_images/web/pages/authoring/basic.jsp (.../basic.jsp) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -41,7 +41,7 @@ } function editItem(idx,sessionMapID){ - var url = "" + idx +"&sessionMapID="+sessionMapID;; + var url = "" + idx +"&sessionMapID="+sessionMapID;; showMessage(url); } //The panel of imageGallery list panel @@ -51,10 +51,9 @@ var deletionConfirmed = confirm(''); if (deletionConfirmed) { - var url = ""; + var url = ""; var param = "imageIndex=" + idx +"&sessionMapID="+sessionMapID;; deleteItemLoading(); - alert(param); var myAjax = new Ajax.Updater( imageGalleryListTargetDiv, url, @@ -139,7 +138,7 @@

- ');" class="button-add-item"> + ');" class="button-add-item">

Fisheye: Tag 616336eff87580ecb6f13770899bc9af7eff4fa8 refers to a dead (removed) revision in file `lams_tool_images/web/pages/authoring/parts/addfile.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_images/web/pages/authoring/parts/addimage.jsp =================================================================== diff -u --- lams_tool_images/web/pages/authoring/parts/addimage.jsp (revision 0) +++ lams_tool_images/web/pages/authoring/parts/addimage.jsp (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -0,0 +1,73 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + <%@ include file="/common/header.jsp"%> + + + + + + + + + + <%@ include file="/common/messages.jsp"%> + + + + + +

+ +

+ +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ <%@ include file="/pages/authoring/parts/imagefile.jsp"%> +
+ + + + + +
+ + + + + + + +
Index: lams_tool_images/web/pages/authoring/parts/addmultipleimages.jsp =================================================================== diff -u --- lams_tool_images/web/pages/authoring/parts/addmultipleimages.jsp (revision 0) +++ lams_tool_images/web/pages/authoring/parts/addmultipleimages.jsp (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -0,0 +1,64 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + <%@ include file="/common/header.jsp"%> + + + + + + + + + + <%@ include file="/common/messages.jsp"%> + + + +

+ +

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + + + +
+ + + + + + +
Index: lams_tool_images/web/pages/authoring/parts/imagefile.jsp =================================================================== diff -u --- lams_tool_images/web/pages/authoring/parts/imagefile.jsp (revision 0) +++ lams_tool_images/web/pages/authoring/parts/imagefile.jsp (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -0,0 +1,45 @@ +<%@ include file="/common/taglibs.jsp"%> + + + + + + + + + + + + + + +
+ + + + + +   + + + + + + +
+
+ + + +
+ Fisheye: Tag 616336eff87580ecb6f13770899bc9af7eff4fa8 refers to a dead (removed) revision in file `lams_tool_images/web/pages/authoring/parts/itemattachment.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_images/web/pages/learning/learning.jsp =================================================================== diff -u -rd135b890fdc2d5b58c6bd02c48c8b3365d9a2ffe -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/web/pages/learning/learning.jsp (.../learning.jsp) (revision d135b890fdc2d5b58c6bd02c48c8b3365d9a2ffe) +++ lams_tool_images/web/pages/learning/learning.jsp (.../learning.jsp) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -387,7 +387,7 @@
- +
Index: lams_tool_images/web/pages/learning/parts/addimage.jsp =================================================================== diff -u -r4b9aac6879339e46cb0a163a8f72400aed80c041 -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/web/pages/learning/parts/addimage.jsp (.../addimage.jsp) (revision 4b9aac6879339e46cb0a163a8f72400aed80c041) +++ lams_tool_images/web/pages/learning/parts/addimage.jsp (.../addimage.jsp) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -9,15 +9,10 @@ <%@ include file="/common/headerWithoutPrototype.jsp"%> - - - -
- <%@ include file="/common/messages.jsp"%> @@ -47,6 +42,12 @@
+ +
+ + + +


Index: lams_tool_images/web/pages/learning/parts/addmultipleimages.jsp =================================================================== diff -u --- lams_tool_images/web/pages/learning/parts/addmultipleimages.jsp (revision 0) +++ lams_tool_images/web/pages/learning/parts/addmultipleimages.jsp (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -0,0 +1,73 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + + <fmt:message key="label.learning.title" /> + + <%@ include file="/common/headerWithoutPrototype.jsp"%> + + + + +
+ + <%@ include file="/common/messages.jsp"%> + + + + +

+ +

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + +
+ + + +
+ +
+ +

+ + + + + + + + + + +
+ + + + + +
Index: lams_tool_images/web/pages/monitoring/parts/addimage.jsp =================================================================== diff -u -r82c1ca392c8358b98025e0402e5eb4f1216c3dee -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/web/pages/monitoring/parts/addimage.jsp (.../addimage.jsp) (revision 82c1ca392c8358b98025e0402e5eb4f1216c3dee) +++ lams_tool_images/web/pages/monitoring/parts/addimage.jsp (.../addimage.jsp) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -9,15 +9,10 @@ <%@ include file="/common/headerWithoutPrototype.jsp"%> - - - -
- <%@ include file="/common/messages.jsp"%> @@ -47,6 +42,12 @@
+ +
+ + + +


Index: lams_tool_images/web/pages/monitoring/parts/addmultipleimages.jsp =================================================================== diff -u --- lams_tool_images/web/pages/monitoring/parts/addmultipleimages.jsp (revision 0) +++ lams_tool_images/web/pages/monitoring/parts/addmultipleimages.jsp (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -0,0 +1,73 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + + <fmt:message key="label.learning.title" /> + + <%@ include file="/common/headerWithoutPrototype.jsp"%> + + + + +
+ + <%@ include file="/common/messages.jsp"%> + + + + +

+ +

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + +
+ + + +
+ +
+ +

+ + + + + + + + + + +
+ + + + + +
Index: lams_tool_images/web/pages/monitoring/summary.jsp =================================================================== diff -u -rdb681dba0a5e44ae9f4e4cf6b9bc575d6175212f -r616336eff87580ecb6f13770899bc9af7eff4fa8 --- lams_tool_images/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision db681dba0a5e44ae9f4e4cf6b9bc575d6175212f) +++ lams_tool_images/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 616336eff87580ecb6f13770899bc9af7eff4fa8) @@ -321,8 +321,8 @@ -