| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const attributesDialog = (function() { | 
					
						
							|  |  |  |     const dialogEl = $("#attributes-dialog"); | 
					
						
							| 
									
										
										
										
											2018-01-11 21:40:09 -05:00
										 |  |  |     const attributesModel = new AttributesModel(); | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-11 21:40:09 -05:00
										 |  |  |     function AttributesModel() { | 
					
						
							|  |  |  |         const self = this; | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-11 21:40:09 -05:00
										 |  |  |         this.attributes = ko.observableArray(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.loadAttributes = async function() { | 
					
						
							|  |  |  |             const noteId = noteEditor.getCurrentNoteId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const attributes = await server.get('notes/' + noteId + '/attributes'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.attributes(attributes); | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.addNewRow = function() { | 
					
						
							| 
									
										
										
										
											2018-01-11 21:40:09 -05:00
										 |  |  |             self.attributes.push({ | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |                 attributeId: '', | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  |                 name: '', | 
					
						
							|  |  |  |                 value: '' | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-01-11 21:40:09 -05:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.save = async function() { | 
					
						
							|  |  |  |             const noteId = noteEditor.getCurrentNoteId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const attributes = await server.put('notes/' + noteId + '/attributes', this.attributes()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             self.attributes(attributes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             showMessage("Attributes have been saved."); | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function showDialog() { | 
					
						
							|  |  |  |         glob.activeDialog = dialogEl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dialogEl.dialog({ | 
					
						
							|  |  |  |             modal: true, | 
					
						
							|  |  |  |             width: 800, | 
					
						
							| 
									
										
										
										
											2018-02-03 12:44:22 -05:00
										 |  |  |             height: 500 | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-11 21:40:09 -05:00
										 |  |  |         attributesModel.loadAttributes(); | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $(document).bind('keydown', 'alt+a', e => { | 
					
						
							|  |  |  |         showDialog(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         e.preventDefault(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-21 23:06:25 -05:00
										 |  |  |     ko.applyBindings(attributesModel, document.getElementById('attributes-dialog')); | 
					
						
							| 
									
										
										
										
											2018-01-11 21:40:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-11 00:01:16 -05:00
										 |  |  |     return { | 
					
						
							|  |  |  |         showDialog | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | })(); |