Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java =================================================================== diff -u -ra4002ee13a835e74c08e3d657494f1c97b531013 -r6e81ff83100e88536170e969f2d8c78a11b35596 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision a4002ee13a835e74c08e3d657494f1c97b531013) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 6e81ff83100e88536170e969f2d8c78a11b35596) @@ -48,6 +48,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; @@ -231,7 +232,37 @@ response.getWriter().write("true"); return null; } + + /** + * Renames lesson. Invoked by Ajax call from general LAMS monitoring. + */ + public ActionForward renameLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, JSONException { + long lessonId = WebUtil.readLongParam(request, "pk"); + + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + if (!getSecurityService().isLessonMonitor(lessonId, user.getUserID(), "rename lesson", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); + return null; + } + String newLessonName = request.getParameter("value"); + if (StringUtils.isBlank(newLessonName)) { + return null; + } + + Lesson lesson = getLessonService().getLesson(lessonId); + lesson.setLessonName(newLessonName); + getUserManagementService().save(lesson); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("successful", true); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(jsonObject); + return null; + } + public ActionForward createLessonClass(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { int organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); Index: lams_monitoring/web/css/_monitorLesson_base.scss =================================================================== diff -u -r312140979ac91708e16d2b57c98f53c13e99ab24 -r6e81ff83100e88536170e969f2d8c78a11b35596 --- lams_monitoring/web/css/_monitorLesson_base.scss (.../_monitorLesson_base.scss) (revision 312140979ac91708e16d2b57c98f53c13e99ab24) +++ lams_monitoring/web/css/_monitorLesson_base.scss (.../_monitorLesson_base.scss) (revision 6e81ff83100e88536170e969f2d8c78a11b35596) @@ -428,4 +428,34 @@ } .group-table>tbody>tr>td, .table>tfoot>tr>td { border-top: none; +} + +/********** RENAME LESSON FEATURE **********/ + +/* Overwrite gliphicon class used by x-editable.js*/ +.glyphicon{ + display: inline-block; + font: normal normal normal 14px/1 FontAwesome; + font-size: inherit; + text-rendering: auto; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +.glyphicon-ok:before { + content: "\f00c"; +} +.glyphicon-remove:before { + content: "\f00d"; +} +/* Overwrite properties set in x-editable.css*/ +.editable-click, a.editable-click, a.editable-click:hover { + border-bottom: none; +} + +/* when item is editable - show pencil icon on hover */ +#lesson-name-strong:hover +span+ i { /* when link is hovered select i */ + visibility: visible; +} +#lesson-name-strong +span+ i { /* in all other case hide it */ + visibility: hidden; } \ No newline at end of file Index: lams_monitoring/web/includes/javascript/monitorLesson.js =================================================================== diff -u -r28360b21c9f90c01d1d615a9c77c5f651e789469 -r6e81ff83100e88536170e969f2d8c78a11b35596 --- lams_monitoring/web/includes/javascript/monitorLesson.js (.../monitorLesson.js) (revision 28360b21c9f90c01d1d615a9c77c5f651e789469) +++ lams_monitoring/web/includes/javascript/monitorLesson.js (.../monitorLesson.js) (revision 6e81ff83100e88536170e969f2d8c78a11b35596) @@ -93,6 +93,33 @@ }); $('#openImButton').click(openChatWindow); + + //turn to inline mode for x-editable.js + $.fn.editable.defaults.mode = 'inline'; + //enable renaming of lesson title + $('#lesson-name-strong').editable({ + type: 'text', + pk: lessonId, + url: LAMS_URL + 'monitoring/monitoring.do?method=renameLesson', + validate: function(value) { + //close editing area on validation failure + if (!value.trim()) { + $('.editable-open').editableContainer('hide', 'cancel'); + return 'Can not be empty!'; + } + }, + //assume server response: 200 Ok {status: 'error', msg: 'field cannot be empty!'} + success: function(response, newValue) { + if(response.status == 'error') { + return response.msg; //msg will be shown in editable form + } + } + //hide and show pencil on showing and hiding editing widget + }).on('shown', function(e, editable) { + $(this).nextAll('i.fa-pencil').hide(); + }).on('hidden', function(e, reason) { + $(this).nextAll('i.fa-pencil').show(); + }); // sets up calendar for schedule date choice $('#scheduleDatetimeField').datetimepicker({ @@ -454,7 +481,7 @@ } updateContributeActivities(response.contributeActivities); - $('.lead','#tabLessonLessonName').html(''+response.lessonName+''); + $('#lesson-name-strong').html(response.lessonName); $('#description').html(response.lessonDescription); } }); Index: lams_monitoring/web/monitor.jsp =================================================================== diff -u -r28360b21c9f90c01d1d615a9c77c5f651e789469 -r6e81ff83100e88536170e969f2d8c78a11b35596 --- lams_monitoring/web/monitor.jsp (.../monitor.jsp) (revision 28360b21c9f90c01d1d615a9c77c5f651e789469) +++ lams_monitoring/web/monitor.jsp (.../monitor.jsp) (revision 6e81ff83100e88536170e969f2d8c78a11b35596) @@ -18,7 +18,8 @@ - + + @@ -44,7 +45,7 @@ - +