@@ -46,7 +46,16 @@ angular.module('mm.addons.notes')
4646 "notes[0][text]" : noteText ,
4747 "notes[0][format]" : 1
4848 } ;
49- return $mmSite . write ( 'core_notes_create_notes' , data ) ;
49+ return $mmSite . write ( 'core_notes_create_notes' , data ) . then ( function ( response ) {
50+ if ( ! response || ! response . length ) {
51+ return $q . reject ( ) ;
52+ }
53+
54+ if ( response [ 0 ] . noteid == - 1 ) {
55+ return $q . reject ( response [ 0 ] . errormessage ) ;
56+ }
57+ return response ;
58+ } ) ;
5059 } ;
5160
5261 /**
@@ -61,8 +70,6 @@ angular.module('mm.addons.notes')
6170 * @return {Boolean }
6271 */
6372 self . isPluginAddNoteEnabled = function ( ) {
64- var infos ;
65-
6673 if ( ! $mmSite . isLoggedIn ( ) ) {
6774 return false ;
6875 } else if ( ! $mmSite . canUseAdvancedFeature ( 'enablenotes' ) ) {
@@ -74,6 +81,33 @@ angular.module('mm.addons.notes')
7481 return true ;
7582 } ;
7683
84+ /**
85+ * Returns whether or not the add note plugin is enabled for a certain course.
86+ *
87+ * @module mm.addons.notes
88+ * @ngdoc method
89+ * @name $mmaNotes#isPluginAddNoteEnabledForCourse
90+ * @param {Number } courseId ID of the course.
91+ * @return {Promise } Promise resolved with true if enabled, resolved with false otherwise.
92+ */
93+ self . isPluginAddNoteEnabledForCourse = function ( courseId ) {
94+ // The only way to detect if it's enabled is to perform a WS call.
95+ // We use an invalid user ID (-1) and check if the error is due to permissions or to invalid ID.
96+ var data = {
97+ "notes[0][userid]" : - 1 ,
98+ "notes[0][courseid]" : courseId ,
99+ "notes[0][publishstate]" : 'personal' ,
100+ "notes[0][text]" : '' ,
101+ "notes[0][format]" : 1
102+ } ;
103+ return $mmSite . read ( 'core_notes_create_notes' , data ) . then ( function ( ) {
104+ // User can add notes.
105+ return true ;
106+ } ) . catch ( function ( ) {
107+ return false ;
108+ } ) ;
109+ } ;
110+
77111 /**
78112 * Returns whether or not the read notes plugin is enabled for the current site.
79113 *
@@ -86,8 +120,6 @@ angular.module('mm.addons.notes')
86120 * @return {Boolean }
87121 */
88122 self . isPluginViewNotesEnabled = function ( ) {
89- var infos ;
90-
91123 if ( ! $mmSite . isLoggedIn ( ) ) {
92124 return false ;
93125 } else if ( ! $mmSite . canUseAdvancedFeature ( 'enablenotes' ) ) {
@@ -99,6 +131,23 @@ angular.module('mm.addons.notes')
99131 return true ;
100132 } ;
101133
134+ /**
135+ * Returns whether or not the read notes plugin is enabled for a certain course.
136+ *
137+ * @module mm.addons.notes
138+ * @ngdoc method
139+ * @name $mmaNotes#isPluginViewNotesEnabledForCourse
140+ * @param {Number } courseId ID of the course.
141+ * @return {Promise } Promise resolved with true if enabled, resolved with false otherwise.
142+ */
143+ self . isPluginViewNotesEnabledForCourse = function ( courseId ) {
144+ return self . getNotes ( courseId ) . then ( function ( ) {
145+ return true ;
146+ } ) . catch ( function ( ) {
147+ return false ;
148+ } ) ;
149+ } ;
150+
102151 /**
103152 * Get users notes for a certain site, course and personal notes.
104153 *
0 commit comments