├── index.php ├── README.md ├── style.css ├── liff-starter.js ├── catatan-config.js └── index.html /index.php: -------------------------------------------------------------------------------- 1 | { 52 | // start to use LIFF's api 53 | initializeApp(); 54 | }) 55 | .catch((err) => { 56 | document.getElementById("liffAppContent").classList.add('hidden'); 57 | document.getElementById("liffInitErrorMessage").classList.remove('hidden'); 58 | }); 59 | } 60 | 61 | /** 62 | * Initialize the app by calling functions handling individual app components 63 | */ 64 | function initializeApp() { 65 | displayLiffData(); 66 | displayIsInClientInfo(); 67 | registerButtonHandlers(); 68 | 69 | // check if the user is logged in/out, and disable inappropriate button 70 | if (liff.isLoggedIn()) { 71 | document.getElementById('liffLoginButton').disabled = true; 72 | } else { 73 | document.getElementById('liffLogoutButton').disabled = true; 74 | } 75 | } 76 | 77 | /** 78 | * Display data generated by invoking LIFF methods 79 | */ 80 | function displayLiffData() { 81 | document.getElementById('isInClient').textContent = liff.isInClient(); 82 | document.getElementById('isLoggedIn').textContent = liff.isLoggedIn(); 83 | } 84 | 85 | /** 86 | * Toggle the login/logout buttons based on the isInClient status, and display a message accordingly 87 | */ 88 | function displayIsInClientInfo() { 89 | if (liff.isInClient()) { 90 | document.getElementById('liffLoginButton').classList.toggle('hidden'); 91 | document.getElementById('liffLogoutButton').classList.toggle('hidden'); 92 | document.getElementById('isInClientMessage').textContent = 'You are opening the app in the in-app browser of LINE.'; 93 | } else { 94 | document.getElementById('isInClientMessage').textContent = 'You are opening the app in an external browser.'; 95 | } 96 | } 97 | 98 | function registerButtonHandlers() { 99 | // openWindow call 100 | document.getElementById('openWindowButton').addEventListener('click', function() { 101 | liff.openWindow({ 102 | url: 'https://catatanliffv2.herokuapp.com/', // Isi dengan Endpoint URL aplikasi web Anda 103 | external: true 104 | }); 105 | }); 106 | 107 | // closeWindow call 108 | document.getElementById('closeWindowButton').addEventListener('click', function() { 109 | if (!liff.isInClient()) { 110 | sendAlertIfNotInClient(); 111 | } else { 112 | liff.closeWindow(); 113 | } 114 | }); 115 | 116 | // login call, only when external browser is used 117 | document.getElementById('liffLoginButton').addEventListener('click', function() { 118 | if (!liff.isLoggedIn()) { 119 | liff.login(); 120 | } 121 | }); 122 | 123 | // logout call only when external browse 124 | document.getElementById('liffLogoutButton').addEventListener('click', function() { 125 | if (liff.isLoggedIn()) { 126 | liff.logout(); 127 | window.location.reload(); 128 | } 129 | }); 130 | 131 | // sendMessages call 132 | document.getElementById('sendMessageButton').addEventListener('click', function() { 133 | if (!liff.isInClient()) { 134 | sendAlertIfNotInClient(); 135 | } else { 136 | liff.sendMessages([{ 137 | 'type': 'text', 138 | 'text': "Anda telah menggunakan fitur Send Message!" 139 | }]).then(function() { 140 | window.alert('Ini adalah pesan dari fitur Send Message'); 141 | }).catch(function(error) { 142 | window.alert('Error sending message: ' + error); 143 | }); 144 | } 145 | }); 146 | } 147 | 148 | /** 149 | * Alert the user if LIFF is opened in an external browser and unavailable buttons are tapped 150 | */ 151 | function sendAlertIfNotInClient() { 152 | alert('This button is unavailable as LIFF is currently being opened in an external browser.'); 153 | } 154 | 155 | /** 156 | * Toggle specified element 157 | * @param {string} elementId The ID of the selected element 158 | */ 159 | function toggleElement(elementId) { 160 | const elem = document.getElementById(elementId); 161 | if (elem.offsetWidth > 0 && elem.offsetHeight > 0) { 162 | elem.style.display = 'none'; 163 | } else { 164 | elem.style.display = 'block'; 165 | } 166 | } -------------------------------------------------------------------------------- /catatan-config.js: -------------------------------------------------------------------------------- 1 | function loadCatatan() { 2 | if (localStorage.list_data && localStorage.id_data) { 3 | list_data = JSON.parse(localStorage.getItem('list_data')); 4 | var data_app = ""; 5 | if (list_data.length > 0) { 6 | data_app = ''; 7 | data_app += '' + 8 | '' + 9 | '' + 10 | '' + 11 | '' + 12 | '' + 13 | '' + 14 | '' + 15 | ''; 16 | 17 | for (i in list_data) { 18 | data_app += ''; 19 | data_app += 20 | '' + 21 | '' + 22 | '' + 23 | '' + 24 | '' + 25 | '' + 26 | ''; 27 | data_app += ''; 28 | } 29 | 30 | data_app += '
IDNamaTanggalAgendaHapus AgendaLihat AgendaEdit Agenda
' + list_data[i].id_data + ' ' + list_data[i].nama + ' ' + list_data[i].tanggal + ' ' + list_data[i].agenda + ' HapusLihatEdit
'; 31 | 32 | } 33 | else { 34 | data_app = "Catatan masih kosong nih"; 35 | } 36 | 37 | 38 | $('#list-catatan').html(data_app); 39 | $('#list-catatan').hide(); 40 | $('#list-catatan').fadeIn(100); 41 | } 42 | } 43 | 44 | function editData(id) { 45 | 46 | if (localStorage.list_data && localStorage.id_data) { 47 | list_data = JSON.parse(localStorage.getItem('list_data')); 48 | idx_data = 0; 49 | for (i in list_data) { 50 | if (list_data[i].id_data == id) { 51 | $("#eid_data").val(list_data[i].id_data); 52 | $("#enama").val(list_data[i].nama); 53 | $("#etanggal").val(list_data[i].tanggal); 54 | $("#eagenda").val(list_data[i].agenda); 55 | list_data.splice(idx_data, 1); 56 | } 57 | idx_data++; 58 | } 59 | gantiMenu('edit-data'); 60 | 61 | } 62 | 63 | } 64 | 65 | function lihatData(id) { 66 | if (localStorage.list_data && localStorage.id_data) { 67 | list_data = JSON.parse(localStorage.getItem('list_data')); 68 | idx_data = 0; 69 | for (i in list_data) { 70 | if (list_data[i].id_data == id) { 71 | $("#lid_data").val(list_data[i].id_data); 72 | $("#lnama").val(list_data[i].nama); 73 | $("#ltanggal").val(list_data[i].tanggal); 74 | $("#lagenda").val(list_data[i].agenda); 75 | list_data.splice(idx_data, 1); 76 | } 77 | idx_data++; 78 | } 79 | gantiMenu('lihat-data'); 80 | 81 | } 82 | } 83 | 84 | 85 | function simpanData() { 86 | 87 | if (!liff.isInClient()) { 88 | sendAlertIfNotInClient(); 89 | } else { 90 | liff.sendMessages([{ 91 | 'type': 'text', 92 | 'text': "Catatan baru berhasil disimpan" 93 | }]).then(function() { 94 | alert('Catatan Tersimpan'); 95 | }).catch(function(error) { 96 | alert('Aduh kok error ya...'); 97 | }); 98 | } 99 | 100 | nama = $('#nama').val(); 101 | tanggal = $('#tanggal').val(); 102 | agenda = $('#agenda').val(); 103 | 104 | if (localStorage.list_data && localStorage.id_data) { 105 | list_data = JSON.parse(localStorage.getItem('list_data')); 106 | id_data = parseInt(localStorage.getItem('id_data')); 107 | } 108 | else { 109 | list_data = []; 110 | id_data = 0; 111 | } 112 | 113 | id_data++; 114 | list_data.push({ 'id_data': id_data, 'nama': nama, 'tanggal': tanggal, 'agenda': agenda }); 115 | localStorage.setItem('list_data', JSON.stringify(list_data)); 116 | localStorage.setItem('id_data', id_data); 117 | document.getElementById('form-data').reset(); 118 | gantiMenu('list-catatan'); 119 | 120 | return false; 121 | } 122 | 123 | function simpanEditData() { 124 | 125 | if (!liff.isInClient()) { 126 | sendAlertIfNotInClient(); 127 | } else { 128 | liff.sendMessages([{ 129 | 'type': 'text', 130 | 'text': "Catatan yang diedit sudah tersimpan" 131 | }]).then(function() { 132 | alert('Catatan tersimpan'); 133 | }).catch(function(error) { 134 | alert('Aduh kok error ya...'); 135 | }); 136 | } 137 | 138 | id_data = $('#eid_data').val(); 139 | nama = $('#enama').val(); 140 | tanggal = $('#etanggal').val(); 141 | agenda = $('#eagenda').val(); 142 | 143 | list_data.push({ 'id_data': id_data, 'nama': nama, 'tanggal': tanggal, 'agenda': agenda }); 144 | localStorage.setItem('list_data', JSON.stringify(list_data)); 145 | document.getElementById('eform-data').reset(); 146 | gantiMenu('list-catatan'); 147 | 148 | return false; 149 | } 150 | 151 | function hapusData(id) { 152 | 153 | if (!liff.isInClient()) { 154 | sendAlertIfNotInClient(); 155 | } else { 156 | liff.sendMessages([{ 157 | 'type': 'text', 158 | 'text': "Catatan sudah terhapus" 159 | }]).then(function() { 160 | alert('Catatan sudah dihapus'); 161 | }).catch(function(error) { 162 | alert('Aduh kok nggak bisa'); 163 | }); 164 | } 165 | 166 | if (localStorage.list_data && localStorage.id_data) { 167 | list_data = JSON.parse(localStorage.getItem('list_data')); 168 | 169 | idx_data = 0; 170 | for (i in list_data) { 171 | if (list_data[i].id_data == id) { 172 | list_data.splice(idx_data, 1); 173 | } 174 | idx_data++; 175 | } 176 | 177 | localStorage.setItem('list_data', JSON.stringify(list_data)); 178 | loadCatatan(); 179 | } 180 | } 181 | 182 | 183 | function gantiMenu(menu) { 184 | if (menu == "list-catatan") { 185 | loadCatatan(); 186 | $('#tambah-catatan').hide(); 187 | $('#list-catatan').fadeIn(); 188 | $('#edit-data').hide(); 189 | $('#lihat-data').hide(); 190 | } 191 | else if (menu == "tambah-catatan") { 192 | $('#tambah-catatan').fadeIn(); 193 | $('#list-catatan').hide(); 194 | $('#edit-data').hide(); 195 | $('#lihat-data').hide(); 196 | } else if (menu == "edit-data") { 197 | $('#edit-data').fadeIn(); 198 | $('#tambah-catatan').hide(); 199 | $('#list-catatan').hide(); 200 | $('#lihat-data').hide(); 201 | } else if (menu == "lihat-data") { 202 | $('#lihat-data').fadeIn(); 203 | $('#edit-data').hide(); 204 | $('#tambah-catatan').hide(); 205 | $('#list-catatan').hide(); 206 | } 207 | } -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Catatan Harianku 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 35 | 53 | 54 | 80 | 81 | 105 | 106 | 107 |
108 | Pilih List Catatan untuk melihat catatan yang sudah dibuat. 109 |
110 | 111 | 112 |
113 | 114 |
115 |
116 | 117 | 118 | 119 |
120 | 121 |
122 | 123 | 124 |
125 |

Informasi:

126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 |
isInClient :
isLoggedIn :
136 |
137 | 138 |
139 | 140 | 141 |
142 |
143 |
144 |
145 |

Available LIFF methods vary depending on the browser you use to open the LIFF app.

146 |

Please refer to the API reference 148 | page for more information.

149 |
150 |
151 |
152 | 153 | 171 | 172 | 176 | 177 | 180 |
181 | 182 | 183 | 184 | 185 | 186 | 187 | --------------------------------------------------------------------------------